use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class Zip method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
Path output = getOutput();
Path scratchDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.zip.scratch");
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new RmStep(getProjectFilesystem(), output));
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
SrcZipAwareFileBundler bundler = new SrcZipAwareFileBundler(getBuildTarget());
bundler.copy(getProjectFilesystem(), context.getSourcePathResolver(), steps, scratchDir, sources);
steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSortedSet.of(), /* junk paths */
false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, scratchDir));
buildableContext.recordArtifact(output);
return steps.build();
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class CxxLink method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(output);
Optional<Path> linkerMapPath = getLinkerMapPath();
if (linkerMapPath.isPresent() && LinkerMapMode.isLinkerMapEnabledForBuildTarget(getBuildTarget())) {
buildableContext.recordArtifact(linkerMapPath.get());
}
Path scratchDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s-tmp");
Path argFilePath = getProjectFilesystem().getRootPath().resolve(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.argsfile"));
Path fileListPath = getProjectFilesystem().getRootPath().resolve(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s__filelist.txt"));
// Try to find all the cell roots used during the link. This isn't technically correct since,
// in theory not all inputs need to come from build rules, but it probably works in practice.
// One way that we know would work is exposing every known cell root paths, since the only rules
// that we built (and therefore need to scrub) will be in one of those roots.
ImmutableSet.Builder<Path> cellRoots = ImmutableSet.builder();
for (BuildRule dep : getDeps()) {
cellRoots.add(dep.getProjectFilesystem().getRootPath());
}
return ImmutableList.of(new MkdirStep(getProjectFilesystem(), output.getParent()), new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir), new RmStep(getProjectFilesystem(), argFilePath), new RmStep(getProjectFilesystem(), fileListPath), CxxPrepareForLinkStep.create(argFilePath, fileListPath, linker.fileList(fileListPath), output, args, linker, getBuildTarget().getCellPath(), context.getSourcePathResolver()), new CxxLinkStep(getProjectFilesystem().getRootPath(), linker.getEnvironment(context.getSourcePathResolver()), linker.getCommandPrefix(context.getSourcePathResolver()), argFilePath, getProjectFilesystem().getRootPath().resolve(scratchDir)), new FileScrubberStep(getProjectFilesystem(), output, linker.getScrubbers(cellRoots.build())), new LogContentsOfFileStep(getProjectFilesystem().resolve(argFilePath), Level.FINEST), new RmStep(getProjectFilesystem(), argFilePath), new LogContentsOfFileStep(getProjectFilesystem().resolve(fileListPath), Level.FINEST), new RmStep(getProjectFilesystem(), fileListPath), new RmStep(getProjectFilesystem(), scratchDir, RmStep.Mode.RECURSIVE));
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class JarFattener method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Path outputDir = getOutputDirectory();
Path fatJarDir = outputDir.resolve("fat-jar-directory");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDir));
// Map of the system-specific shared library name to it's resource name as a string.
ImmutableMap.Builder<String, String> sonameToResourceMapBuilder = ImmutableMap.builder();
for (Map.Entry<String, SourcePath> entry : nativeLibraries.entrySet()) {
String resource = FAT_JAR_NATIVE_LIBRARY_RESOURCE_ROOT + "/" + entry.getKey();
sonameToResourceMapBuilder.put(entry.getKey(), resource);
steps.add(new MkdirStep(getProjectFilesystem(), fatJarDir.resolve(resource).getParent()));
steps.add(new SymlinkFileStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(entry.getValue()), fatJarDir.resolve(resource), /* useAbsolutePaths */
true));
}
ImmutableMap<String, String> sonameToResourceMap = sonameToResourceMapBuilder.build();
// Grab the source path representing the fat jar info resource.
Path fatJarInfo = fatJarDir.resolve(FatJar.FAT_JAR_INFO_RESOURCE);
steps.add(writeFatJarInfo(fatJarInfo, sonameToResourceMap));
// Build up the resource and src collections.
Set<Path> javaSourceFilePaths = Sets.newHashSet();
for (String srcResource : FAT_JAR_SRC_RESOURCES) {
Path fatJarSource = outputDir.resolve(Paths.get(srcResource).getFileName());
javaSourceFilePaths.add(fatJarSource);
steps.add(writeFromResource(fatJarSource, srcResource));
}
Path fatJarMainSource = outputDir.resolve(Paths.get(FAT_JAR_MAIN_SRC_RESOURCE).getFileName());
javaSourceFilePaths.add(fatJarMainSource);
steps.add(writeFromResource(fatJarMainSource, FAT_JAR_MAIN_SRC_RESOURCE));
// Symlink the inner JAR into it's place in the fat JAR.
steps.add(new MkdirStep(getProjectFilesystem(), fatJarDir.resolve(FAT_JAR_INNER_JAR).getParent()));
steps.add(new SymlinkFileStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(innerJar), fatJarDir.resolve(FAT_JAR_INNER_JAR), /* useAbsolutePaths */
true));
// Build the final fat JAR from the structure we've layed out above. We first package the
// fat jar resources (e.g. native libs) using the "stored" compression level, to avoid
// expensive compression on builds and decompression on startup.
Path zipped = outputDir.resolve("contents.zip");
Step zipStep = new ZipStep(getProjectFilesystem(), zipped, ImmutableSet.of(), false, ZipCompressionLevel.MIN_COMPRESSION_LEVEL, fatJarDir);
Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));
CompileToJarStepFactory compileStepFactory = new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY);
compileStepFactory.createCompileStep(context, ImmutableSortedSet.copyOf(javaSourceFilePaths), getBuildTarget(), context.getSourcePathResolver(), ruleFinder, getProjectFilesystem(), /* classpathEntries */
ImmutableSortedSet.of(), fatJarDir, /* workingDir */
Optional.empty(), pathToSrcsList, /* suggestBuildRule */
Optional.empty(), NoOpClassUsageFileWriter.instance(), steps, buildableContext);
steps.add(zipStep);
steps.add(new JarDirectoryStep(getProjectFilesystem(), output, ImmutableSortedSet.of(zipped), /* mainClass */
FatJarMain.class.getName(), /* manifestFile */
null));
return steps.build();
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class JavaBinary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> commands = ImmutableList.builder();
Path outputDirectory = getOutputDirectory();
Step mkdir = new MkdirStep(getProjectFilesystem(), outputDirectory);
commands.add(mkdir);
ImmutableSortedSet<Path> includePaths;
if (metaInfDirectory != null) {
Path stagingRoot = outputDirectory.resolve("meta_inf_staging");
Path stagingTarget = stagingRoot.resolve("META-INF");
MakeCleanDirectoryStep createStagingRoot = new MakeCleanDirectoryStep(getProjectFilesystem(), stagingRoot);
commands.add(createStagingRoot);
MkdirAndSymlinkFileStep link = new MkdirAndSymlinkFileStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(metaInfDirectory), stagingTarget);
commands.add(link);
includePaths = ImmutableSortedSet.<Path>naturalOrder().add(stagingRoot).addAll(context.getSourcePathResolver().getAllAbsolutePaths(getTransitiveClasspaths())).build();
} else {
includePaths = context.getSourcePathResolver().getAllAbsolutePaths(getTransitiveClasspaths());
}
Path outputFile = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
Path manifestPath = manifestFile == null ? null : context.getSourcePathResolver().getAbsolutePath(manifestFile);
Step jar = new JarDirectoryStep(getProjectFilesystem(), outputFile, includePaths, mainClass, manifestPath, mergeManifests, blacklist);
commands.add(jar);
buildableContext.recordArtifact(outputFile);
return commands.build();
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep 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();
}
Aggregations