Search in sources :

Example 6 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class BuildResultPrinter method showArtifacts.

/**
   * Prints a flat list of all artifacts built by the passed top-level targets.
   *
   * <p>This corresponds to the --experimental_show_artifacts flag.
   */
public void showArtifacts(BuildRequest request, Collection<ConfiguredTarget> configuredTargets, Collection<AspectValue> aspects) {
    TopLevelArtifactContext context = request.getTopLevelArtifactContext();
    Collection<ConfiguredTarget> targetsToPrint = filterTargetsToPrint(configuredTargets);
    Collection<AspectValue> aspectsToPrint = filterAspectsToPrint(aspects);
    NestedSetBuilder<Artifact> artifactsBuilder = NestedSetBuilder.stableOrder();
    for (ConfiguredTarget target : targetsToPrint) {
        artifactsBuilder.addTransitive(TopLevelArtifactHelper.getAllArtifactsToBuild(target, context).getImportantArtifacts());
    }
    for (AspectValue aspect : aspectsToPrint) {
        artifactsBuilder.addTransitive(TopLevelArtifactHelper.getAllArtifactsToBuild(aspect, context).getImportantArtifacts());
    }
    OutErr outErr = request.getOutErr();
    outErr.printErrLn("Build artifacts:");
    NestedSet<Artifact> artifacts = artifactsBuilder.build();
    for (Artifact artifact : artifacts) {
        if (!artifact.isSourceArtifact()) {
            outErr.printErrLn(">>>" + artifact.getPath());
        }
    }
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) OutErr(com.google.devtools.build.lib.util.io.OutErr) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) OutputFileConfiguredTarget(com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget) InputFileConfiguredTarget(com.google.devtools.build.lib.analysis.InputFileConfiguredTarget) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 7 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class ExecutionProgressReceiver method evaluated.

@Override
public void evaluated(SkyKey skyKey, Supplier<SkyValue> skyValueSupplier, EvaluationState state) {
    SkyFunctionName type = skyKey.functionName();
    if (type.equals(SkyFunctions.TARGET_COMPLETION)) {
        TargetCompletionValue value = (TargetCompletionValue) skyValueSupplier.get();
        if (value == null) {
            return;
        }
        ConfiguredTarget target = value.getConfiguredTarget();
        builtTargets.add(target);
        if (testedTargets.contains(target)) {
            postTestTargetComplete(target);
        } else {
            postBuildTargetComplete(target);
        }
    } else if (type.equals(SkyFunctions.ASPECT_COMPLETION)) {
        AspectCompletionValue value = (AspectCompletionValue) skyValueSupplier.get();
        if (value != null) {
            AspectValue aspectValue = value.getAspectValue();
            ArtifactsToBuild artifacts = TopLevelArtifactHelper.getAllArtifactsToBuild(aspectValue, topLevelArtifactContext);
            eventBus.post(AspectCompleteEvent.createSuccessful(aspectValue, artifacts));
        }
    } else if (type.equals(SkyFunctions.ACTION_EXECUTION)) {
        // Remember all completed actions, even those in error, regardless of having been cached or
        // really executed.
        actionCompleted((Action) skyKey.argument());
    }
}
Also used : SkyFunctionName(com.google.devtools.build.skyframe.SkyFunctionName) AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) AspectCompletionValue(com.google.devtools.build.lib.skyframe.AspectCompletionValue) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) TargetCompletionValue(com.google.devtools.build.lib.skyframe.TargetCompletionValue) ArtifactsToBuild(com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsToBuild)

Example 8 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class ExecutionTool method executeBuild.

/**
   * Performs the execution phase (phase 3) of the build, in which the Builder
   * is applied to the action graph to bring the targets up to date. (This
   * function will return prior to execution-proper if --nobuild was specified.)
   * @param buildId UUID of the build id
   * @param analysisResult the analysis phase output
   * @param buildResult the mutable build result
   * @param packageRoots package roots collected from loading phase and BuildConfigurationCollection
   * creation
   */
void executeBuild(UUID buildId, AnalysisResult analysisResult, BuildResult buildResult, BuildConfigurationCollection configurations, ImmutableMap<PackageIdentifier, Path> packageRoots, TopLevelArtifactContext topLevelArtifactContext) throws BuildFailedException, InterruptedException, TestExecException, AbruptExitException {
    Stopwatch timer = Stopwatch.createStarted();
    prepare(packageRoots, analysisResult.getWorkspaceName());
    ActionGraph actionGraph = analysisResult.getActionGraph();
    // Get top-level artifacts.
    ImmutableSet<Artifact> additionalArtifacts = analysisResult.getAdditionalArtifactsToBuild();
    OutputService outputService = env.getOutputService();
    ModifiedFileSet modifiedOutputFiles = ModifiedFileSet.EVERYTHING_MODIFIED;
    if (outputService != null) {
        modifiedOutputFiles = outputService.startBuild(buildId, request.getBuildOptions().finalizeActions);
    } else {
        // TODO(bazel-team): this could be just another OutputService
        startLocalOutputBuild(analysisResult.getWorkspaceName());
    }
    List<BuildConfiguration> targetConfigurations = configurations.getTargetConfigurations();
    BuildConfiguration targetConfiguration = targetConfigurations.size() == 1 ? targetConfigurations.get(0) : null;
    if (targetConfigurations.size() == 1) {
        String productName = runtime.getProductName();
        String dirName = env.getWorkspaceName();
        String workspaceName = analysisResult.getWorkspaceName();
        OutputDirectoryLinksUtils.createOutputDirectoryLinks(dirName, env.getWorkspace(), env.getDirectories().getExecRoot(workspaceName), env.getDirectories().getOutputPath(workspaceName), getReporter(), targetConfiguration, request.getBuildOptions().getSymlinkPrefix(productName), productName);
    }
    ActionCache actionCache = getActionCache();
    SkyframeExecutor skyframeExecutor = env.getSkyframeExecutor();
    Builder builder = createBuilder(request, actionCache, skyframeExecutor, modifiedOutputFiles);
    //
    // Execution proper.  All statements below are logically nested in
    // begin/end pairs.  No early returns or exceptions please!
    //
    Collection<ConfiguredTarget> configuredTargets = buildResult.getActualTargets();
    env.getEventBus().post(new ExecutionStartingEvent(configuredTargets));
    getReporter().handle(Event.progress("Building..."));
    // Conditionally record dependency-checker log:
    ExplanationHandler explanationHandler = installExplanationHandler(request.getBuildOptions().explanationPath, request.getOptionsDescription());
    Set<ConfiguredTarget> builtTargets = new HashSet<>();
    Collection<AspectValue> aspects = analysisResult.getAspects();
    Iterable<Artifact> allArtifactsForProviders = Iterables.concat(additionalArtifacts, TopLevelArtifactHelper.getAllArtifactsToBuild(analysisResult.getTargetsToBuild(), analysisResult.getTopLevelContext()).getAllArtifacts(), TopLevelArtifactHelper.getAllArtifactsToBuildFromAspects(aspects, analysisResult.getTopLevelContext()).getAllArtifacts(), //TODO(dslomov): Artifacts to test from aspects?
    TopLevelArtifactHelper.getAllArtifactsToTest(analysisResult.getTargetsToTest()));
    if (request.isRunningInEmacs()) {
        // The syntax of this message is tightly constrained by lisp/progmodes/compile.el in emacs
        request.getOutErr().printErrLn("blaze: Entering directory `" + getExecRoot() + "/'");
    }
    boolean buildCompleted = false;
    try {
        for (ActionContextProvider actionContextProvider : actionContextProviders) {
            actionContextProvider.executionPhaseStarting(actionGraph, allArtifactsForProviders);
        }
        executor.executionPhaseStarting();
        skyframeExecutor.drainChangedFiles();
        if (request.getViewOptions().discardAnalysisCache) {
            // Free memory by removing cache entries that aren't going to be needed. Note that in
            // skyframe full, this destroys the action graph as well, so we can only do it after the
            // action graph is no longer needed.
            env.getSkyframeBuildView().clearAnalysisCache(analysisResult.getTargetsToBuild());
        }
        configureResourceManager(request);
        Profiler.instance().markPhase(ProfilePhase.EXECUTE);
        builder.buildArtifacts(env.getReporter(), additionalArtifacts, analysisResult.getParallelTests(), analysisResult.getExclusiveTests(), analysisResult.getTargetsToBuild(), analysisResult.getAspects(), executor, builtTargets, request.getBuildOptions().explanationPath != null, env.getBlazeWorkspace().getLastExecutionTimeRange(), topLevelArtifactContext);
        buildCompleted = true;
    } catch (BuildFailedException | TestExecException e) {
        buildCompleted = true;
        throw e;
    } finally {
        env.recordLastExecutionTime();
        if (request.isRunningInEmacs()) {
            request.getOutErr().printErrLn("blaze: Leaving directory `" + getExecRoot() + "/'");
        }
        if (buildCompleted) {
            getReporter().handle(Event.progress("Building complete."));
        }
        env.getEventBus().post(new ExecutionFinishedEvent(ImmutableMap.<String, Long>of(), 0L, skyframeExecutor.getOutputDirtyFilesAndClear(), skyframeExecutor.getModifiedFilesDuringPreviousBuildAndClear()));
        executor.executionPhaseEnding();
        for (ActionContextProvider actionContextProvider : actionContextProviders) {
            actionContextProvider.executionPhaseEnding();
        }
        Profiler.instance().markPhase(ProfilePhase.FINISH);
        if (buildCompleted) {
            saveCaches(actionCache);
        }
        try (AutoProfiler p = AutoProfiler.profiled("Show results", ProfilerTask.INFO)) {
            buildResult.setSuccessfulTargets(determineSuccessfulTargets(configuredTargets, builtTargets, timer));
            BuildResultPrinter buildResultPrinter = new BuildResultPrinter(env);
            buildResultPrinter.showBuildResult(request, buildResult, configuredTargets, analysisResult.getAspects());
        }
        try (AutoProfiler p = AutoProfiler.profiled("Show artifacts", ProfilerTask.INFO)) {
            if (request.getBuildOptions().showArtifacts) {
                BuildResultPrinter buildResultPrinter = new BuildResultPrinter(env);
                buildResultPrinter.showArtifacts(request, configuredTargets, analysisResult.getAspects());
            }
        }
        if (explanationHandler != null) {
            uninstallExplanationHandler(explanationHandler);
        }
        // code has already run.
        if (env.getOutputService() != null) {
            boolean isBuildSuccessful = buildResult.getSuccessfulTargets().size() == configuredTargets.size();
            env.getOutputService().finalizeBuild(isBuildSuccessful);
        }
    }
}
Also used : Builder(com.google.devtools.build.lib.skyframe.Builder) ExecutorBuilder(com.google.devtools.build.lib.exec.ExecutorBuilder) Stopwatch(com.google.common.base.Stopwatch) SkyframeExecutor(com.google.devtools.build.lib.skyframe.SkyframeExecutor) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) ActionContextProvider(com.google.devtools.build.lib.exec.ActionContextProvider) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) ActionGraph(com.google.devtools.build.lib.actions.ActionGraph) AutoProfiler(com.google.devtools.build.lib.profiler.AutoProfiler) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) ExecutionStartingEvent(com.google.devtools.build.lib.buildtool.buildevent.ExecutionStartingEvent) ActionCache(com.google.devtools.build.lib.actions.cache.ActionCache) ModifiedFileSet(com.google.devtools.build.lib.vfs.ModifiedFileSet) OutputService(com.google.devtools.build.lib.exec.OutputService) TestExecException(com.google.devtools.build.lib.actions.TestExecException)

Example 9 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectWithOutputGroupsAsList.

@Test
public void aspectWithOutputGroupsAsList() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   g = target.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", "   return struct(output_groups = { 'my_result' : [ f for f in g] })", "", "MyAspect = aspect(", "   implementation=_impl,", ")");
    scratch.file("test/BUILD", "java_library(", "     name = 'xxx',", "     srcs = ['A.java'],", ")");
    AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
    assertThat(transform(analysisResult.getTargetsToBuild(), new Function<ConfiguredTarget, String>() {

        @Nullable
        @Override
        public String apply(ConfiguredTarget configuredTarget) {
            return configuredTarget.getLabel().toString();
        }
    })).containsExactly("//test:xxx");
    AspectValue aspectValue = analysisResult.getAspects().iterator().next();
    OutputGroupProvider outputGroupProvider = aspectValue.getConfiguredAspect().getProvider(OutputGroupProvider.class);
    assertThat(outputGroupProvider).isNotNull();
    NestedSet<Artifact> names = outputGroupProvider.getOutputGroup("my_result");
    assertThat(names).isNotEmpty();
    NestedSet<Artifact> expectedSet = getConfiguredTarget("//test:xxx").getProvider(OutputGroupProvider.class).getOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL);
    assertThat(names).containsExactlyElementsIn(expectedSet);
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Nullable(javax.annotation.Nullable) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 10 with AspectValue

use of com.google.devtools.build.lib.skyframe.AspectValue in project bazel by bazelbuild.

the class SkylarkAspectsTest method aspectPropagating.

@Test
public void aspectPropagating() throws Exception {
    scratch.file("test/aspect.bzl", "def _impl(target, ctx):", "   s = depset([target.label])", "   c = depset([ctx.rule.kind])", "   for i in ctx.rule.attr.deps:", "       s += i.target_labels", "       c += i.rule_kinds", "   return struct(target_labels = s, rule_kinds = c)", "", "MyAspect = aspect(", "   implementation=_impl,", "   attr_aspects=['deps'],", ")");
    scratch.file("test/BUILD", "java_library(", "     name = 'yyy',", ")", "java_library(", "     name = 'xxx',", "     srcs = ['A.java'],", "     deps = [':yyy'],", ")");
    AnalysisResult analysisResult = update(ImmutableList.of("test/aspect.bzl%MyAspect"), "//test:xxx");
    assertThat(getLabelsToBuild(analysisResult)).containsExactly("//test:xxx");
    AspectValue aspectValue = analysisResult.getAspects().iterator().next();
    SkylarkProviders skylarkProviders = aspectValue.getConfiguredAspect().getProvider(SkylarkProviders.class);
    assertThat(skylarkProviders).isNotNull();
    Object names = skylarkProviders.getValue("target_labels");
    assertThat(names).isInstanceOf(SkylarkNestedSet.class);
    assertThat(transform(((SkylarkNestedSet) names).toCollection(), new Function<Object, String>() {

        @Nullable
        @Override
        public String apply(Object o) {
            assertThat(o).isInstanceOf(Label.class);
            return o.toString();
        }
    })).containsExactly("//test:xxx", "//test:yyy");
    Object ruleKinds = skylarkProviders.getValue("rule_kinds");
    assertThat(ruleKinds).isInstanceOf(SkylarkNestedSet.class);
    assertThat(((SkylarkNestedSet) ruleKinds).toCollection()).containsExactly("java_library");
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) Label(com.google.devtools.build.lib.cmdline.Label) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Nullable(javax.annotation.Nullable) SkylarkNestedSet(com.google.devtools.build.lib.syntax.SkylarkNestedSet) Test(org.junit.Test)

Aggregations

AspectValue (com.google.devtools.build.lib.skyframe.AspectValue)13 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)7 Artifact (com.google.devtools.build.lib.actions.Artifact)6 Test (org.junit.Test)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 Label (com.google.devtools.build.lib.cmdline.Label)4 Nullable (javax.annotation.Nullable)4 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)3 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)3 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)2 InputFileConfiguredTarget (com.google.devtools.build.lib.analysis.InputFileConfiguredTarget)2 OutputFileConfiguredTarget (com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget)2 TopLevelArtifactContext (com.google.devtools.build.lib.analysis.TopLevelArtifactContext)2 OutErr (com.google.devtools.build.lib.util.io.OutErr)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Stopwatch (com.google.common.base.Stopwatch)1 EventBus (com.google.common.eventbus.EventBus)1 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)1 ArtifactOwner (com.google.devtools.build.lib.actions.ArtifactOwner)1