use of com.facebook.buck.zip.ZipStep in project buck by facebook.
the class AndroidAar method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> commands = ImmutableList.builder();
// Create temp folder to store the files going to be zipped
commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
// Remove the output .aar file
commands.add(new RmStep(getProjectFilesystem(), pathToOutputFile));
// put manifest into tmp folder
commands.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(manifest.getSourcePathToOutput()), temp.resolve("AndroidManifest.xml")));
// put R.txt into tmp folder
commands.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(androidResource.getPathToTextSymbolsFile())), temp.resolve("R.txt")));
// put res/ and assets/ into tmp folder
commands.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(assembledResourceDirectory), temp.resolve("res"), CopyStep.DirectoryMode.CONTENTS_ONLY));
commands.add(CopyStep.forDirectory(getProjectFilesystem(), context.getSourcePathResolver().getRelativePath(assembledAssetsDirectory), temp.resolve("assets"), CopyStep.DirectoryMode.CONTENTS_ONLY));
// Create our Uber-jar, and place it in the tmp folder.
commands.add(new JarDirectoryStep(getProjectFilesystem(), temp.resolve("classes.jar"), context.getSourcePathResolver().getAllAbsolutePaths(classpathsToIncludeInJar), /* mainClass */
null, /* manifestFile */
null));
// move native libs into tmp folder under jni/
if (assembledNativeLibs.isPresent()) {
commands.add(CopyStep.forDirectory(getProjectFilesystem(), assembledNativeLibs.get(), temp.resolve("jni"), CopyStep.DirectoryMode.CONTENTS_ONLY));
}
// move native assets into tmp folder under assets/lib/
for (SourcePath dir : nativeLibAssetsDirectories) {
CopyNativeLibraries.copyNativeLibrary(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(dir), temp.resolve("assets").resolve("lib"), ImmutableSet.of(), commands);
}
// do the zipping
commands.add(new MkdirStep(getProjectFilesystem(), pathToOutputFile.getParent()));
commands.add(new ZipStep(getProjectFilesystem(), pathToOutputFile, ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, temp));
buildableContext.recordArtifact(pathToOutputFile);
return commands.build();
}
use of com.facebook.buck.zip.ZipStep in project buck by facebook.
the class BuiltinApplePackage method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> commands = ImmutableList.builder();
// Remove the output .ipa file if it exists already
commands.add(new RmStep(getProjectFilesystem(), pathToOutputFile));
// Create temp folder to store the files going to be zipped
commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
Path payloadDir = temp.resolve("Payload");
commands.add(new MkdirStep(getProjectFilesystem(), payloadDir));
// Recursively copy the .app directory into the Payload folder
Path bundleOutputPath = context.getSourcePathResolver().getRelativePath(Preconditions.checkNotNull(bundle.getSourcePathToOutput()));
appendAdditionalAppleWatchSteps(commands);
commands.add(CopyStep.forDirectory(getProjectFilesystem(), bundleOutputPath, payloadDir, CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
appendAdditionalSwiftSteps(context.getSourcePathResolver(), commands);
// do the zipping
commands.add(new MkdirStep(getProjectFilesystem(), pathToOutputFile.getParent()));
commands.add(new ZipStep(getProjectFilesystem(), pathToOutputFile, ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, temp));
buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
return commands.build();
}
use of com.facebook.buck.zip.ZipStep in project buck by facebook.
the class PackageStringAssets method getBuildSteps.
// TODO(russellporter): Add an integration test for packaging string assets
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
if (filteredResourcesProvider.getResDirectories().isEmpty()) {
// There is no zip file, but we still need to provide a consistent hash to
// ComputeExopackageDepsAbi in this case.
buildableContext.addMetadata(STRING_ASSETS_ZIP_HASH, Hashing.sha1().hashInt(0).toString());
return ImmutableList.of();
}
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// We need to generate a zip file with the following dir structure:
// /assets/strings/*.fbstr
Path pathToBaseDir = getPathToStringAssetsDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToBaseDir));
Path pathToDirContainingAssetsDir = pathToBaseDir.resolve("string_assets");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToDirContainingAssetsDir));
final Path pathToStrings = pathToDirContainingAssetsDir.resolve("assets").resolve("strings");
Function<String, Path> assetPathBuilder = locale -> pathToStrings.resolve(locale + STRING_ASSET_FILE_EXTENSION);
Path pathToStringAssetsZip = getPathToStringAssetsZip();
Path pathToAllLocalesStringAssetsZip = getPathToAllLocalesStringAssetsZip();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToStrings));
steps.add(new CompileStringsStep(getProjectFilesystem(), filteredResourcesProvider.getStringFiles(), aaptPackageResources.getPathToRDotTxtDir(), assetPathBuilder));
steps.add(new ZipStep(getProjectFilesystem(), pathToAllLocalesStringAssetsZip, ImmutableSet.of(), false, ZipCompressionLevel.MAX_COMPRESSION_LEVEL, pathToDirContainingAssetsDir));
steps.add(new ZipStep(getProjectFilesystem(), pathToStringAssetsZip, locales.stream().map(assetPathBuilder::apply).collect(MoreCollectors.toImmutableSet()), false, ZipCompressionLevel.MAX_COMPRESSION_LEVEL, pathToDirContainingAssetsDir));
steps.add(new RecordFileSha1Step(getProjectFilesystem(), pathToStringAssetsZip, STRING_ASSETS_ZIP_HASH, buildableContext));
buildableContext.recordArtifact(pathToAllLocalesStringAssetsZip);
buildableContext.recordArtifact(pathToStringAssetsZip);
return steps.build();
}
use of com.facebook.buck.zip.ZipStep in project buck by facebook.
the class Javadoc method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(output);
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
steps.add(new RmStep(getProjectFilesystem(), output));
// Fast path: nothing to do so just create an empty zip and return.
if (sources.isEmpty()) {
steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.<Path>of(), /* junk paths */
false, ZipCompressionLevel.MIN_COMPRESSION_LEVEL, output));
return steps.build();
}
Path sourcesListFilePath = scratchDir.resolve("all-sources.txt");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
// Write an @-file with all the source files in
steps.add(new WriteFileStep(getProjectFilesystem(), Joiner.on("\n").join(sources.stream().map(context.getSourcePathResolver()::getAbsolutePath).map(Path::toString).iterator()), sourcesListFilePath, /* can execute */
false));
Path atArgs = scratchDir.resolve("options");
// Write an @-file with the classpath
StringBuilder argsBuilder = new StringBuilder("-classpath ");
Joiner.on(File.pathSeparator).appendTo(argsBuilder, getDeps().stream().filter(HasClasspathEntries.class::isInstance).flatMap(rule -> ((HasClasspathEntries) rule).getTransitiveClasspaths().stream()).map(context.getSourcePathResolver()::getAbsolutePath).map(Object::toString).iterator());
steps.add(new WriteFileStep(getProjectFilesystem(), argsBuilder.toString(), atArgs, /* can execute */
false));
Path uncompressedOutputDir = scratchDir.resolve("docs");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), uncompressedOutputDir));
steps.add(new ShellStep(getProjectFilesystem().resolve(scratchDir)) {
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
return ImmutableList.of("javadoc", "-Xdoclint:none", "-notimestamp", "-d", uncompressedOutputDir.getFileName().toString(), "@" + getProjectFilesystem().resolve(atArgs), "@" + getProjectFilesystem().resolve(sourcesListFilePath));
}
@Override
public String getShortName() {
return "javadoc";
}
});
steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.of(), /* junk paths */
false, DEFAULT_COMPRESSION_LEVEL, uncompressedOutputDir));
return steps.build();
}
use of com.facebook.buck.zip.ZipStep 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();
}
Aggregations