Search in sources :

Example 21 with Artifact

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

the class DataBinding method processDeps.

/**
   * Processes deps that also apply data binding.
   *
   * @param ruleContext the current rule
   * @param attributes java compilation attributes. The directories of the deps' metadata outputs
   *     (see {@link #getMetadataOutputs}) are added to this rule's annotation processor classpath.
   * @return the deps' metadata outputs. These need to be staged as compilation inputs to the
   *     current rule.
   */
static ImmutableList<Artifact> processDeps(RuleContext ruleContext, JavaTargetAttributes.Builder attributes) {
    ImmutableList.Builder<Artifact> dataBindingJavaInputs = ImmutableList.<Artifact>builder();
    if (LocalResourceContainer.definesAndroidResources(ruleContext.attributes())) {
        dataBindingJavaInputs.add(DataBinding.getLayoutInfoFile(ruleContext));
    }
    for (Artifact dataBindingDepMetadata : getTransitiveMetadata(ruleContext, "deps")) {
        attributes.addProcessorPathDir(dataBindingDepMetadata.getExecPath().getParentDirectory());
        dataBindingJavaInputs.add(dataBindingDepMetadata);
    }
    return dataBindingJavaInputs.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 22 with Artifact

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

the class DexArchiveAspect method createDesugarAction.

private static Artifact createDesugarAction(RuleContext ruleContext, String desugarPrereqName, Artifact jar, ImmutableList<Artifact> bootclasspath, NestedSet<Artifact> classpath, Artifact result) {
    CustomCommandLine args = new CustomCommandLine.Builder().addExecPath("--input", jar).addExecPath("--output", result).addBeforeEachExecPath("--classpath_entry", classpath).addBeforeEachExecPath("--bootclasspath_entry", bootclasspath).build();
    // Just use params file, since classpaths can get long
    Artifact paramFile = ruleContext.getDerivedArtifact(ParameterFile.derivePath(result.getRootRelativePath()), result.getRoot());
    ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile, args, ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));
    ruleContext.registerAction(new SpawnAction.Builder().setExecutable(ruleContext.getExecutablePrerequisite(desugarPrereqName, Mode.HOST)).addArgument("@" + paramFile.getExecPathString()).addInput(jar).addInput(paramFile).addInputs(bootclasspath).addTransitiveInputs(classpath).addOutput(result).setMnemonic("Desugar").setProgressMessage("Desugaring " + jar.prettyPrint() + " for Android").build(ruleContext));
    return result;
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) ParameterFileWriteAction(com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 23 with Artifact

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

the class DexArchiveAspect method create.

@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters params) throws InterruptedException {
    ConfiguredAspect.Builder result = new ConfiguredAspect.Builder(this, params, ruleContext);
    Function<Artifact, Artifact> desugaredJars = desugarJarsIfRequested(base, ruleContext, result);
    TriState incrementalAttr = TriState.valueOf(params.getOnlyValueOfAttribute("incremental_dexing"));
    if (incrementalAttr == TriState.NO || (getAndroidConfig(ruleContext).getIncrementalDexingBinaries().isEmpty() && incrementalAttr != TriState.YES)) {
        // Dex archives will never be used, so don't bother setting them up.
        return result.build();
    }
    if (JavaCommon.isNeverLink(ruleContext)) {
        return result.addProvider(DexArchiveProvider.NEVERLINK).build();
    }
    DexArchiveProvider.Builder dexArchives = new DexArchiveProvider.Builder().addTransitiveProviders(collectPrerequisites(ruleContext, DexArchiveProvider.class));
    Iterable<Artifact> runtimeJars = getProducedRuntimeJars(base, ruleContext);
    if (runtimeJars != null) {
        boolean basenameClash = checkBasenameClash(runtimeJars);
        Set<Set<String>> aspectDexopts = aspectDexopts(ruleContext);
        for (Artifact jar : runtimeJars) {
            for (Set<String> incrementalDexopts : aspectDexopts) {
                // Since we're potentially dexing the same jar multiple times with different flags, we
                // need to write unique artifacts for each flag combination. Here, it is convenient to
                // distinguish them by putting the flags that were used for creating the artifacts into
                // their filenames.
                String uniqueFilename = (basenameClash ? jar.getRootRelativePathString() : jar.getFilename()) + Joiner.on("").join(incrementalDexopts) + ".dex.zip";
                Artifact dexArchive = createDexArchiveAction(ruleContext, ASPECT_DEXBUILDER_PREREQ, desugaredJars.apply(jar), incrementalDexopts, AndroidBinary.getDxArtifact(ruleContext, uniqueFilename));
                dexArchives.addDexArchive(incrementalDexopts, dexArchive, jar);
            }
        }
    }
    return result.addProvider(dexArchives.build()).build();
}
Also used : ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) NestedSet(com.google.devtools.build.lib.collect.nestedset.NestedSet) Artifact(com.google.devtools.build.lib.actions.Artifact) TriState(com.google.devtools.build.lib.packages.TriState)

Example 24 with Artifact

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

the class JackCompilationHelper method extractResourcesFromJar.

/**
   * Generates an action which creates a zip file from the contents of the input jar, filtering out
   * non-resource files and returning a zip file containing only resources.
   */
private Artifact extractResourcesFromJar(Artifact jar) {
    Artifact result = ruleContext.getUniqueDirectoryArtifact(PARTIAL_JACK_DIRECTORY, FileSystemUtils.replaceExtension(jar.getRootRelativePath(), "-resources.zip"), ruleContext.getBinOrGenfilesDirectory());
    ruleContext.registerAction(new SpawnAction.Builder().setExecutable(resourceExtractorBinary).addInputArgument(jar).addOutputArgument(result).setProgressMessage("Extracting resources from " + jar.getExecPath().getBaseName()).setMnemonic("AndroidJillResources").build(ruleContext));
    return result;
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 25 with Artifact

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

the class JackCompilationHelper method postprocessPartialJackAndAddResources.

/**
   * Generates an action to finish processing a partial Jack library generated by
   * {@link #convertJarToPartialJack(Artifact)} and add resources from
   * {@link #extractResourcesFromJar(Artifact)}, then returns the final library.
   */
private Artifact postprocessPartialJackAndAddResources(Artifact partialJackLibrary, Artifact resources) {
    Artifact result = ruleContext.getUniqueDirectoryArtifact(JACK_DIRECTORY, partialJackLibrary.getRootRelativePath().relativeTo(ruleContext.getUniqueDirectory(PARTIAL_JACK_DIRECTORY)), ruleContext.getBinOrGenfilesDirectory());
    CustomCommandLine.Builder builder = CustomCommandLine.builder().add(SANITY_CHECKS).add(useSanityChecks ? SANITY_CHECKS_ON : SANITY_CHECKS_OFF).addExecPath(IMPORT_JACK_LIBRARY, partialJackLibrary).addExecPath(IMPORT_RESOURCE_ZIP, resources).addExecPath(OUTPUT_JACK, result);
    ruleContext.registerAction(new SpawnAction.Builder().setExecutable(jackBinary).addInput(partialJackLibrary).addInput(resources).addOutput(result).setCommandLine(builder.build()).setProgressMessage("Processing " + partialJackLibrary.getExecPath().getBaseName() + " as Jack library").setMnemonic("AndroidJillPostprocess").build(ruleContext));
    return result;
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) 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