use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class RuleFactoryTest method testBuildRuleFailsInWorkspaceFile.
@Test
public void testBuildRuleFailsInWorkspaceFile() throws Exception {
Path myPkgPath = scratch.resolve("/foo/workspace/WORKSPACE");
Package.Builder pkgBuilder = packageFactory.newPackageBuilder(Label.EXTERNAL_PACKAGE_IDENTIFIER, "TESTING").setFilename(myPkgPath).setMakeEnv(new MakeEnvironment.Builder());
Map<String, Object> attributeValues = new HashMap<>();
attributeValues.put("name", "foo");
attributeValues.put("alwayslink", true);
RuleClass ruleClass = provider.getRuleClassMap().get("cc_library");
try {
RuleFactory.createAndAddRule(pkgBuilder, ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(new EventBus()), /*ast=*/
null, Location.fromFileAndOffsets(myPkgPath.asFragment(), 42, 42), /*env=*/
null, new AttributeContainer(ruleClass));
fail();
} catch (RuleFactory.InvalidRuleException e) {
assertThat(e.getMessage()).contains("cannot be in the WORKSPACE file");
}
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class RuleFactoryTest method testCreateRule.
@Test
public void testCreateRule() 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("alwayslink", true);
RuleClass ruleClass = provider.getRuleClassMap().get("cc_library");
Rule rule = RuleFactory.createAndAddRule(pkgBuilder, ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(new EventBus()), /*ast=*/
null, LOCATION_42, /*env=*/
null, new AttributeContainer(ruleClass));
assertSame(rule, rule.getAssociatedRule());
// pkg.getRules() = [rule]
Package pkg = pkgBuilder.build();
assertThat(Sets.newHashSet(pkg.getTargets(Rule.class))).hasSize(1);
assertEquals(rule, pkg.getTargets(Rule.class).iterator().next());
assertSame(rule, pkg.getTarget("foo"));
assertEquals(Label.parseAbsolute("//mypkg:foo"), rule.getLabel());
assertEquals("foo", rule.getName());
assertEquals("cc_library", rule.getRuleClass());
assertEquals("cc_library rule", rule.getTargetKind());
assertEquals(42, rule.getLocation().getStartOffset());
assertFalse(rule.containsErrors());
// Attr with explicitly-supplied value:
AttributeMap attributes = RawAttributeMapper.of(rule);
assertTrue(attributes.get("alwayslink", Type.BOOLEAN));
try {
// type error: boolean, not string!
attributes.get("alwayslink", Type.STRING);
fail();
} catch (Exception e) {
/* Class of exception and error message are not specified by API. */
}
try {
// no such attribute
attributes.get("nosuchattr", Type.STRING);
fail();
} catch (Exception e) {
/* Class of exception and error message are not specified by API. */
}
// Attrs with default values:
// cc_library linkstatic default=0 according to build encyc.
assertFalse(attributes.get("linkstatic", Type.BOOLEAN));
assertFalse(attributes.get("testonly", Type.BOOLEAN));
assertThat(attributes.get("srcs", BuildType.LABEL_LIST)).isEmpty();
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class RuleFactoryTest method testCreateWorkspaceRule.
@Test
public void testCreateWorkspaceRule() throws Exception {
Path myPkgPath = scratch.resolve("/foo/workspace/WORKSPACE");
Package.Builder pkgBuilder = packageFactory.newExternalPackageBuilder(myPkgPath, "TESTING");
Map<String, Object> attributeValues = new HashMap<>();
attributeValues.put("name", "foo");
attributeValues.put("actual", "//foo:bar");
RuleClass ruleClass = provider.getRuleClassMap().get("bind");
Rule rule = RuleFactory.createAndAddRule(pkgBuilder, ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(new EventBus()), /*ast=*/
null, Location.fromFileAndOffsets(myPkgPath.asFragment(), 42, 42), /*env=*/
null, new AttributeContainer(ruleClass));
assertFalse(rule.containsErrors());
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class RuleFactoryTest method testOutputFileNotEqualDot.
@Test
public void testOutputFileNotEqualDot() throws Exception {
Path myPkgPath = scratch.resolve("/foo");
Package.Builder pkgBuilder = packageFactory.newPackageBuilder(PackageIdentifier.createInMainRepo("mypkg"), "TESTING").setFilename(myPkgPath).setMakeEnv(new MakeEnvironment.Builder());
Map<String, Object> attributeValues = new HashMap<>();
attributeValues.put("outs", Lists.newArrayList("."));
attributeValues.put("name", "some");
RuleClass ruleClass = provider.getRuleClassMap().get("genrule");
try {
RuleFactory.createAndAddRule(pkgBuilder, ruleClass, new BuildLangTypedAttributeValuesMap(attributeValues), new Reporter(new EventBus()), /*ast=*/
null, Location.fromFileAndOffsets(myPkgPath.asFragment(), 42, 42), /*env=*/
null, new AttributeContainer(ruleClass));
fail();
} catch (RuleFactory.InvalidRuleException e) {
assertTrue(e.getMessage(), e.getMessage().contains("output file name can't be equal '.'"));
}
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class PrepareDepsOfPatternsFunctionTest method getGraphFromPatternsEvaluation.
private WalkableGraph getGraphFromPatternsEvaluation(ImmutableList<String> patternSequence, boolean keepGoing) throws InterruptedException {
SkyKey independentTarget = PrepareDepsOfPatternsValue.key(patternSequence, "");
ImmutableList<SkyKey> singletonTargetPattern = ImmutableList.of(independentTarget);
// When PrepareDepsOfPatternsFunction completes evaluation,
EvaluationResult<SkyValue> evaluationResult = getSkyframeExecutor().getDriverForTesting().evaluate(singletonTargetPattern, keepGoing, LOADING_PHASE_THREADS, new Reporter(new EventBus(), eventCollector));
// Currently all callers either expect success or pass keepGoing=true, which implies success,
// since PrepareDepsOfPatternsFunction swallows all errors. Will need to be changed if a test
// that evaluates with keepGoing=false and expects errors is added.
assertThatEvaluationResult(evaluationResult).hasNoError();
return Preconditions.checkNotNull(evaluationResult.getWalkableGraph());
}
Aggregations