Search in sources :

Example 1 with StoredEventHandler

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

the class PackageFactory method createPackageFromPreprocessingResult.

/****************************************************************************
   * Package creation.
   */
/**
   * Loads, scans parses and evaluates the build file at "buildFile", and
   * creates and returns a Package builder instance capable of building a package identified by
   * "packageId".
   *
   * <p>This method returns a builder to allow the caller to do additional work, if necessary.
   *
   * <p>This method assumes "packageId" is a valid package name according to the
   * {@link LabelValidator#validatePackageName} heuristic.
   *
   * <p>See {@link #evaluateBuildFile} for information on AST retention.
   *
   * <p>Executes {@code globber.onCompletion()} on completion and executes
   * {@code globber.onInterrupt()} on an {@link InterruptedException}.
   */
// Used outside of bazel!
public Package.Builder createPackageFromPreprocessingResult(String workspaceName, PackageIdentifier packageId, Path buildFile, Preprocessor.Result preprocessingResult, List<Statement> preludeStatements, Map<String, Extension> imports, ImmutableList<Label> skylarkFileDependencies, RuleVisibility defaultVisibility, Globber globber) throws InterruptedException {
    StoredEventHandler localReporterForParsing = new StoredEventHandler();
    // Run the lexer and parser with a local reporter, so that errors from other threads do not
    // show up below.
    BuildFileAST buildFileAST = parseBuildFile(packageId, preprocessingResult.result, preludeStatements, localReporterForParsing);
    AstAfterPreprocessing astAfterPreprocessing = new AstAfterPreprocessing(preprocessingResult, buildFileAST, localReporterForParsing);
    return createPackageFromPreprocessingAst(workspaceName, packageId, buildFile, astAfterPreprocessing, imports, skylarkFileDependencies, defaultVisibility, globber);
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) AstAfterPreprocessing(com.google.devtools.build.lib.packages.Preprocessor.AstAfterPreprocessing) BuildFileAST(com.google.devtools.build.lib.syntax.BuildFileAST)

Example 2 with StoredEventHandler

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

the class WorkspaceFactory method execute.

/**
   * Actually runs through the AST, calling the functions in the WORKSPACE file and adding rules
   * to the //external package.
   */
public void execute(BuildFileAST ast, Map<String, Extension> importedExtensions) throws InterruptedException {
    Preconditions.checkNotNull(ast);
    Preconditions.checkNotNull(importedExtensions);
    execute(ast, importedExtensions, new StoredEventHandler());
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler)

Example 3 with StoredEventHandler

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

the class WorkspaceFactory method parse.

@VisibleForTesting
public void parse(ParserInputSource source, @Nullable StoredEventHandler localReporter) throws BuildFileContainsErrorsException, InterruptedException {
    // because most people are just using it to resolve Maven dependencies.
    if (localReporter == null) {
        localReporter = new StoredEventHandler();
    }
    BuildFileAST buildFileAST = BuildFileAST.parseBuildFile(source, localReporter);
    if (buildFileAST.containsErrors()) {
        throw new BuildFileContainsErrorsException(Label.EXTERNAL_PACKAGE_IDENTIFIER, "Failed to parse " + source.getPath());
    }
    execute(buildFileAST, null, localReporter);
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) BuildFileAST(com.google.devtools.build.lib.syntax.BuildFileAST) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with StoredEventHandler

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

the class TreeArtifactBuildTest method testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected.

@Test
public void testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected() throws Exception {
    // Failure expected
    StoredEventHandler storingEventHandler = new StoredEventHandler();
    reporter.removeHandler(failFastHandler);
    reporter.addHandler(storingEventHandler);
    final Artifact out = createTreeArtifact("output");
    TreeArtifactTestAction action = new TreeArtifactTestAction(out) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) {
            try {
                writeFile(out.getPath().getChild("one"), "one");
                writeFile(out.getPath().getChild("two"), "two");
                FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../../output/random/pointer");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(action);
    try {
        buildArtifact(action.getSoleOutput());
        // Should have thrown
        fail();
    } catch (BuildFailedException e) {
        List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
        assertThat(errors).hasSize(2);
        assertThat(errors.get(0).getMessage()).contains("A TreeArtifact may not contain relative symlinks whose target paths traverse " + "outside of the TreeArtifact");
        assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
    }
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) ActionInputHelper.treeFileArtifact(com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with StoredEventHandler

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

the class ConfiguredTargetFunction method createConfiguredTarget.

@Nullable
private ConfiguredTargetValue createConfiguredTarget(SkyframeBuildView view, Environment env, Target target, BuildConfiguration configuration, OrderedSetMultimap<Attribute, ConfiguredTarget> depValueMap, ImmutableMap<Label, ConfigMatchingProvider> configConditions, NestedSetBuilder<Package> transitivePackages) throws ConfiguredTargetFunctionException, InterruptedException {
    StoredEventHandler events = new StoredEventHandler();
    BuildConfiguration ownerConfig = (configuration == null) ? null : configuration.getArtifactOwnerConfiguration();
    CachingAnalysisEnvironment analysisEnvironment = view.createAnalysisEnvironment(new ConfiguredTargetKey(target.getLabel(), ownerConfig), false, events, env, configuration);
    if (env.valuesMissing()) {
        return null;
    }
    Preconditions.checkNotNull(depValueMap);
    ConfiguredTarget configuredTarget = view.createConfiguredTarget(target, configuration, analysisEnvironment, depValueMap, configConditions);
    events.replayOn(env.getListener());
    if (events.hasErrors()) {
        analysisEnvironment.disable(target);
        throw new ConfiguredTargetFunctionException(new ConfiguredValueCreationException("Analysis of target '" + target.getLabel() + "' failed; build aborted", target.getLabel()));
    }
    Preconditions.checkState(!analysisEnvironment.hasErrors(), "Analysis environment hasError() but no errors reported");
    if (env.valuesMissing()) {
        return null;
    }
    analysisEnvironment.disable(target);
    Preconditions.checkNotNull(configuredTarget, target);
    ImmutableMap<Artifact, ActionAnalysisMetadata> generatingActions;
    // rule implementation).
    try {
        generatingActions = Actions.filterSharedActionsAndThrowActionConflict(analysisEnvironment.getRegisteredActions());
    } catch (ActionConflictException e) {
        throw new ConfiguredTargetFunctionException(e);
    }
    return new ConfiguredTargetValue(configuredTarget, generatingActions, transitivePackages.build());
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) CachingAnalysisEnvironment(com.google.devtools.build.lib.analysis.CachingAnalysisEnvironment) Artifact(com.google.devtools.build.lib.actions.Artifact) Nullable(javax.annotation.Nullable)

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