Search in sources :

Example 6 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class BuildResultPrinter method showBuildResult.

/**
   * Shows the result of the build. Information includes the list of up-to-date
   * and failed targets and list of output artifacts for successful targets
   *
   * <p>This corresponds to the --show_result flag.
   */
public void showBuildResult(BuildRequest request, BuildResult result, Collection<ConfiguredTarget> configuredTargets, Collection<AspectValue> aspects) {
    // NOTE: be careful what you print!  We don't want to create a consistency
    // problem where the summary message and the exit code disagree.  The logic
    // here is already complex.
    Collection<ConfiguredTarget> targetsToPrint = filterTargetsToPrint(configuredTargets);
    Collection<AspectValue> aspectsToPrint = filterAspectsToPrint(aspects);
    // Filter the targets we care about into two buckets:
    Collection<ConfiguredTarget> succeeded = new ArrayList<>();
    Collection<ConfiguredTarget> failed = new ArrayList<>();
    for (ConfiguredTarget target : targetsToPrint) {
        Collection<ConfiguredTarget> successfulTargets = result.getSuccessfulTargets();
        (successfulTargets.contains(target) ? succeeded : failed).add(target);
    }
    // Suppress summary if --show_result value is exceeded:
    if (succeeded.size() + failed.size() + aspectsToPrint.size() > request.getBuildOptions().maxResultTargets) {
        return;
    }
    OutErr outErr = request.getOutErr();
    TopLevelArtifactContext context = request.getTopLevelArtifactContext();
    for (ConfiguredTarget target : succeeded) {
        Label label = target.getLabel();
        // For up-to-date targets report generated artifacts, but only
        // if they have associated action and not middleman artifacts.
        boolean headerFlag = true;
        for (Artifact artifact : TopLevelArtifactHelper.getAllArtifactsToBuild(target, context).getImportantArtifacts()) {
            if (shouldPrint(artifact)) {
                if (headerFlag) {
                    outErr.printErr("Target " + label + " up-to-date:\n");
                    headerFlag = false;
                }
                outErr.printErrLn(formatArtifactForShowResults(artifact, request));
            }
        }
        if (headerFlag) {
            outErr.printErr("Target " + label + " up-to-date (nothing to build)\n");
        }
    }
    for (AspectValue aspect : aspectsToPrint) {
        Label label = aspect.getLabel();
        String aspectName = aspect.getConfiguredAspect().getName();
        boolean headerFlag = true;
        NestedSet<Artifact> importantArtifacts = TopLevelArtifactHelper.getAllArtifactsToBuild(aspect, context).getImportantArtifacts();
        for (Artifact importantArtifact : importantArtifacts) {
            if (headerFlag) {
                outErr.printErr("Aspect " + aspectName + " of " + label + " up-to-date:\n");
                headerFlag = false;
            }
            if (shouldPrint(importantArtifact)) {
                outErr.printErrLn(formatArtifactForShowResults(importantArtifact, request));
            }
        }
        if (headerFlag) {
            outErr.printErr("Aspect " + aspectName + " of " + label + " up-to-date (nothing to build)\n");
        }
    }
    for (ConfiguredTarget target : failed) {
        outErr.printErr("Target " + target.getLabel() + " failed to build\n");
        // For failed compilation, it is still useful to examine temp artifacts,
        // (ie, preprocessed and assembler files).
        OutputGroupProvider topLevelProvider = target.getProvider(OutputGroupProvider.class);
        String productName = env.getRuntime().getProductName();
        if (topLevelProvider != null) {
            for (Artifact temp : topLevelProvider.getOutputGroup(OutputGroupProvider.TEMP_FILES)) {
                if (temp.getPath().exists()) {
                    outErr.printErrLn("  See temp at " + OutputDirectoryLinksUtils.getPrettyPath(temp.getPath(), env.getWorkspaceName(), env.getWorkspace(), request.getBuildOptions().getSymlinkPrefix(productName), productName));
                }
            }
        }
    }
    if (!failed.isEmpty() && !request.getOptions(ExecutionOptions.class).verboseFailures) {
        outErr.printErr("Use --verbose_failures to see the command lines of failed build steps.\n");
    }
}
Also used : AspectValue(com.google.devtools.build.lib.skyframe.AspectValue) OutErr(com.google.devtools.build.lib.util.io.OutErr) OutputGroupProvider(com.google.devtools.build.lib.analysis.OutputGroupProvider) ArrayList(java.util.ArrayList) Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) OutputFileConfiguredTarget(com.google.devtools.build.lib.analysis.OutputFileConfiguredTarget) InputFileConfiguredTarget(com.google.devtools.build.lib.analysis.InputFileConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) ExecutionOptions(com.google.devtools.build.lib.exec.ExecutionOptions) TopLevelArtifactContext(com.google.devtools.build.lib.analysis.TopLevelArtifactContext)

Example 7 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class TestStrategy method getArgs.

/**
   * Generates a command line to run for the test action, taking into account coverage and {@code
   * --run_under} settings.
   *
   * @param coverageScript a script interjected between setup script and rest of command line to
   *     collect coverage data. If this is an empty string, it is ignored.
   * @param testAction The test action.
   * @return the command line as string list.
   * @throws ExecException 
   */
protected ImmutableList<String> getArgs(String coverageScript, TestRunnerAction testAction) throws ExecException {
    List<String> args = Lists.newArrayList();
    // testAction.getConfiguration().getTargetOS() == OS.WINDOWS
    if (OS.getCurrent() == OS.WINDOWS) {
        args.add(testAction.getShExecutable().getPathString());
        args.add("-c");
        args.add("$0 $*");
    }
    Artifact testSetup = testAction.getRuntimeArtifact(TEST_SETUP_BASENAME);
    args.add(testSetup.getExecPath().getCallablePathString());
    if (testAction.isCoverageMode()) {
        args.add(coverageScript);
    }
    TestTargetExecutionSettings execSettings = testAction.getExecutionSettings();
    // Insert the command prefix specified by the "--run_under=<command-prefix>" option, if any.
    if (execSettings.getRunUnder() != null) {
        addRunUnderArgs(testAction, args);
    }
    // Execute the test using the alias in the runfiles tree, as mandated by the Test Encyclopedia.
    args.add(execSettings.getExecutable().getRootRelativePath().getCallablePathString());
    args.addAll(execSettings.getArgs());
    return ImmutableList.copyOf(args);
}
Also used : TestTargetExecutionSettings(com.google.devtools.build.lib.rules.test.TestTargetExecutionSettings) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 8 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class AndroidStudioInfoAspect method makeAndroidIdeInfo.

private static AndroidIdeInfo makeAndroidIdeInfo(AndroidIdeInfoProvider androidIdeInfoProvider, DependenciesResult dependenciesResult, NestedSetBuilder<Artifact> ideResolveArtifacts) {
    AndroidIdeInfo.Builder builder = AndroidIdeInfo.newBuilder();
    if (androidIdeInfoProvider.getSignedApk() != null) {
        builder.setApk(makeArtifactLocation(androidIdeInfoProvider.getSignedApk()));
    }
    Artifact manifest = androidIdeInfoProvider.getManifest();
    if (manifest != null) {
        builder.setManifest(makeArtifactLocation(manifest));
        addResolveArtifact(ideResolveArtifacts, manifest);
    }
    for (Artifact artifact : androidIdeInfoProvider.getApksUnderTest()) {
        builder.addDependencyApk(makeArtifactLocation(artifact));
    }
    for (SourceDirectory resourceDir : androidIdeInfoProvider.getResourceDirs()) {
        ArtifactLocation artifactLocation = makeArtifactLocation(resourceDir);
        builder.addResources(artifactLocation);
    }
    if (androidIdeInfoProvider.getJavaPackage() != null) {
        builder.setJavaPackage(androidIdeInfoProvider.getJavaPackage());
    }
    String idlImportRoot = androidIdeInfoProvider.getIdlImportRoot();
    if (idlImportRoot != null) {
        builder.setIdlImportRoot(idlImportRoot);
    }
    boolean hasIdlSources = !androidIdeInfoProvider.getIdlSrcs().isEmpty();
    builder.setHasIdlSources(hasIdlSources);
    if (hasIdlSources) {
        LibraryArtifact idlLibraryArtifact = makeLibraryArtifact(ideResolveArtifacts, androidIdeInfoProvider.getIdlClassJar(), null, androidIdeInfoProvider.getIdlSourceJar());
        if (idlLibraryArtifact != null) {
            builder.setIdlJar(idlLibraryArtifact);
        }
    }
    builder.setGenerateResourceClass(androidIdeInfoProvider.definesAndroidResources());
    if (dependenciesResult.resources != null) {
        builder.setLegacyResources(dependenciesResult.resources.toString());
    }
    OutputJar resourceJar = androidIdeInfoProvider.getResourceJar();
    if (resourceJar != null) {
        LibraryArtifact resourceLibraryArtifact = makeLibraryArtifact(ideResolveArtifacts, resourceJar.getClassJar(), resourceJar.getIJar(), resourceJar.getSrcJar());
        if (resourceLibraryArtifact != null) {
            builder.setResourceJar(resourceLibraryArtifact);
        }
    }
    return builder.build();
}
Also used : OutputJar(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar) ArtifactLocation(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.ArtifactLocation) SourceDirectory(com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider.SourceDirectory) AndroidIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.AndroidIdeInfo) LibraryArtifact(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) LibraryArtifact(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact)

Example 9 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class AndroidStudioInfoAspect method makeJavaIdeInfo.

private JavaIdeInfo makeJavaIdeInfo(ConfiguredTarget base, RuleContext ruleContext, JavaRuleOutputJarsProvider outputJarsProvider, AndroidStudioInfoFilesProvider.Builder providerBuilder) {
    NestedSetBuilder<Artifact> ideResolveArtifacts = providerBuilder.ideResolveFilesBuilder();
    JavaIdeInfo.Builder builder = JavaIdeInfo.newBuilder();
    List<Artifact> javaSources = Lists.newArrayList();
    List<Artifact> generatedJavaSources = Lists.newArrayList();
    List<Artifact> srcjars = Lists.newArrayList();
    divideJavaSources(ruleContext, javaSources, generatedJavaSources, srcjars);
    if (!javaSources.isEmpty()) {
        Artifact packageManifest = derivedArtifact(base, ruleContext, ".manifest");
        providerBuilder.ideInfoFilesBuilder().add(packageManifest);
        ruleContext.registerAction(makePackageManifestAction(ruleContext, packageManifest, javaSources));
        builder.setPackageManifest(makeArtifactLocation(packageManifest));
    }
    // This can be removed once android_resources is deleted
    if (ruleContext.attributes().has("resources", BuildType.LABEL) && ruleContext.getRule().getRuleClass().startsWith("android_")) {
        srcjars = ImmutableList.of();
    }
    if (!javaSources.isEmpty() && (!generatedJavaSources.isEmpty() || !srcjars.isEmpty())) {
        Artifact filteredGenJar = derivedArtifact(base, ruleContext, "-filtered-gen.jar");
        Artifact filteredGenSrcJar = derivedArtifact(base, ruleContext, "-filtered-gen-src.jar");
        List<Artifact> jars = Lists.newArrayList();
        List<Artifact> sourceJars = Lists.newArrayList();
        for (OutputJar outputJar : outputJarsProvider.getOutputJars()) {
            Artifact jar = outputJar.getIJar();
            if (jar == null) {
                jar = outputJar.getClassJar();
            }
            if (jar != null) {
                jars.add(jar);
            }
            if (outputJar.getSrcJar() != null) {
                sourceJars.add(outputJar.getSrcJar());
            }
        }
        ruleContext.registerAction(makeFilteredJarAction(ruleContext, jars, sourceJars, generatedJavaSources, srcjars, filteredGenJar, filteredGenSrcJar));
        ideResolveArtifacts.add(filteredGenJar);
        ideResolveArtifacts.add(filteredGenSrcJar);
        builder.setFilteredGenJar(makeLibraryArtifact(ideResolveArtifacts, filteredGenJar, null, filteredGenSrcJar));
    }
    collectJarsFromOutputJarsProvider(builder, ideResolveArtifacts, outputJarsProvider);
    Artifact jdeps = outputJarsProvider.getJdeps();
    if (jdeps != null) {
        builder.setJdeps(makeArtifactLocation(jdeps));
    }
    JavaGenJarsProvider genJarsProvider = base.getProvider(JavaGenJarsProvider.class);
    if (genJarsProvider != null) {
        collectGenJars(builder, ideResolveArtifacts, genJarsProvider);
    }
    Collection<Artifact> sourceFiles = getSources(ruleContext);
    for (Artifact sourceFile : sourceFiles) {
        builder.addSources(makeArtifactLocation(sourceFile));
    }
    return builder.build();
}
Also used : OutputJar(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar) JavaGenJarsProvider(com.google.devtools.build.lib.rules.java.JavaGenJarsProvider) JavaIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo) Artifact(com.google.devtools.build.lib.actions.Artifact) LibraryArtifact(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact)

Example 10 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class SpawnInputExpander method getInputMapping.

/**
   * Convert the inputs of the given spawn to a map from exec-root relative paths to action inputs.
   * In some cases, this generates empty files, for which it uses {@link #EMPTY_FILE}.
   */
public SortedMap<PathFragment, ActionInput> getInputMapping(Spawn spawn, ArtifactExpander artifactExpander, ActionInputFileCache actionInputFileCache, FilesetActionContext filesetContext) throws IOException {
    TreeMap<PathFragment, ActionInput> inputMap = new TreeMap<>();
    addInputs(inputMap, spawn, artifactExpander);
    addRunfilesToInputs(inputMap, spawn.getRunfilesSupplier(), actionInputFileCache);
    for (Artifact manifest : spawn.getFilesetManifests()) {
        parseFilesetManifest(inputMap, manifest, filesetContext.getWorkspaceName());
    }
    return inputMap;
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) TreeMap(java.util.TreeMap) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)659 Test (org.junit.Test)242 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)184 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)83 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)65 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)64 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)51 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)50 ImmutableList (com.google.common.collect.ImmutableList)46 Action (com.google.devtools.build.lib.actions.Action)42 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)38 Path (com.google.devtools.build.lib.vfs.Path)37 HashMap (java.util.HashMap)37 Map (java.util.Map)36 Root (com.google.devtools.build.lib.actions.Root)31 LinkedHashMap (java.util.LinkedHashMap)31 ImmutableMap (com.google.common.collect.ImmutableMap)28 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)28