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();
}
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;
}
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();
}
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;
}
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;
}
Aggregations