Search in sources :

Example 11 with Reporter

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();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) HashMap(java.util.HashMap) Reporter(com.google.devtools.build.lib.events.Reporter) EventBus(com.google.common.eventbus.EventBus) BuildLangTypedAttributeValuesMap(com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap) Test(org.junit.Test)

Example 12 with Reporter

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());
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) HashMap(java.util.HashMap) Reporter(com.google.devtools.build.lib.events.Reporter) EventBus(com.google.common.eventbus.EventBus) BuildLangTypedAttributeValuesMap(com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap) Test(org.junit.Test)

Example 13 with Reporter

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 '.'"));
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) HashMap(java.util.HashMap) Reporter(com.google.devtools.build.lib.events.Reporter) EventBus(com.google.common.eventbus.EventBus) BuildLangTypedAttributeValuesMap(com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap) Test(org.junit.Test)

Example 14 with Reporter

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());
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) Reporter(com.google.devtools.build.lib.events.Reporter) EventBus(com.google.common.eventbus.EventBus)

Example 15 with Reporter

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")));
}
Also used : Reporter(com.google.devtools.build.lib.events.Reporter) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) EventHandler(com.google.devtools.build.lib.events.EventHandler) EventBus(com.google.common.eventbus.EventBus) ExtendedEventHandler(com.google.devtools.build.lib.events.ExtendedEventHandler) MoreAsserts.assertContainsEvent(com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent) Event(com.google.devtools.build.lib.events.Event) Supplier(com.google.common.base.Supplier) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Test(org.junit.Test)

Aggregations

Reporter (com.google.devtools.build.lib.events.Reporter)17 EventBus (com.google.common.eventbus.EventBus)15 Test (org.junit.Test)8 Path (com.google.devtools.build.lib.vfs.Path)7 HashMap (java.util.HashMap)6 BuildLangTypedAttributeValuesMap (com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap)5 Event (com.google.devtools.build.lib.events.Event)3 EventHandler (com.google.devtools.build.lib.events.EventHandler)3 SkyKey (com.google.devtools.build.skyframe.SkyKey)3 SkyValue (com.google.devtools.build.skyframe.SkyValue)3 EventCollector (com.google.devtools.build.lib.events.EventCollector)2 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)2 ArrayList (java.util.ArrayList)2 Supplier (com.google.common.base.Supplier)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Range (com.google.common.collect.Range)1 ActionCacheChecker (com.google.devtools.build.lib.actions.ActionCacheChecker)1 ActionExecutionStatusReporter (com.google.devtools.build.lib.actions.ActionExecutionStatusReporter)1 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)1