use of com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap in project bazel by bazelbuild.
the class PackageFactory method addRule.
// Helper function for createRuleFunction.
private static void addRule(RuleFactory ruleFactory, String ruleClassName, PackageContext context, Map<String, Object> kwargs, FuncallExpression ast, Environment env) throws RuleFactory.InvalidRuleException, Package.NameConflictException, InterruptedException {
RuleClass ruleClass = getBuiltInRuleClass(ruleClassName, ruleFactory);
BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(kwargs);
AttributeContainer attributeContainer = ruleFactory.getAttributeContainer(ruleClass);
RuleFactory.createAndAddRule(context, ruleClass, attributeValues, ast, env, attributeContainer);
}
use of com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap in project bazel by bazelbuild.
the class RuleClassTest method createRule.
private Rule createRule(RuleClass ruleClass, String name, Map<String, Object> attributeValues, Location location) throws LabelSyntaxException, InterruptedException, CannotPrecomputeDefaultsException {
Package.Builder pkgBuilder = createDummyPackageBuilder();
Label ruleLabel;
try {
ruleLabel = pkgBuilder.createLabel(name);
} catch (LabelSyntaxException e) {
throw new IllegalArgumentException("Rule has illegal label");
}
return ruleClass.createRule(pkgBuilder, ruleLabel, new BuildLangTypedAttributeValuesMap(attributeValues), reporter, /*ast=*/
null, location, new AttributeContainer(ruleClass));
}
use of com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap in project bazel by bazelbuild.
the class RuleFactoryTest method testWorkspaceRuleFailsInBuildFile.
@Test
public void testWorkspaceRuleFailsInBuildFile() throws Exception {
Path myPkgPath = scratch.resolve("/foo/workspace/mypkg/BUILD");
Package.Builder pkgBuilder = packageFactory.newPackageBuilder(PackageIdentifier.createInMainRepo("mypkg"), "TESTING").setFilename(myPkgPath).setMakeEnv(new MakeEnvironment.Builder());
Map<String, Object> attributeValues = new HashMap<>();
attributeValues.put("name", "foo");
attributeValues.put("actual", "//bar:baz");
RuleClass ruleClass = provider.getRuleClassMap().get("bind");
try {
RuleFactory.createAndAddRule(pkgBuilder, ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(new EventBus()), /*ast=*/
null, LOCATION_42, /*env=*/
null, new AttributeContainer(ruleClass));
fail();
} catch (RuleFactory.InvalidRuleException e) {
assertThat(e.getMessage()).contains("must be in the WORKSPACE file");
}
}
use of com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap in project bazel by bazelbuild.
the class ExternalPackageBuilder method createAndAddRepositoryRule.
public Rule createAndAddRepositoryRule(Package.Builder pkg, RuleClass ruleClass, RuleClass bindRuleClass, Map<String, Object> kwargs, FuncallExpression ast) throws RuleFactory.InvalidRuleException, Package.NameConflictException, LabelSyntaxException, InterruptedException {
StoredEventHandler eventHandler = new StoredEventHandler();
BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(kwargs);
Rule rule = RuleFactory.createRule(pkg, ruleClass, attributeValues, eventHandler, ast, ast.getLocation(), /*env=*/
null, new AttributeContainer(ruleClass));
pkg.addEvents(eventHandler.getEvents());
overwriteRule(pkg, rule);
for (Map.Entry<String, Label> entry : ruleClass.getExternalBindingsFunction().apply(rule).entrySet()) {
Label nameLabel = Label.parseAbsolute("//external:" + entry.getKey());
addBindRule(pkg, bindRuleClass, nameLabel, entry.getValue(), rule.getLocation(), new AttributeContainer(bindRuleClass));
}
return rule;
}
use of com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap in project bazel by bazelbuild.
the class ExternalPackageBuilder method addBindRule.
static void addBindRule(Builder pkg, RuleClass bindRuleClass, Label virtual, Label actual, Location location, AttributeContainer attributeContainer) throws RuleFactory.InvalidRuleException, Package.NameConflictException, InterruptedException {
Map<String, Object> attributes = Maps.newHashMap();
// Bound rules don't have a name field, but this works because we don't want more than one
// with the same virtual name.
attributes.put("name", virtual.getName());
if (actual != null) {
attributes.put("actual", actual);
}
StoredEventHandler handler = new StoredEventHandler();
BuildLangTypedAttributeValuesMap attributeValues = new BuildLangTypedAttributeValuesMap(attributes);
Rule rule = RuleFactory.createRule(pkg, bindRuleClass, attributeValues, handler, /*ast=*/
null, location, /*env=*/
null, attributeContainer);
overwriteRule(pkg, rule);
rule.setVisibility(ConstantRuleVisibility.PUBLIC);
}
Aggregations