use of com.google.devtools.build.lib.events.Reporter 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.devtools.build.lib.events.Reporter 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.devtools.build.lib.events.Reporter 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.devtools.build.lib.events.Reporter 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());
}
use of com.google.devtools.build.lib.events.Reporter in project bazel by bazelbuild.
the class ParallelEvaluatorTest method signalValueEnqueuedAndEvaluated.
@Test
public void signalValueEnqueuedAndEvaluated() throws Exception {
final Set<SkyKey> enqueuedValues = Sets.newConcurrentHashSet();
final Set<SkyKey> evaluatedValues = Sets.newConcurrentHashSet();
EvaluationProgressReceiver progressReceiver = new EvaluationProgressReceiver() {
@Override
public void invalidated(SkyKey skyKey, InvalidationState state) {
throw new IllegalStateException();
}
@Override
public void enqueueing(SkyKey skyKey) {
enqueuedValues.add(skyKey);
}
@Override
public void computed(SkyKey skyKey, long elapsedTimeNanos) {
}
@Override
public void evaluated(SkyKey skyKey, Supplier<SkyValue> skyValueSupplier, EvaluationState state) {
evaluatedValues.add(skyKey);
}
};
ExtendedEventHandler reporter = new Reporter(new EventBus(), new EventHandler() {
@Override
public void handle(Event e) {
throw new IllegalStateException();
}
});
MemoizingEvaluator aug = new InMemoryMemoizingEvaluator(ImmutableMap.of(GraphTester.NODE_TYPE, tester.getFunction()), new RecordingDifferencer(), progressReceiver);
SequentialBuildDriver driver = new SequentialBuildDriver(aug);
tester.getOrCreate("top1").setComputedValue(CONCATENATE).addDependency("d1").addDependency("d2");
tester.getOrCreate("top2").setComputedValue(CONCATENATE).addDependency("d3");
tester.getOrCreate("top3");
assertThat(enqueuedValues).isEmpty();
assertThat(evaluatedValues).isEmpty();
tester.set("d1", new StringValue("1"));
tester.set("d2", new StringValue("2"));
tester.set("d3", new StringValue("3"));
driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top1")), false, 200, reporter);
assertThat(enqueuedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1", "d1", "d2")));
assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1", "d1", "d2")));
enqueuedValues.clear();
evaluatedValues.clear();
driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top2")), false, 200, reporter);
assertThat(enqueuedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top2", "d3")));
assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top2", "d3")));
enqueuedValues.clear();
evaluatedValues.clear();
driver.evaluate(ImmutableList.of(GraphTester.toSkyKey("top1")), false, 200, reporter);
assertThat(enqueuedValues).isEmpty();
assertThat(evaluatedValues).containsExactlyElementsIn(Arrays.asList(GraphTester.toSkyKeys("top1")));
}
Aggregations