本文整理汇总了Java中com.google.devtools.build.lib.syntax.Environment类的典型用法代码示例。如果您正苦于以下问题:Java Environment类的具体用法?Java Environment怎么用?Java Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Environment类属于com.google.devtools.build.lib.syntax包,在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的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;
}
示例2: createGlobals
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
/**
* Create native global variables from the modules
*
* <p>The returned object can be reused for different instances of environments.
*/
private Environment.Frame createGlobals(
EventHandler eventHandler, Options options, ConfigFile<?> currentConfigFile,
ConfigFile<?> mainConfigFile,
Supplier<ImmutableMap<String, ? extends ConfigFile<?>>> configFilesSupplier) {
Environment env = createEnvironment(eventHandler, Environment.SKYLARK,
ImmutableMap.of());
for (Class<?> module : modules) {
logger.log(Level.INFO, "Creating variable for " + module.getName());
// Create the module object and associate it with the functions
Runtime.registerModuleGlobals(env, module);
// Add the options to the module that require them
if (OptionsAwareModule.class.isAssignableFrom(module)) {
((OptionsAwareModule) getModuleGlobal(env, module)).setOptions(options);
}
if (LabelsAwareModule.class.isAssignableFrom(module)) {
((LabelsAwareModule) getModuleGlobal(env, module))
.setConfigFile(mainConfigFile, currentConfigFile);
((LabelsAwareModule) getModuleGlobal(env, module))
.setAllConfigResources(configFilesSupplier);
}
}
env.mutability().close();
return env.getGlobals();
}
示例3: SkylarkDefinedAspect
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
public SkylarkDefinedAspect(
BaseFunction implementation,
ImmutableList<String> attributeAspects,
ImmutableList<Attribute> attributes,
ImmutableList<ImmutableSet<SkylarkProviderIdentifier>> requiredAspectProviders,
ImmutableSet<SkylarkProviderIdentifier> provides,
ImmutableSet<String> paramAttributes,
ImmutableSet<String> fragments,
// The host transition is in lib.analysis, so we can't reference it directly here.
ConfigurationTransition hostTransition,
ImmutableSet<String> hostFragments,
ImmutableList<Label> requiredToolchains,
Environment funcallEnv) {
this.implementation = implementation;
this.attributeAspects = attributeAspects;
this.attributes = attributes;
this.requiredAspectProviders = requiredAspectProviders;
this.provides = provides;
this.paramAttributes = paramAttributes;
this.fragments = fragments;
this.hostTransition = hostTransition;
this.hostFragments = hostFragments;
this.requiredToolchains = requiredToolchains;
this.funcallEnv = funcallEnv;
}
示例4: callGetRulesFunction
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
static SkylarkDict<String, SkylarkDict<String, Object>> callGetRulesFunction(
FuncallExpression ast, Environment env)
throws EvalException {
PackageContext context = getContext(env, ast);
Collection<Target> targets = context.pkgBuilder.getTargets();
Location loc = ast.getLocation();
SkylarkDict<String, SkylarkDict<String, Object>> rules = SkylarkDict.of(env);
for (Target t : targets) {
if (t instanceof Rule) {
SkylarkDict<String, Object> m = targetDict(t, loc, env);
Preconditions.checkNotNull(m);
rules.put(t.getName(), m, loc, env);
}
}
return rules;
}
示例5: createAndAddRule
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
/**
* Creates a {@link Rule} instance, adds it to the {@link Package.Builder} and returns it.
*
* @param pkgBuilder the under-construction {@link Package.Builder} to which the rule belongs
* @param ruleClass the {@link RuleClass} of the rule
* @param attributeValues a {@link BuildLangTypedAttributeValuesMap} mapping attribute names to
* attribute values of build-language type. Each attribute must be defined for this class of
* rule, and have a build-language-typed value which can be converted to the appropriate
* native type of the attribute (i.e. via {@link BuildType#selectableConvert}). There must
* be a map entry for each non-optional attribute of this class of rule.
* @param eventHandler a eventHandler on which errors and warnings are reported during
* rule creation
* @param ast the abstract syntax tree of the rule expression (optional)
* @param location the location at which this rule was declared
* @param env the lexical environment of the function call which declared this rule (optional)
* @param attributeContainer the {@link AttributeContainer} the rule will contain
* @throws InvalidRuleException if the rule could not be constructed for any
* reason (e.g. no {@code name} attribute is defined)
* @throws NameConflictException if the rule's name or output files conflict with others in this
* package
* @throws InterruptedException if interrupted
*/
static Rule createAndAddRule(
Package.Builder pkgBuilder,
RuleClass ruleClass,
BuildLangTypedAttributeValuesMap attributeValues,
EventHandler eventHandler,
@Nullable FuncallExpression ast,
Location location,
@Nullable Environment env,
AttributeContainer attributeContainer)
throws InvalidRuleException, NameConflictException, InterruptedException {
Rule rule =
createRule(
pkgBuilder,
ruleClass,
attributeValues,
eventHandler,
ast,
location,
env,
attributeContainer);
pkgBuilder.addRule(rule);
return rule;
}
示例6: createGlobals
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
private Environment.Frame createGlobals(
ImmutableMap<String, Object> skylarkAccessibleToplLevels,
ImmutableList<Class<?>> modules) {
try (Mutability mutability = Mutability.create("ConfiguredRuleClassProvider globals")) {
Environment env = createSkylarkRuleClassEnvironment(
mutability,
SkylarkModules.getGlobals(modules),
SkylarkSemantics.DEFAULT_SEMANTICS,
/*eventHandler=*/ null,
/*astFileContentHashCode=*/ null,
/*importMap=*/ null);
for (Map.Entry<String, Object> entry : skylarkAccessibleToplLevels.entrySet()) {
env.setup(entry.getKey(), entry.getValue());
}
return env.getGlobals();
}
}
示例7: createSkylarkRuleClassEnvironment
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
private Environment createSkylarkRuleClassEnvironment(
Mutability mutability,
Environment.Frame globals,
SkylarkSemantics skylarkSemantics,
EventHandler eventHandler,
String astFileContentHashCode,
Map<String, Extension> importMap) {
Environment env =
Environment.builder(mutability)
.setGlobals(globals)
.setSemantics(skylarkSemantics)
.setEventHandler(eventHandler)
.setFileContentHashCode(astFileContentHashCode)
.setImportedExtensions(importMap)
.setPhase(Phase.LOADING)
.build();
SkylarkUtils.setToolsRepository(env, toolsRepository);
SkylarkUtils.setFragmentMap(env, configurationFragmentMap);
SkylarkUtils.setLipoDataTransition(env, getLipoDataTransition());
return env;
}
示例8: invoke
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "unused"})
public Label invoke(
String labelString, Boolean relativeToCallerRepository, Location loc, Environment env)
throws EvalException {
Label parentLabel = null;
if (relativeToCallerRepository) {
parentLabel = env.getCallerLabel();
} else {
parentLabel = env.getGlobals().getTransitiveLabel();
}
try {
if (parentLabel != null) {
LabelValidator.parseAbsoluteLabel(labelString);
labelString = parentLabel.getRelative(labelString).getUnambiguousCanonicalForm();
}
return labelCache.get(labelString);
} catch (LabelValidator.BadLabelException | LabelSyntaxException | ExecutionException e) {
throw new EvalException(loc, "Illegal absolute label syntax: " + labelString);
}
}
示例9: invoke
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的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);
}
}
示例10: createNonconfigurableAttrDescriptor
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
private static Descriptor createNonconfigurableAttrDescriptor(
String name,
SkylarkDict<String, Object> kwargs,
Type<?> type,
FuncallExpression ast,
Environment env)
throws EvalException {
String whyNotConfigurableReason =
Preconditions.checkNotNull(maybeGetNonConfigurableReason(type), type);
try {
return new Descriptor(
name, createAttribute(type, kwargs, ast, env).nonconfigurable(whyNotConfigurableReason));
} catch (ConversionException e) {
throw new EvalException(ast.getLocation(), e.getMessage());
}
}
示例11: invoke
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的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);
}
示例12: makeBigStruct
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
private static Info makeBigStruct(Environment env) {
// struct(a=[struct(x={1:1}), ()], b=(), c={2:2})
return NativeProvider.STRUCT.create(
ImmutableMap.<String, Object>of(
"a",
MutableList.<Object>of(
env,
NativeProvider.STRUCT.create(
ImmutableMap.<String, Object>of(
"x", SkylarkDict.<Object, Object>of(env, 1, 1)),
"no field '%s'"),
Tuple.of()),
"b", Tuple.of(),
"c", SkylarkDict.<Object, Object>of(env, 2, 2)),
"no field '%s'");
}
示例13: getBuckGlobals
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
/**
* @return The environment frame with configured buck globals. This includes built-in rules like
* {@code java_library}.
* @param disableImplicitNativeRules If true, do not export native rules into the provided context
*/
private Environment.Frame getBuckGlobals(boolean disableImplicitNativeRules) {
Environment.Frame buckGlobals;
try (Mutability mutability = Mutability.create("global")) {
Environment globalEnv =
Environment.builder(mutability)
.setGlobals(BazelLibrary.GLOBALS)
.useDefaultSemantics()
.build();
BuiltinFunction readConfigFunction = ReadConfig.create();
globalEnv.setup(readConfigFunction.getName(), readConfigFunction);
if (!disableImplicitNativeRules) {
for (BuiltinFunction buckRuleFunction : buckRuleFunctionsSupplier.get()) {
globalEnv.setup(buckRuleFunction.getName(), buckRuleFunction);
}
}
buckGlobals = globalEnv.getGlobals();
}
return buckGlobals;
}
示例14: newRuleDefinition
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
/**
* Create a Skylark definition for the {@code ruleClass} rule.
*
* <p>This makes functions like @{code java_library} available in build files. All they do is
* capture passed attribute values in a map and adds them to the {@code ruleRegistry}.
*
* @param ruleClass The name of the rule to to define.
* @return Skylark function to handle the Buck rule.
*/
private BuiltinFunction newRuleDefinition(Description<?> ruleClass) {
String name = Description.getBuildRuleType(ruleClass).getName();
return new BuiltinFunction(
name, FunctionSignature.KWARGS, BuiltinFunction.USE_AST_ENV, /*isRule=*/ true) {
@SuppressWarnings({"unused"})
public Runtime.NoneType invoke(
Map<String, Object> kwargs, FuncallExpression ast, Environment env) throws EvalException {
ImmutableMap.Builder<String, Object> builder =
ImmutableMap.<String, Object>builder()
.put("buck.base_path", env.lookup(Runtime.PKG_NAME))
.put("buck.type", name);
ImmutableMap<String, ParamInfo> allParamInfo =
CoercedTypeCache.INSTANCE.getAllParamInfo(
typeCoercerFactory, ruleClass.getConstructorArgType());
populateAttributes(kwargs, builder, allParamInfo);
throwOnMissingRequiredAttribute(kwargs, allParamInfo, getName(), ast);
ParseContext parseContext = getParseContext(env, ast);
parseContext.recordRule(builder.build());
return Runtime.NONE;
}
};
}
示例15: testGlobBadPathsFailsWithNiceError
import com.google.devtools.build.lib.syntax.Environment; //导入依赖的package包/类
@Test
public void testGlobBadPathsFailsWithNiceError() throws Exception {
FileSystemUtils.createDirectoryAndParents(root.getChild("some_dir"));
Path buildFile = root.getChild("BUCK");
FileSystemUtils.writeContentAsLatin1(buildFile, "txts = glob(['non_existent'])");
SingleCapturingEventHandler handler = new SingleCapturingEventHandler();
try (Mutability mutability = Mutability.create("BUCK")) {
Pair<Boolean, Environment> result = evaluate(buildFile, mutability, handler);
Assert.assertFalse(result.getFirst());
}
Event event = handler.getLastEvent();
Location loc = event.getLocation();
Assert.assertNotNull(loc);
Assert.assertEquals(1, loc.getStartLine().intValue());
Assert.assertEquals(7, loc.getStartOffset());
Assert.assertTrue(event.getMessage().matches("Cannot find .*non_existent"));
}