use of com.facebook.buck.step.fs.RmStep in project buck by facebook.
the class JavaSourceJar method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
JavaPackageFinder packageFinder = context.getJavaPackageFinder();
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
steps.add(new RmStep(getProjectFilesystem(), output));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
Set<Path> seenPackages = Sets.newHashSet();
for (Path source : context.getSourcePathResolver().filterInputsToCompareToOutput(sources)) {
Path packageFolder = packageFinder.findJavaPackageFolder(source);
Path packageDir = temp.resolve(packageFolder);
if (seenPackages.add(packageDir)) {
steps.add(new MkdirStep(getProjectFilesystem(), packageDir));
}
steps.add(CopyStep.forFile(getProjectFilesystem(), source, packageDir.resolve(source.getFileName())));
}
steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.of(), /* junk paths */
false, DEFAULT_COMPRESSION_LEVEL, temp));
buildableContext.recordArtifact(output);
return steps.build();
}
use of com.facebook.buck.step.fs.RmStep in project buck by facebook.
the class JsBundle method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
final SourcePathResolver sourcePathResolver = context.getSourcePathResolver();
final SourcePath jsOutputDir = getSourcePathToOutput();
final SourcePath sourceMapFile = getSourcePathToSourceMap();
String jobArgs = Stream.concat(Stream.of("bundle", JsFlavors.bundleJobArgs(getBuildTarget().getFlavors()), JsUtil.resolveMapJoin(libraries, sourcePathResolver, p -> "--lib " + p), String.format("--sourcemap %s", sourcePathResolver.getAbsolutePath(sourceMapFile)), String.format("--out %s/%s", sourcePathResolver.getAbsolutePath(jsOutputDir), bundleName)), entryPoints.stream()).filter(s -> !s.isEmpty()).collect(Collectors.joining(" "));
buildableContext.recordArtifact(sourcePathResolver.getRelativePath(jsOutputDir));
buildableContext.recordArtifact(sourcePathResolver.getRelativePath(sourceMapFile));
return ImmutableList.of(new RmStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(getOutputRoot())), new MkdirStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(jsOutputDir)), new MkdirStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(sourceMapFile).getParent()), JsUtil.workerShellStep(worker, jobArgs, getBuildTarget(), sourcePathResolver, getProjectFilesystem()));
}
use of com.facebook.buck.step.fs.RmStep in project buck by facebook.
the class JsLibrary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
final SourcePathResolver sourcePathResolver = context.getSourcePathResolver();
final Path outputPath = sourcePathResolver.getAbsolutePath(getSourcePathToOutput());
final String jobArgs = String.format("library %s --out %s %s", JsUtil.resolveMapJoin(libraryDependencies, sourcePathResolver, p -> "--lib " + p), outputPath, JsUtil.resolveMapJoin(sources, sourcePathResolver, Path::toString));
return ImmutableList.of(new RmStep(getProjectFilesystem(), outputPath), JsUtil.workerShellStep(worker, jobArgs, getBuildTarget(), sourcePathResolver, getProjectFilesystem()));
}
use of com.facebook.buck.step.fs.RmStep 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.fs.RmStep in project buck by facebook.
the class HaskellPackageRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// Setup the scratch dir.
Path scratchDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
// Setup the package DB directory.
final Path packageDb = getPackageDb();
steps.add(new RmStep(getProjectFilesystem(), packageDb, RmStep.Mode.RECURSIVE));
buildableContext.recordArtifact(packageDb);
// Create the registration file.
Path registrationFile = scratchDir.resolve("registration-file");
steps.add(getWriteRegistrationFileStep(context.getSourcePathResolver(), registrationFile, packageDb));
// Build the the package DB.
steps.add(new GhcPkgStep(context.getSourcePathResolver(), ImmutableList.of("init", packageDb.toString()), ImmutableMap.of()));
steps.add(new GhcPkgStep(context.getSourcePathResolver(), ImmutableList.of("-v0", "register", "--package-conf=" + packageDb, "--no-expand-pkgroot", registrationFile.toString()), ImmutableMap.of("GHC_PACKAGE_PATH", depPackages.values().stream().map(input -> context.getSourcePathResolver().getAbsolutePath(input.getPackageDb()).toString()).collect(Collectors.joining(":")))));
return steps.build();
}
Aggregations