use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class PreDexMerge method addMetadataWriteStep.
private void addMetadataWriteStep(final PreDexedFilesSorter.Result result, final ImmutableList.Builder<Step> steps, final Path metadataFilePath) {
StringBuilder nameBuilder = new StringBuilder(30);
final boolean isRootModule = result.apkModule.equals(apkModuleGraph.getRootAPKModule());
final String storeId = result.apkModule.getName();
nameBuilder.append("write_");
if (!isRootModule) {
nameBuilder.append(storeId);
nameBuilder.append("_");
}
nameBuilder.append("metadata_txt");
steps.add(new AbstractExecutionStep(nameBuilder.toString()) {
@Override
public StepExecutionResult execute(ExecutionContext executionContext) {
Map<Path, DexWithClasses> metadataTxtEntries = result.metadataTxtDexEntries;
List<String> lines = Lists.newArrayListWithCapacity(metadataTxtEntries.size());
lines.add(".id " + storeId);
if (isRootModule) {
if (dexSplitMode.getDexStore() == DexStore.RAW) {
lines.add(".root_relative");
}
} else {
for (APKModule dependency : apkModuleGraph.getGraph().getOutgoingNodesFor(result.apkModule)) {
lines.add(".requires " + dependency.getName());
}
}
try {
for (Map.Entry<Path, DexWithClasses> entry : metadataTxtEntries.entrySet()) {
Path pathToSecondaryDex = entry.getKey();
String containedClass = Iterables.get(entry.getValue().getClassNames(), 0);
containedClass = containedClass.replace('/', '.');
Sha1HashCode hash = getProjectFilesystem().computeSha1(pathToSecondaryDex);
lines.add(String.format("%s %s %s", pathToSecondaryDex.getFileName(), hash, containedClass));
}
getProjectFilesystem().writeLinesToPath(lines, metadataFilePath);
} catch (IOException e) {
executionContext.logError(e, "Failed when writing metadata.txt multi-dex.");
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
}
use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class UnzipAar method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), unpackDirectory));
steps.add(new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(aarFile), unpackDirectory));
steps.add(new TouchStep(getProjectFilesystem(), getProguardConfig()));
steps.add(new MkdirStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(getAssetsDirectory())));
steps.add(new MkdirStep(getProjectFilesystem(), getNativeLibsDirectory()));
steps.add(new TouchStep(getProjectFilesystem(), getTextSymbolsFile()));
// We take the classes.jar file that is required to exist in an .aar and merge it with any
// .jar files under libs/ into an "uber" jar. We do this for simplicity because we do not know
// how many entries there are in libs/ at graph enhancement time, but we need to make sure
// that all of the .class files in the .aar get packaged. As it is implemented today, an
// android_library that depends on an android_prebuilt_aar can compile against anything in the
// .aar's classes.jar or libs/.
steps.add(new MkdirStep(getProjectFilesystem(), uberClassesJar.getParent()));
steps.add(new AbstractExecutionStep("create_uber_classes_jar") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
Path libsDirectory = unpackDirectory.resolve("libs");
boolean dirDoesNotExistOrIsEmpty;
if (!getProjectFilesystem().exists(libsDirectory)) {
dirDoesNotExistOrIsEmpty = true;
} else {
try {
dirDoesNotExistOrIsEmpty = getProjectFilesystem().getDirectoryContents(libsDirectory).isEmpty();
} catch (IOException e) {
context.logError(e, "Failed to get directory contents of %s", libsDirectory);
return StepExecutionResult.ERROR;
}
}
Path classesJar = unpackDirectory.resolve("classes.jar");
JavacEventSinkToBuckEventBusBridge eventSink = new JavacEventSinkToBuckEventBusBridge(context.getBuckEventBus());
if (!getProjectFilesystem().exists(classesJar)) {
try {
JarDirectoryStepHelper.createEmptyJarFile(getProjectFilesystem(), classesJar, eventSink, context.getStdErr());
} catch (IOException e) {
context.logError(e, "Failed to create empty jar %s", classesJar);
return StepExecutionResult.ERROR;
}
}
if (dirDoesNotExistOrIsEmpty) {
try {
getProjectFilesystem().copy(classesJar, uberClassesJar, ProjectFilesystem.CopySourceMode.FILE);
} catch (IOException e) {
context.logError(e, "Failed to copy from %s to %s", classesJar, uberClassesJar);
return StepExecutionResult.ERROR;
}
} else {
// Glob all of the contents from classes.jar and the entries in libs/ into a single JAR.
ImmutableSortedSet.Builder<Path> entriesToJarBuilder = ImmutableSortedSet.naturalOrder();
entriesToJarBuilder.add(classesJar);
try {
entriesToJarBuilder.addAll(getProjectFilesystem().getDirectoryContents(libsDirectory));
} catch (IOException e) {
context.logError(e, "Failed to get directory contents of %s", libsDirectory);
return StepExecutionResult.ERROR;
}
ImmutableSortedSet<Path> entriesToJar = entriesToJarBuilder.build();
try {
JarDirectoryStepHelper.createJarFile(getProjectFilesystem(), uberClassesJar, entriesToJar, /* mainClass */
Optional.empty(), /* manifestFile */
Optional.empty(), /* mergeManifests */
true, /* blacklist */
ImmutableSet.of(), eventSink, context.getStdErr());
} catch (IOException e) {
context.logError(e, "Failed to jar %s into %s", entriesToJar, uberClassesJar);
return StepExecutionResult.ERROR;
}
}
return StepExecutionResult.SUCCESS;
}
});
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTextSymbolsDir));
steps.add(new ExtractFromAndroidManifestStep(getAndroidManifest(), getProjectFilesystem(), buildableContext, METADATA_KEY_FOR_R_DOT_JAVA_PACKAGE, pathToRDotJavaPackageFile));
steps.add(CopyStep.forFile(getProjectFilesystem(), getTextSymbolsFile(), pathToTextSymbolsFile));
buildableContext.recordArtifact(unpackDirectory);
buildableContext.recordArtifact(uberClassesJar);
buildableContext.recordArtifact(pathToTextSymbolsFile);
buildableContext.recordArtifact(pathToRDotJavaPackageFile);
return steps.build();
}
use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class AbstractExecutionStepTest method testDescriptionGetters.
@Test
public void testDescriptionGetters() {
String description = "How I describe myself.";
Step step = new AbstractExecutionStep(description) {
@Override
public StepExecutionResult execute(ExecutionContext context) {
return StepExecutionResult.SUCCESS;
}
};
ExecutionContext context = TestExecutionContext.newInstance();
assertEquals(description, step.getShortName());
assertEquals(description, step.getDescription(context));
}
use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class NdkLibrary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// .so files are written to the libs/ subdirectory of the output directory.
// All of them should be recorded via the BuildableContext.
Path binDirectory = buildArtifactsDirectory.resolve("libs");
steps.add(new RmStep(getProjectFilesystem(), makefile));
steps.add(new MkdirStep(getProjectFilesystem(), makefile.getParent()));
steps.add(new WriteFileStep(getProjectFilesystem(), makefileContents, makefile, false));
steps.add(new NdkBuildStep(getProjectFilesystem(), root, makefile, buildArtifactsDirectory, binDirectory, flags, macroExpander));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), genDirectory));
steps.add(CopyStep.forDirectory(getProjectFilesystem(), binDirectory, genDirectory, CopyStep.DirectoryMode.CONTENTS_ONLY));
buildableContext.recordArtifact(genDirectory);
// Some tools need to inspect .so files whose symbols haven't been stripped, so cache these too.
// However, the intermediate object files are huge and we have no interest in them, so filter
// them out.
steps.add(new AbstractExecutionStep("cache_unstripped_so") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
try {
Set<Path> unstrippedSharedObjs = getProjectFilesystem().getFilesUnderPath(buildArtifactsDirectory, input -> input.toString().endsWith(".so"));
for (Path path : unstrippedSharedObjs) {
buildableContext.recordArtifact(path);
}
} catch (IOException e) {
context.logError(e, "Failed to cache intermediate artifacts of %s.", getBuildTarget());
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
return steps.build();
}
use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class JavaSymbolsRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
Step mkdirStep = new MkdirStep(getProjectFilesystem(), outputPath.getParent());
Step extractSymbolsStep = new AbstractExecutionStep("java-symbols") {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException {
Symbols symbols = symbolsFinder.extractSymbols();
Symbols symbolsToSerialize;
if (generatedSymbols.isEmpty()) {
symbolsToSerialize = symbols;
} else {
symbolsToSerialize = new Symbols(Iterables.concat(symbols.provided, generatedSymbols), symbols.required, symbols.exported);
}
try (OutputStream output = getProjectFilesystem().newFileOutputStream(outputPath)) {
context.getObjectMapper().writeValue(output, symbolsToSerialize);
}
return StepExecutionResult.SUCCESS;
}
};
return ImmutableList.of(mkdirStep, extractSymbolsStep);
}
Aggregations