use of com.facebook.buck.step.Step in project buck by facebook.
the class AppleAssetCatalog method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder();
stepsBuilder.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDir));
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), outputPlist.getParent()));
ImmutableSortedSet<Path> absoluteAssetCatalogDirs = context.getSourcePathResolver().getAllAbsolutePaths(assetCatalogDirs);
stepsBuilder.add(new ActoolStep(getProjectFilesystem().getRootPath(), applePlatformName, actool.getEnvironment(context.getSourcePathResolver()), actool.getCommandPrefix(context.getSourcePathResolver()), absoluteAssetCatalogDirs, getProjectFilesystem().resolve(outputDir), getProjectFilesystem().resolve(outputPlist), appIcon, launchImage, optimization));
buildableContext.recordArtifact(getOutputDir());
buildableContext.recordArtifact(outputPlist);
return stepsBuilder.build();
}
use of com.facebook.buck.step.Step 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.Step in project buck by facebook.
the class MergeAndroidResourceSources method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), destinationDirectory));
steps.add(new MergeAndroidResourceSourcesStep(originalDirectories.stream().map(context.getSourcePathResolver()::getAbsolutePath).collect(MoreCollectors.toImmutableList()), getProjectFilesystem().resolve(destinationDirectory), getProjectFilesystem().resolve(tempDirectory)));
buildableContext.recordArtifact(destinationDirectory);
return steps.build();
}
use of com.facebook.buck.step.Step in project buck by facebook.
the class SmartDexingStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
try {
Multimap<Path, Path> outputToInputs = outputToInputsSupplier.get();
runDxCommands(context, outputToInputs);
if (secondaryOutputDir.isPresent()) {
removeExtraneousSecondaryArtifacts(secondaryOutputDir.get(), outputToInputs.keySet(), filesystem);
// Concatenate if solid compression is specified.
// create a mapping of the xzs file target and the dex.jar files that go into it
ImmutableMultimap.Builder<Path, Path> secondaryDexJarsMultimapBuilder = ImmutableMultimap.builder();
for (Path p : outputToInputs.keySet()) {
if (DexStore.XZS.matchesPath(p)) {
String[] matches = p.getFileName().toString().split("-");
Path output = p.getParent().resolve(matches[0].concat(SECONDARY_SOLID_DEX_EXTENSION));
secondaryDexJarsMultimapBuilder.put(output, p);
}
}
ImmutableMultimap<Path, Path> secondaryDexJarsMultimap = secondaryDexJarsMultimapBuilder.build();
if (!secondaryDexJarsMultimap.isEmpty()) {
for (Map.Entry<Path, Collection<Path>> entry : secondaryDexJarsMultimap.asMap().entrySet()) {
Path store = entry.getKey();
Collection<Path> secondaryDexJars = entry.getValue();
// Construct the output path for our solid blob and its compressed form.
Path secondaryBlobOutput = store.getParent().resolve("uncompressed.dex.blob");
Path secondaryCompressedBlobOutput = store;
// Concatenate the jars into a blob and compress it.
StepRunner stepRunner = new DefaultStepRunner();
Step concatStep = new ConcatStep(filesystem, ImmutableList.copyOf(secondaryDexJars), secondaryBlobOutput);
Step xzStep;
if (xzCompressionLevel.isPresent()) {
xzStep = new XzStep(filesystem, secondaryBlobOutput, secondaryCompressedBlobOutput, xzCompressionLevel.get().intValue());
} else {
xzStep = new XzStep(filesystem, secondaryBlobOutput, secondaryCompressedBlobOutput);
}
stepRunner.runStepForBuildTarget(context, concatStep, Optional.empty());
stepRunner.runStepForBuildTarget(context, xzStep, Optional.empty());
}
}
}
} catch (StepFailedException | IOException e) {
context.logError(e, "There was an error in smart dexing step.");
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.step.Step in project buck by facebook.
the class SmartDexingStep method runDxCommands.
private void runDxCommands(ExecutionContext context, Multimap<Path, Path> outputToInputs) throws StepFailedException, InterruptedException {
DefaultStepRunner stepRunner = new DefaultStepRunner();
// Invoke dx commands in parallel for maximum thread utilization. In testing, dx revealed
// itself to be CPU (and not I/O) bound making it a good candidate for parallelization.
List<Step> dxSteps = generateDxCommands(filesystem, outputToInputs);
List<Callable<Void>> callables = Lists.transform(dxSteps, step -> (Callable<Void>) () -> {
stepRunner.runStepForBuildTarget(context, step, Optional.empty());
return null;
});
try {
MoreFutures.getAll(executorService, callables);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
Throwables.throwIfInstanceOf(cause, StepFailedException.class);
// Programmer error. Boo-urns.
throw new RuntimeException(cause);
}
}
Aggregations