use of com.facebook.buck.step.fs.MakeCleanDirectoryStep 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.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class ProGuardObfuscateStep method create.
/**
* Create steps that write out ProGuard's command line arguments to a text file and then run
* ProGuard using those arguments. We write the arguments to a file to avoid blowing out
* exec()'s ARG_MAX limit.
*
* @param steps Where to append the generated steps.
*/
public static void create(JavaRuntimeLauncher javaRuntimeLauncher, ProjectFilesystem filesystem, Optional<Path> proguardJarOverride, String proguardMaxHeapSize, Optional<String> proguardAgentPath, Path generatedProGuardConfig, Set<Path> customProguardConfigs, SdkProguardType sdkProguardConfig, Optional<Integer> optimizationPasses, Optional<List<String>> proguardJvmArgs, Map<Path, Path> inputAndOutputEntries, Set<Path> additionalLibraryJarsForProguard, Path proguardDirectory, BuildableContext buildableContext, boolean skipProguard, ImmutableList.Builder<Step> steps) {
steps.add(new MakeCleanDirectoryStep(filesystem, proguardDirectory));
Path pathToProGuardCommandLineArgsFile = proguardDirectory.resolve("command-line.txt");
CommandLineHelperStep commandLineHelperStep = new CommandLineHelperStep(filesystem, generatedProGuardConfig, customProguardConfigs, sdkProguardConfig, optimizationPasses, inputAndOutputEntries, additionalLibraryJarsForProguard, proguardDirectory, pathToProGuardCommandLineArgsFile);
if (skipProguard) {
steps.add(commandLineHelperStep, new TouchStep(filesystem, commandLineHelperStep.getMappingTxt()));
} else {
ProGuardObfuscateStep proGuardStep = new ProGuardObfuscateStep(javaRuntimeLauncher, filesystem, inputAndOutputEntries, pathToProGuardCommandLineArgsFile, skipProguard, proguardJarOverride, proguardMaxHeapSize, proguardJvmArgs, proguardAgentPath);
buildableContext.recordArtifact(commandLineHelperStep.getConfigurationTxt());
buildableContext.recordArtifact(commandLineHelperStep.getMappingTxt());
buildableContext.recordArtifact(commandLineHelperStep.getSeedsTxt());
steps.add(commandLineHelperStep, proGuardStep, // here to guarantee it's around when we go to cache this rule.
new TouchStep(filesystem, commandLineHelperStep.getMappingTxt()));
}
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class PrebuiltJar method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
SourcePathResolver resolver = context.getSourcePathResolver();
// Create a copy of the JAR in case it was generated by another rule.
Path resolvedBinaryJar = resolver.getAbsolutePath(binaryJar);
Path resolvedCopiedBinaryJar = getProjectFilesystem().resolve(copiedBinaryJar);
Preconditions.checkState(!resolvedBinaryJar.equals(resolvedCopiedBinaryJar), "%s: source (%s) can't be equal to destination (%s) when copying prebuilt JAR.", getBuildTarget().getFullyQualifiedName(), resolvedBinaryJar, copiedBinaryJar);
if (resolver.getFilesystem(binaryJar).isDirectory(resolvedBinaryJar)) {
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), copiedBinaryJar));
steps.add(CopyStep.forDirectory(getProjectFilesystem(), resolvedBinaryJar, copiedBinaryJar, CopyStep.DirectoryMode.CONTENTS_ONLY));
} else {
if (!MorePaths.getFileExtension(copiedBinaryJar.getFileName()).equals(MorePaths.getFileExtension(resolvedBinaryJar))) {
context.getEventBus().post(ConsoleEvent.warning("Assuming %s is a JAR and renaming to %s in %s. " + "Change the extension of the binary_jar to '.jar' to remove this warning.", resolvedBinaryJar.getFileName(), copiedBinaryJar.getFileName(), getBuildTarget().getFullyQualifiedName()));
}
steps.add(new MkdirStep(getProjectFilesystem(), copiedBinaryJar.getParent()));
steps.add(CopyStep.forFile(getProjectFilesystem(), resolvedBinaryJar, copiedBinaryJar));
}
buildableContext.recordArtifact(copiedBinaryJar);
// Create a step to compute the ABI key.
steps.add(new MkdirStep(getProjectFilesystem(), internalAbiJar.getParent()));
steps.add(new RmStep(getProjectFilesystem(), internalAbiJar));
steps.add(new CalculateAbiStep(buildableContext, getProjectFilesystem(), resolvedBinaryJar, internalAbiJar));
JavaLibraryRules.addAccumulateClassNamesStep(this, buildableContext, context.getSourcePathResolver(), steps);
return steps.build();
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class PrebuiltJarDescription method createGwtModule.
@VisibleForTesting
static BuildRule createGwtModule(BuildRuleParams params, Arg arg) {
// Because a PrebuiltJar rarely requires any building whatsoever (it could if the source_jar
// is a BuildTargetSourcePath), we make the PrebuiltJar a dependency of the GWT module. If this
// becomes a performance issue in practice, then we will explore reducing the dependencies of
// the GWT module.
final SourcePath input;
if (arg.gwtJar.isPresent()) {
input = arg.gwtJar.get();
} else if (arg.sourceJar.isPresent()) {
input = arg.sourceJar.get();
} else {
input = arg.binaryJar;
}
class ExistingOuputs extends AbstractBuildRule {
@AddToRuleKey
private final SourcePath source;
private final Path output;
protected ExistingOuputs(BuildRuleParams params, SourcePath source) {
super(params);
this.source = source;
BuildTarget target = params.getBuildTarget();
this.output = BuildTargets.getGenPath(getProjectFilesystem(), target, String.format("%s/%%s-gwt.jar", target.getShortName()));
}
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), output.getParent()));
steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(source), output));
return steps.build();
}
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), output);
}
}
return new ExistingOuputs(params, input);
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep 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();
}
Aggregations