本文整理匯總了Java中com.google.devtools.build.lib.syntax.SkylarkList類的典型用法代碼示例。如果您正苦於以下問題:Java SkylarkList類的具體用法?Java SkylarkList怎麽用?Java SkylarkList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SkylarkList類屬於com.google.devtools.build.lib.syntax包,在下文中一共展示了SkylarkList類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: invoke
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
@SuppressWarnings("unused")
public SkylarkList<Transformation> invoke(Core self, SkylarkList<Transformation> transforms,
Location location)
throws EvalException {
ImmutableList.Builder<Transformation> builder = ImmutableList.builder();
for (Transformation t : transforms.getContents(Transformation.class, "transformations")) {
try {
builder.add(t.reverse());
} catch (NonReversibleValidationException e) {
throw new EvalException(location, e.getMessage());
}
}
return SkylarkList.createImmutable(builder.build().reverse());
}
示例2: invoke
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
public NoneType invoke(GitModule self, String name, String origin, String destination,
SkylarkList<String> strRefSpecs, Boolean prune, Location location, Environment env)
throws EvalException {
GeneralOptions generalOptions = self.options.get(GeneralOptions.class);
List<Refspec> refspecs = new ArrayList<>();
for (String refspec : SkylarkList.castList(strRefSpecs, String.class, "refspecs")) {
refspecs.add(Refspec.create(
generalOptions.getEnvironment(), generalOptions.getCwd(), refspec, location));
}
Core.getCore(env).addMigration(location, name,
new Mirror(generalOptions, self.options.get(GitOptions.class),
name, origin, destination, refspecs,
self.options.get(GitMirrorOptions.class), prune, self.mainConfigFile));
return Runtime.NONE;
}
示例3: checkAttributesNonEmpty
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
public void checkAttributesNonEmpty(
Rule rule, RuleErrorConsumer ruleErrorConsumer, AttributeMap attributes) {
for (String attributeName : attributes.getAttributeNames()) {
Attribute attr = attributes.getAttributeDefinition(attributeName);
if (!attr.isNonEmpty()) {
continue;
}
Object attributeValue = attributes.get(attributeName, attr.getType());
boolean isEmpty = false;
if (attributeValue instanceof SkylarkList) {
isEmpty = ((SkylarkList) attributeValue).isEmpty();
} else if (attributeValue instanceof List<?>) {
isEmpty = ((List<?>) attributeValue).isEmpty();
} else if (attributeValue instanceof Map<?, ?>) {
isEmpty = ((Map<?, ?>) attributeValue).isEmpty();
}
if (isEmpty) {
ruleErrorConsumer.attributeError(attr.getName(), "attribute must be non empty");
}
}
}
示例4: createInstanceFromSkylark
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected JavaInfo createInstanceFromSkylark(Object[] args, Location loc)
throws EvalException {
JavaInfo javaInfo =
JavaInfoBuildHelper.getInstance()
.createJavaInfo(
(Artifact) args[0],
(SkylarkList<Artifact>) args[1],
(SkylarkList<Artifact>) args[2],
(Boolean) args[3],
(Boolean) args[4],
(SkylarkList<JavaInfo>) args[5],
(SkylarkList<JavaInfo>) args[6],
(SkylarkList<JavaInfo>) args[7],
args[8],
args[9],
loc);
return javaInfo;
}
示例5: createInstanceFromSkylark
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
@Override
protected PlatformInfo createInstanceFromSkylark(Object[] args, Location loc)
throws EvalException {
// Based on SIGNATURE above, the args are label, constraint_values.
Label label = (Label) args[0];
List<ConstraintValueInfo> constraintValues =
SkylarkList.castSkylarkListOrNoneToList(
args[1], ConstraintValueInfo.class, "constraint_values");
try {
return builder()
.setLabel(label)
.addConstraints(constraintValues)
.setLocation(loc)
.build();
} catch (DuplicateConstraintException dce) {
throw new EvalException(
loc, String.format("Cannot create PlatformInfo: %s", dce.getMessage()));
}
}
示例6: invoke
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
public Provider invoke(String doc, Object fields, Location location) throws EvalException {
Iterable<String> fieldNames = null;
if (fields instanceof SkylarkList<?>) {
@SuppressWarnings("unchecked")
SkylarkList<String> list = (SkylarkList<String>)
SkylarkType.cast(
fields,
SkylarkList.class, String.class, location,
"Expected list of strings or dictionary of string -> string for 'fields'");
fieldNames = list;
} else if (fields instanceof SkylarkDict) {
Map<String, String> dict = SkylarkType.castMap(
fields,
String.class, String.class,
"Expected list of strings or dictionary of string -> string for 'fields'");
fieldNames = dict.keySet();
}
return SkylarkProvider.createUnexportedSchemaful(fieldNames, location);
}
示例7: invoke
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
@SuppressWarnings("unused")
public NoneType invoke(
Args self,
Object value,
Object format,
Object beforeEach,
Object joinWith,
Object mapFn,
Location loc)
throws EvalException {
if (self.isImmutable()) {
throw new EvalException(null, "cannot modify frozen value");
}
if (value instanceof SkylarkNestedSet || value instanceof SkylarkList) {
self.addVectorArg(value, format, beforeEach, joinWith, mapFn, loc);
} else {
self.addScalarArg(value, format, beforeEach, joinWith, mapFn, loc);
}
return Runtime.NONE;
}
示例8: invoke
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
@SuppressWarnings("unused")
public String invoke(
SkylarkRuleContext ctx,
String input,
SkylarkList targets,
Location loc,
Environment env)
throws EvalException {
ctx.checkMutable("expand_location");
try {
return LocationExpander.withExecPaths(
ctx.getRuleContext(),
makeLabelMap(targets.getContents(TransitiveInfoCollection.class, "targets")))
.expand(input);
} catch (IllegalStateException ise) {
throw new EvalException(loc, ise);
}
}
示例9: labels
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
@SkylarkCallable(
doc =
"Expands all references to labels embedded within a string for all files using a mapping "
+ "from definition labels (i.e. the label in the output type attribute) to files. "
+ "Deprecated.",
documented = false
)
public String expand(
@Nullable String expression, SkylarkList<Object> artifacts, Label labelResolver)
throws EvalException, FuncallException {
checkMutable("expand");
try {
Map<Label, Iterable<Artifact>> labelMap = new HashMap<>();
for (Artifact artifact : artifacts.getContents(Artifact.class, "artifacts")) {
labelMap.put(artifactsLabelMap.get(artifact), ImmutableList.of(artifact));
}
return LabelExpander.expand(expression, labelMap, labelResolver);
} catch (NotUniqueExpansionException e) {
throw new FuncallException(e.getMessage() + " while expanding '" + expression + "'");
}
}
示例10: setAllowedFileTypes
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
private static void setAllowedFileTypes(
String attr, Object fileTypesObj, FuncallExpression ast, Attribute.Builder<?> builder)
throws EvalException {
if (fileTypesObj == Boolean.TRUE) {
builder.allowedFileTypes(FileTypeSet.ANY_FILE);
} else if (fileTypesObj == Boolean.FALSE) {
builder.allowedFileTypes(FileTypeSet.NO_FILE);
} else if (fileTypesObj instanceof SkylarkFileType) {
// TODO(laurentlb): deprecated, to be removed
builder.allowedFileTypes(((SkylarkFileType) fileTypesObj).getFileTypeSet());
} else if (fileTypesObj instanceof SkylarkList) {
List<String> arg =
SkylarkList.castSkylarkListOrNoneToList(
fileTypesObj, String.class, "allow_files argument");
builder.allowedFileTypes(FileType.of(arg));
} else {
throw new EvalException(
ast.getLocation(), attr + " should be a boolean or a string list");
}
}
示例11: buildProviderPredicate
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
/**
* Builds a list of sets of accepted providers from Skylark list {@code obj}.
* The list can either be a list of providers (in that case the result is a list with one
* set) or a list of lists of providers (then the result is the list of sets).
* @param argumentName used in error messages.
* @param location location for error messages.
*/
static ImmutableList<ImmutableSet<SkylarkProviderIdentifier>> buildProviderPredicate(
SkylarkList<?> obj, String argumentName, Location location) throws EvalException {
if (obj.isEmpty()) {
return ImmutableList.of();
}
boolean isListOfProviders = true;
for (Object o : obj) {
if (!isProvider(o)) {
isListOfProviders = false;
break;
}
}
if (isListOfProviders) {
return ImmutableList.of(getSkylarkProviderIdentifiers(obj, location));
} else {
return getProvidersList(obj, argumentName, location);
}
}
示例12: getSkylarkProviderIdentifiers
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
/**
* Converts Skylark identifiers of providers (either a string or a provider value)
* to their internal representations.
*/
static ImmutableSet<SkylarkProviderIdentifier> getSkylarkProviderIdentifiers(
SkylarkList<?> list, Location location) throws EvalException {
ImmutableList.Builder<SkylarkProviderIdentifier> result = ImmutableList.builder();
for (Object obj : list) {
if (obj instanceof String) {
result.add(SkylarkProviderIdentifier.forLegacy((String) obj));
} else if (obj instanceof Provider) {
Provider constructor = (Provider) obj;
if (!constructor.isExported()) {
throw new EvalException(location,
"Providers should be top-level values in extension files that define them.");
}
result.add(SkylarkProviderIdentifier.forKey(constructor.getKey()));
}
}
return ImmutableSet.copyOf(result.build());
}
示例13: getProvidersList
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
private static ImmutableList<ImmutableSet<SkylarkProviderIdentifier>> getProvidersList(
SkylarkList<?> skylarkList, String argumentName, Location location) throws EvalException {
ImmutableList.Builder<ImmutableSet<SkylarkProviderIdentifier>> providersList =
ImmutableList.builder();
String errorMsg = "Illegal argument: element in '%s' is of unexpected type. "
+ "Either all elements should be providers, "
+ "or all elements should be lists of providers, but got %s.";
for (Object o : skylarkList) {
if (!(o instanceof SkylarkList)) {
throw new EvalException(location, String.format(errorMsg, PROVIDERS_ARG,
"an element of type " + EvalUtils.getDataTypeName(o, true)));
}
for (Object value : (SkylarkList) o) {
if (!isProvider(value)) {
throw new EvalException(location, String.format(errorMsg, argumentName,
"list with an element of type "
+ EvalUtils.getDataTypeNameFromClass(value.getClass())));
}
}
providersList.add(getSkylarkProviderIdentifiers((SkylarkList<?>) o, location));
}
return providersList.build();
}
示例14: invoke
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
public Descriptor invoke(
Integer defaultInt,
String doc,
Boolean mandatory,
SkylarkList<?> values,
FuncallExpression ast,
Environment env)
throws EvalException {
// TODO(bazel-team): Replace literal strings with constants.
env.checkLoadingOrWorkspacePhase("attr.int", ast.getLocation());
return createAttrDescriptor(
getName(),
EvalUtils.<String, Object>optionMap(
env, DEFAULT_ARG, defaultInt, MANDATORY_ARG, mandatory, VALUES_ARG, values),
Type.INTEGER,
ast,
env);
}
示例15: javaInfoSourceJarsExposed
import com.google.devtools.build.lib.syntax.SkylarkList; //導入依賴的package包/類
@Test
public void javaInfoSourceJarsExposed() throws Exception {
scratch.file(
"foo/extension.bzl",
"result = provider()",
"def _impl(ctx):",
" return [result(source_jars = ctx.attr.dep[JavaInfo].source_jars)]",
"my_rule = rule(_impl, attrs = { 'dep' : attr.label() })");
scratch.file(
"foo/BUILD",
"load(':extension.bzl', 'my_rule')",
"java_library(name = 'my_java_lib_b', srcs = ['java/B.java'])",
"java_library(name = 'my_java_lib_a', srcs = ['java/A.java'] , deps = [':my_java_lib_b'])",
"my_rule(name = 'my_skylark_rule', dep = ':my_java_lib_a')");
assertNoEvents();
ConfiguredTarget myRuleTarget = getConfiguredTarget("//foo:my_skylark_rule");
Info info = myRuleTarget.get(
new SkylarkKey(Label.parseAbsolute("//foo:extension.bzl"), "result"));
@SuppressWarnings("unchecked") SkylarkList<Artifact> sourceJars =
(SkylarkList<Artifact>) (info.getValue("source_jars"));
assertThat(prettyArtifactNames(sourceJars)).containsExactly("foo/libmy_java_lib_a-src.jar");
assertThat(prettyArtifactNames(sourceJars)).doesNotContain("foo/libmy_java_lib_b-src.jar");
}