Search in sources :

Example 6 with StoredEventHandler

use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.

the class AspectFunction method createAspect.

@Nullable
private AspectValue createAspect(Environment env, AspectKey key, ImmutableList<Aspect> aspectPath, Aspect aspect, ConfiguredAspectFactory aspectFactory, ConfiguredTarget associatedTarget, BuildConfiguration aspectConfiguration, ImmutableMap<Label, ConfigMatchingProvider> configConditions, OrderedSetMultimap<Attribute, ConfiguredTarget> directDeps, NestedSetBuilder<Package> transitivePackages) throws AspectFunctionException, InterruptedException {
    SkyframeBuildView view = buildViewProvider.getSkyframeBuildView();
    StoredEventHandler events = new StoredEventHandler();
    CachingAnalysisEnvironment analysisEnvironment = view.createAnalysisEnvironment(key, false, events, env, aspectConfiguration);
    if (env.valuesMissing()) {
        return null;
    }
    ConfiguredAspect configuredAspect;
    if (ConfiguredTargetFunction.aspectMatchesConfiguredTarget(associatedTarget, aspect)) {
        configuredAspect = view.getConfiguredTargetFactory().createAspect(analysisEnvironment, associatedTarget, aspectPath, aspectFactory, aspect, directDeps, configConditions, aspectConfiguration, view.getHostConfiguration(aspectConfiguration));
    } else {
        configuredAspect = ConfiguredAspect.forNonapplicableTarget(aspect.getDescriptor());
    }
    events.replayOn(env.getListener());
    if (events.hasErrors()) {
        analysisEnvironment.disable(associatedTarget.getTarget());
        throw new AspectFunctionException(new AspectCreationException("Analysis of target '" + associatedTarget.getLabel() + "' failed; build aborted"));
    }
    Preconditions.checkState(!analysisEnvironment.hasErrors(), "Analysis environment hasError() but no errors reported");
    if (env.valuesMissing()) {
        return null;
    }
    analysisEnvironment.disable(associatedTarget.getTarget());
    Preconditions.checkNotNull(configuredAspect);
    return new AspectValue(key, aspect, associatedTarget.getLabel(), associatedTarget.getTarget().getLocation(), configuredAspect, ImmutableList.copyOf(analysisEnvironment.getRegisteredActions()), transitivePackages.build());
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) CachingAnalysisEnvironment(com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment) Nullable(javax.annotation.Nullable)

Example 7 with StoredEventHandler

use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.

the class ResolverTest method testArtifactResolution.

@Test
public void testArtifactResolution() throws Exception {
    StoredEventHandler handler = new StoredEventHandler();
    DefaultModelResolver modelResolver = Mockito.mock(DefaultModelResolver.class);
    Resolver resolver = new Resolver(handler, modelResolver);
    resolver.resolveArtifact("x:y:1.2.3");
    Collection<Rule> rules = resolver.getRules();
    assertThat(rules).hasSize(1);
    Rule rule = rules.iterator().next();
    assertThat(rule.name()).isEqualTo("x_y");
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) Test(org.junit.Test)

Example 8 with StoredEventHandler

use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.

the class BuildViewTestCase method getRuleContextForSkylark.

/**
   * Creates and returns a rule context to use for Skylark tests that is equivalent to the one
   * that was used to create the given configured target.
   */
protected RuleContext getRuleContextForSkylark(ConfiguredTarget target) throws Exception {
    // TODO(bazel-team): we need this horrible workaround because CachingAnalysisEnvironment
    // only works with StoredErrorEventListener despite the fact it accepts the interface
    // ErrorEventListener, so it's not possible to create it with reporter.
    // See BuildView.getRuleContextForTesting().
    StoredEventHandler eventHandler = new StoredEventHandler() {

        @Override
        public synchronized void handle(Event e) {
            super.handle(e);
            reporter.handle(e);
        }
    };
    return view.getRuleContextForTesting(target, eventHandler, masterConfig);
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) Event(com.google.devtools.build.lib.events.Event)

Example 9 with StoredEventHandler

use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.

the class BlazeExecutorTest method testDebugPrintActionContexts.

@Test
public void testDebugPrintActionContexts() throws Exception {
    TestExecutorBuilder builder = new TestExecutorBuilder(directories, binTools);
    OptionsParser parser = OptionsParser.newOptionsParser(TestExecutorBuilder.DEFAULT_OPTIONS);
    parser.parse("--debug_print_action_contexts");
    Reporter reporter = new Reporter(new EventBus());
    StoredEventHandler storedEventHandler = new StoredEventHandler();
    reporter.addHandler(storedEventHandler);
    SpawnActionContext mockStrategy = Mockito.mock(SpawnActionContext.class);
    builder.setReporter(reporter).setOptionsParser(parser).setExecution("mock", mockStrategy);
    builder.build();
    Event event = Iterables.find(storedEventHandler.getEvents(), new Predicate<Event>() {

        @Override
        public boolean apply(@Nullable Event event) {
            return event.getMessage().contains("SpawnActionContextMap: \"mock\" = ");
        }
    });
    assertThat(event).isNotNull();
    assertThat(event.getMessage()).contains("\"mock\" = " + mockStrategy.getClass().getSimpleName());
}
Also used : TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) Reporter(com.google.devtools.build.lib.events.Reporter) Event(com.google.devtools.build.lib.events.Event) EventBus(com.google.common.eventbus.EventBus) OptionsParser(com.google.devtools.common.options.OptionsParser) SpawnActionContext(com.google.devtools.build.lib.actions.SpawnActionContext) Test(org.junit.Test)

Example 10 with StoredEventHandler

use of com.google.devtools.build.lib.events.StoredEventHandler in project bazel by bazelbuild.

the class SubincludePreprocessor method preprocess.

@Override
public Preprocessor.Result preprocess(Path buildFilePath, byte[] buildFileBytes, String packageName, Globber globber, Set<String> ruleNames) throws IOException, InterruptedException {
    StoredEventHandler eventHandler = new StoredEventHandler();
    char[] content = FileSystemUtils.convertFromLatin1(buildFileBytes);
    while (true) {
        Matcher matcher = SUBINCLUDE_REGEX.matcher(CharBuffer.wrap(content));
        if (!matcher.find()) {
            break;
        }
        String name = matcher.group(1);
        String path = resolveSubinclude(name);
        char[] subContent;
        if (path.isEmpty()) {
            // This location is not correct, but will do for testing purposes.
            eventHandler.handle(Event.error(Location.fromFile(buildFilePath), "Cannot find subincluded file \'" + name + "\'"));
            // Emit a mocksubinclude(), so we know to preprocess again if the file becomes
            // visible. We cannot fail the preprocess here, as it would drop the content.
            subContent = new char[0];
        } else {
            // TODO(bazel-team): figure out the correct behavior for a non-existent file from an
            // existent package.
            subContent = FileSystemUtils.readContentAsLatin1(fileSystem.getPath(path));
        }
        String mock = "\nmocksubinclude('" + name + "', '" + path + "')\n";
        content = Chars.concat(Arrays.copyOf(content, matcher.start()), mock.toCharArray(), subContent, Arrays.copyOfRange(content, matcher.end(), content.length));
    }
    if (Chars.indexOf(content, TRANSIENT_ERROR.toCharArray()) >= 0) {
        throw new IOException("transient error requested in " + buildFilePath.asFragment());
    }
    return Preprocessor.Result.success(ParserInputSource.create(content, buildFilePath.asFragment()), eventHandler.hasErrors(), eventHandler.getEvents());
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) Matcher(java.util.regex.Matcher) IOException(java.io.IOException)

Aggregations

StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)21 IOException (java.io.IOException)6 Test (org.junit.Test)6 ImmutableList (com.google.common.collect.ImmutableList)5 Artifact (com.google.devtools.build.lib.actions.Artifact)5 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)5 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)4 SkyKey (com.google.devtools.build.skyframe.SkyKey)4 List (java.util.List)4 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)3 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)3 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)3 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)3 BuildFileAST (com.google.devtools.build.lib.syntax.BuildFileAST)3 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)3 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)3 Nullable (javax.annotation.Nullable)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 CachingAnalysisEnvironment (com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment)2 Event (com.google.devtools.build.lib.events.Event)2