use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class JavaTest method getPostBuildSteps.
@Override
public ImmutableList<Step> getPostBuildSteps(BuildContext buildContext) {
return ImmutableList.<Step>builder().add(new MkdirStep(getProjectFilesystem(), getClassPathFile().getParent())).add(new AbstractExecutionStep("write classpath file") {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException {
ImmutableSet<Path> classpathEntries = ImmutableSet.<Path>builder().addAll(compiledTestsLibrary.getTransitiveClasspaths().stream().map(buildContext.getSourcePathResolver()::getAbsolutePath).collect(MoreCollectors.toImmutableSet())).addAll(additionalClasspathEntries.stream().map(e -> e.isLeft() ? buildContext.getSourcePathResolver().getAbsolutePath(e.getLeft()) : e.getRight()).collect(MoreCollectors.toImmutableSet())).addAll(getBootClasspathEntries(context)).build();
getProjectFilesystem().writeLinesToPath(Iterables.transform(classpathEntries, Object::toString), getClassPathFile());
return StepExecutionResult.SUCCESS;
}
}).build();
}
use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class RelinkerRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
final ImmutableList.Builder<Step> relinkerSteps = ImmutableList.builder();
if (linker != null) {
ImmutableList<Arg> args = ImmutableList.<Arg>builder().addAll(linkerArgs).add(StringArg.of("-Wl,--version-script=" + getRelativeVersionFilePath().toString())).build();
relinkerSteps.addAll(new CxxLink(buildRuleParams.withAppendedFlavor(InternalFlavor.of("cxx-link")).withoutFlavor(LinkerMapMode.NO_LINKER_MAP.getFlavor()), linker, getLibFilePath(), args, cxxBuckConfig.getLinkScheduleInfo(), cxxBuckConfig.shouldCacheLinks()).getBuildSteps(context, buildableContext));
buildableContext.recordArtifact(getRelativeVersionFilePath());
}
buildableContext.recordArtifact(getSymbolsNeededOutPath());
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), getScratchDirPath()), new AbstractExecutionStep("xdso-dce relinker") {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
ImmutableSet<String> symbolsNeeded = readSymbolsNeeded();
if (linker == null) {
getProjectFilesystem().copyFile(getBaseLibPath(), getLibFilePath());
buildableContext.recordArtifact(getLibFilePath());
} else {
writeVersionScript(context.getProcessExecutor(), symbolsNeeded);
for (Step s : relinkerSteps.build()) {
StepExecutionResult executionResult = s.execute(context);
if (!executionResult.isSuccess()) {
return StepExecutionResult.ERROR;
}
}
}
writeSymbols(getSymbolsNeededOutPath(), Sets.union(symbolsNeeded, getSymbols(context.getProcessExecutor(), getLibFilePath()).undefined));
return StepExecutionResult.SUCCESS;
}
});
}
use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class CopyNativeLibraries method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), getBinPath()));
final Path pathToNativeLibs = getPathToNativeLibsDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToNativeLibs));
final Path pathToNativeLibsAssets = getPathToNativeLibsAssetsDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToNativeLibsAssets));
for (SourcePath nativeLibDir : nativeLibDirectories.asList().reverse()) {
copyNativeLibrary(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(nativeLibDir), pathToNativeLibs, cpuFilters, steps);
}
addStepsForCopyingStrippedNativeLibrariesOrAssets(context.getSourcePathResolver(), getProjectFilesystem(), stripLibRules, pathToNativeLibs, steps);
addStepsForCopyingStrippedNativeLibrariesOrAssets(context.getSourcePathResolver(), getProjectFilesystem(), stripLibAssetRules, pathToNativeLibsAssets, steps);
final Path pathToMetadataTxt = getPathToMetadataTxt();
steps.add(new AbstractExecutionStep("hash_native_libs") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
ProjectFilesystem filesystem = getProjectFilesystem();
ImmutableList.Builder<String> metadataLines = ImmutableList.builder();
try {
for (Path nativeLib : filesystem.getFilesUnderPath(getPathToAllLibsDir())) {
Sha1HashCode filesha1 = filesystem.computeSha1(nativeLib);
Path relativePath = getPathToAllLibsDir().relativize(nativeLib);
metadataLines.add(String.format("%s %s", relativePath, filesha1));
}
filesystem.writeLinesToPath(metadataLines.build(), pathToMetadataTxt);
} catch (IOException e) {
context.logError(e, "There was an error hashing native libraries.");
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
buildableContext.recordArtifact(pathToNativeLibs);
buildableContext.recordArtifact(pathToNativeLibsAssets);
buildableContext.recordArtifact(pathToMetadataTxt);
return steps.build();
}
use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class DexProducedFromJavaLibrary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new RmStep(getProjectFilesystem(), getPathToDex()));
// Make sure that the buck-out/gen/ directory exists for this.buildTarget.
steps.add(new MkdirStep(getProjectFilesystem(), getPathToDex().getParent()));
// If there are classes, run dx.
final ImmutableSortedMap<String, HashCode> classNamesToHashes = javaLibrary.getClassNamesToHashes();
final boolean hasClassesToDx = !classNamesToHashes.isEmpty();
final Supplier<Integer> weightEstimate;
@Nullable final DxStep dx;
if (hasClassesToDx) {
Path pathToOutputFile = context.getSourcePathResolver().getAbsolutePath(javaLibrarySourcePath);
EstimateDexWeightStep estimate = new EstimateDexWeightStep(getProjectFilesystem(), pathToOutputFile);
steps.add(estimate);
weightEstimate = estimate;
// To be conservative, use --force-jumbo for these intermediate .dex files so that they can be
// merged into a final classes.dex that uses jumbo instructions.
dx = new DxStep(getProjectFilesystem(), getPathToDex(), Collections.singleton(pathToOutputFile), EnumSet.of(DxStep.Option.USE_CUSTOM_DX_IF_AVAILABLE, DxStep.Option.RUN_IN_PROCESS, DxStep.Option.NO_OPTIMIZE, DxStep.Option.FORCE_JUMBO));
steps.add(dx);
// The `DxStep` delegates to android tools to build a ZIP with timestamps in it, making
// the output non-deterministic. So use an additional scrubbing step to zero these out.
steps.add(new ZipScrubberStep(getProjectFilesystem(), getPathToDex()));
} else {
dx = null;
weightEstimate = Suppliers.ofInstance(0);
}
// Run a step to record artifacts and metadata. The values recorded depend upon whether dx was
// run.
String stepName = hasClassesToDx ? "record_dx_success" : "record_empty_dx";
AbstractExecutionStep recordArtifactAndMetadataStep = new AbstractExecutionStep(stepName) {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException {
if (hasClassesToDx) {
buildableContext.recordArtifact(getPathToDex());
@Nullable Collection<String> referencedResources = dx.getResourcesReferencedInCode();
if (referencedResources != null) {
buildableContext.addMetadata(REFERENCED_RESOURCES, Ordering.natural().immutableSortedCopy(referencedResources));
}
}
buildableContext.addMetadata(WEIGHT_ESTIMATE, String.valueOf(weightEstimate.get()));
// Record the classnames to hashes map.
buildableContext.addMetadata(CLASSNAMES_TO_HASHES, context.getObjectMapper().writeValueAsString(Maps.transformValues(classNamesToHashes, Object::toString)));
return StepExecutionResult.SUCCESS;
}
};
steps.add(recordArtifactAndMetadataStep);
return steps.build();
}
use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.
the class ResourcesFilter method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
final ImmutableList.Builder<Path> filteredResDirectoriesBuilder = ImmutableList.builder();
ImmutableSet<Path> whitelistedStringPaths = whitelistedStringDirs.stream().map(context.getSourcePathResolver()::getRelativePath).collect(MoreCollectors.toImmutableSet());
ImmutableList<Path> resPaths = resDirectories.stream().map(context.getSourcePathResolver()::getRelativePath).collect(MoreCollectors.toImmutableList());
final FilterResourcesStep filterResourcesStep = createFilterResourcesStep(resPaths, whitelistedStringPaths, locales, filteredResDirectoriesBuilder);
steps.add(filterResourcesStep);
final ImmutableList.Builder<Path> stringFilesBuilder = ImmutableList.builder();
// The list of strings.xml files is only needed to build string assets
if (resourceCompressionMode.isStoreStringsAsAssets()) {
GetStringsFilesStep getStringsFilesStep = new GetStringsFilesStep(getProjectFilesystem(), resPaths, stringFilesBuilder);
steps.add(getStringsFilesStep);
}
final ImmutableList<Path> filteredResDirectories = filteredResDirectoriesBuilder.build();
for (Path outputResourceDir : filteredResDirectories) {
buildableContext.recordArtifact(outputResourceDir);
}
steps.add(new AbstractExecutionStep("record_build_output") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
buildableContext.addMetadata(RES_DIRECTORIES_KEY, filteredResDirectories.stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
buildableContext.addMetadata(STRING_FILES_KEY, stringFilesBuilder.build().stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
return StepExecutionResult.SUCCESS;
}
});
return steps.build();
}
Aggregations