use of com.facebook.buck.step.fs.MakeCleanDirectoryStep 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.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class AndroidBinary method addDexingSteps.
/**
* Create dex artifacts for all of the individual directories of compiled .class files (or
* the obfuscated jar files if proguard is used). If split dex is used, multiple dex artifacts
* will be produced.
* @param classpathEntriesToDex Full set of classpath entries that must make
* their way into the final APK structure (but not necessarily into the
* primary dex).
* @param secondaryDexDirectories The contract for updating this builder must match that
* of {@link PreDexMerge#getSecondaryDexDirectories()}.
* @param steps List of steps to add to.
* @param primaryDexPath Output path for the primary dex file.
*/
@VisibleForTesting
void addDexingSteps(Set<Path> classpathEntriesToDex, Supplier<ImmutableMap<String, HashCode>> classNamesToHashesSupplier, ImmutableSet.Builder<Path> secondaryDexDirectories, ImmutableList.Builder<Step> steps, Path primaryDexPath, Optional<SourcePath> dexReorderToolFile, Optional<SourcePath> dexReorderDataDumpFile, ImmutableMultimap<APKModule, Path> additionalDexStoreToJarPathMap, SourcePathResolver resolver) {
final Supplier<Set<Path>> primaryInputsToDex;
final Optional<Path> secondaryDexDir;
final Optional<Supplier<Multimap<Path, Path>>> secondaryOutputToInputs;
Path secondaryDexParentDir = getBinPath("__%s_secondary_dex__/");
Path additionalDexParentDir = getBinPath("__%s_additional_dex__/");
Path additionalDexAssetsDir = additionalDexParentDir.resolve("assets");
final Optional<ImmutableSet<Path>> additionalDexDirs;
if (shouldSplitDex()) {
Optional<Path> proguardFullConfigFile = Optional.empty();
Optional<Path> proguardMappingFile = Optional.empty();
if (packageType.isBuildWithObfuscation()) {
Path proguardConfigDir = getProguardTextFilesPath();
proguardFullConfigFile = Optional.of(proguardConfigDir.resolve("configuration.txt"));
proguardMappingFile = Optional.of(proguardConfigDir.resolve("mapping.txt"));
}
// DexLibLoader expects that metadata.txt and secondary jar files are under this dir
// in assets.
// Intermediate directory holding the primary split-zip jar.
Path splitZipDir = getBinPath("__%s_split_zip__");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), splitZipDir));
Path primaryJarPath = splitZipDir.resolve("primary.jar");
Path secondaryJarMetaDirParent = splitZipDir.resolve("secondary_meta");
Path secondaryJarMetaDir = secondaryJarMetaDirParent.resolve(SECONDARY_DEX_SUBDIR);
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), secondaryJarMetaDir));
Path secondaryJarMeta = secondaryJarMetaDir.resolve("metadata.txt");
// Intermediate directory holding _ONLY_ the secondary split-zip jar files. This is
// important because SmartDexingCommand will try to dx every entry in this directory. It
// does this because it's impossible to know what outputs split-zip will generate until it
// runs.
final Path secondaryZipDir = getBinPath("__%s_secondary_zip__");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), secondaryZipDir));
// Intermediate directory holding the directories holding _ONLY_ the additional split-zip
// jar files that are intended for that dex store.
final Path additionalDexStoresZipDir = getBinPath("__%s_dex_stores_zip__");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), additionalDexStoresZipDir));
for (APKModule dexStore : additionalDexStoreToJarPathMap.keySet()) {
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), additionalDexStoresZipDir.resolve(dexStore.getName())));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), secondaryJarMetaDirParent.resolve("assets").resolve(dexStore.getName())));
}
// Run the split-zip command which is responsible for dividing the large set of input
// classpaths into a more compact set of jar files such that no one jar file when dexed will
// yield a dex artifact too large for dexopt or the dx method limit to handle.
Path zipSplitReportDir = getBinPath("__%s_split_zip_report__");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), zipSplitReportDir));
SplitZipStep splitZipCommand = new SplitZipStep(getProjectFilesystem(), classpathEntriesToDex, secondaryJarMeta, primaryJarPath, secondaryZipDir, "secondary-%d.jar", secondaryJarMetaDirParent, additionalDexStoresZipDir, proguardFullConfigFile, proguardMappingFile, skipProguard, dexSplitMode, dexSplitMode.getPrimaryDexScenarioFile().map(resolver::getAbsolutePath), dexSplitMode.getPrimaryDexClassesFile().map(resolver::getAbsolutePath), dexSplitMode.getSecondaryDexHeadClassesFile().map(resolver::getAbsolutePath), dexSplitMode.getSecondaryDexTailClassesFile().map(resolver::getAbsolutePath), additionalDexStoreToJarPathMap, enhancementResult.getAPKModuleGraph(), zipSplitReportDir);
steps.add(splitZipCommand);
// smart dexing command. Smart dex will handle "cleaning" this directory properly.
if (reorderClassesIntraDex) {
secondaryDexDir = Optional.of(secondaryDexParentDir.resolve(SMART_DEX_SECONDARY_DEX_SUBDIR));
Path intraDexReorderSecondaryDexDir = secondaryDexParentDir.resolve(SECONDARY_DEX_SUBDIR);
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), secondaryDexDir.get()));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), intraDexReorderSecondaryDexDir));
} else {
secondaryDexDir = Optional.of(secondaryDexParentDir.resolve(SECONDARY_DEX_SUBDIR));
steps.add(new MkdirStep(getProjectFilesystem(), secondaryDexDir.get()));
}
if (additionalDexStoreToJarPathMap.isEmpty()) {
additionalDexDirs = Optional.empty();
} else {
ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
for (APKModule dexStore : additionalDexStoreToJarPathMap.keySet()) {
Path dexStorePath = additionalDexAssetsDir.resolve(dexStore.getName());
builder.add(dexStorePath);
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), dexStorePath));
}
additionalDexDirs = Optional.of(builder.build());
}
if (dexSplitMode.getDexStore() == DexStore.RAW) {
secondaryDexDirectories.add(secondaryDexDir.get());
} else {
secondaryDexDirectories.add(secondaryJarMetaDirParent);
secondaryDexDirectories.add(secondaryDexParentDir);
}
if (additionalDexDirs.isPresent()) {
secondaryDexDirectories.add(additionalDexParentDir);
}
// Adjust smart-dex inputs for the split-zip case.
primaryInputsToDex = Suppliers.ofInstance(ImmutableSet.of(primaryJarPath));
Supplier<Multimap<Path, Path>> secondaryOutputToInputsMap = splitZipCommand.getOutputToInputsMapSupplier(secondaryDexDir.get(), additionalDexAssetsDir);
secondaryOutputToInputs = Optional.of(secondaryOutputToInputsMap);
} else {
// Simple case where our inputs are the natural classpath directories and we don't have
// to worry about secondary jar/dex files.
primaryInputsToDex = Suppliers.ofInstance(classpathEntriesToDex);
secondaryDexDir = Optional.empty();
secondaryOutputToInputs = Optional.empty();
}
HashInputJarsToDexStep hashInputJarsToDexStep = new HashInputJarsToDexStep(getProjectFilesystem(), primaryInputsToDex, secondaryOutputToInputs, classNamesToHashesSupplier);
steps.add(hashInputJarsToDexStep);
// Stores checksum information from each invocation to intelligently decide when dx needs
// to be re-run.
Path successDir = getBinPath("__%s_smart_dex__/.success");
steps.add(new MkdirStep(getProjectFilesystem(), successDir));
// Add the smart dexing tool that is capable of avoiding the external dx invocation(s) if
// it can be shown that the inputs have not changed. It also parallelizes dx invocations
// where applicable.
//
// Note that by not specifying the number of threads this command will use it will select an
// optimal default regardless of the value of --num-threads. This decision was made with the
// assumption that --num-threads specifies the threading of build rule execution and does not
// directly apply to the internal threading/parallelization details of various build commands
// being executed. For example, aapt is internally threaded by default when preprocessing
// images.
EnumSet<DxStep.Option> dxOptions = PackageType.RELEASE.equals(packageType) ? EnumSet.of(DxStep.Option.NO_LOCALS) : EnumSet.of(DxStep.Option.NO_OPTIMIZE);
Path selectedPrimaryDexPath = primaryDexPath;
if (reorderClassesIntraDex) {
String primaryDexFileName = primaryDexPath.getFileName().toString();
String smartDexPrimaryDexFileName = "smart-dex-" + primaryDexFileName;
Path smartDexPrimaryDexPath = Paths.get(primaryDexPath.toString().replace(primaryDexFileName, smartDexPrimaryDexFileName));
selectedPrimaryDexPath = smartDexPrimaryDexPath;
}
SmartDexingStep smartDexingCommand = new SmartDexingStep(getProjectFilesystem(), selectedPrimaryDexPath, primaryInputsToDex, secondaryDexDir, secondaryOutputToInputs, hashInputJarsToDexStep, successDir, dxOptions, dxExecutorService, xzCompressionLevel, dxMaxHeapSize);
steps.add(smartDexingCommand);
if (reorderClassesIntraDex) {
IntraDexReorderStep intraDexReorderStep = new IntraDexReorderStep(getProjectFilesystem(), resolver.getAbsolutePath(dexReorderToolFile.get()), resolver.getAbsolutePath(dexReorderDataDumpFile.get()), getBuildTarget(), selectedPrimaryDexPath, primaryDexPath, secondaryOutputToInputs, SMART_DEX_SECONDARY_DEX_SUBDIR, SECONDARY_DEX_SUBDIR);
steps.add(intraDexReorderStep);
}
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class DummyRDotJava method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
final Path rDotJavaSrcFolder = getRDotJavaSrcFolder(getBuildTarget(), getProjectFilesystem());
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), rDotJavaSrcFolder));
// Generate the .java files and record where they will be written in javaSourceFilePaths.
ImmutableSortedSet<Path> javaSourceFilePaths;
if (androidResourceDeps.isEmpty()) {
// In this case, the user is likely running a Robolectric test that does not happen to
// depend on any resources. However, if Robolectric doesn't find an R.java file, it flips
// out, so we have to create one, anyway.
// TODO(bolinfest): Stop hardcoding com.facebook. This should match the package in the
// associated TestAndroidManifest.xml file.
Path emptyRDotJava = rDotJavaSrcFolder.resolve("com/facebook/R.java");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), emptyRDotJava.getParent()));
steps.add(new WriteFileStep(getProjectFilesystem(), "package com.facebook;\n public class R {}\n", emptyRDotJava, /* executable */
false));
javaSourceFilePaths = ImmutableSortedSet.of(emptyRDotJava);
} else {
MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(getProjectFilesystem(), context.getSourcePathResolver(), androidResourceDeps, rDotJavaSrcFolder, forceFinalResourceIds, unionPackage, /* rName */
Optional.empty(), useOldStyleableFormat);
steps.add(mergeStep);
if (!finalRName.isPresent()) {
javaSourceFilePaths = mergeStep.getRDotJavaFiles();
} else {
MergeAndroidResourcesStep mergeFinalRStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(getProjectFilesystem(), context.getSourcePathResolver(), androidResourceDeps, rDotJavaSrcFolder, /* forceFinalResourceIds */
true, unionPackage, finalRName, useOldStyleableFormat);
steps.add(mergeFinalRStep);
javaSourceFilePaths = ImmutableSortedSet.<Path>naturalOrder().addAll(mergeStep.getRDotJavaFiles()).addAll(mergeFinalRStep.getRDotJavaFiles()).build();
}
}
// Clear out the directory where the .class files will be generated.
final Path rDotJavaClassesFolder = getRDotJavaBinFolder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), rDotJavaClassesFolder));
Path pathToAbiOutputDir = getPathToAbiOutputDir(getBuildTarget(), getProjectFilesystem());
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToAbiOutputDir));
Path pathToAbiOutputFile = pathToAbiOutputDir.resolve("abi.jar");
Path pathToJarOutputDir = outputJar.getParent();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToJarOutputDir));
Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));
// Compile the .java files.
final JavacStep javacStep = RDotJava.createJavacStepForDummyRDotJavaFiles(javaSourceFilePaths, pathToSrcsList, rDotJavaClassesFolder, javacOptions, getBuildTarget(), context.getSourcePathResolver(), ruleFinder, getProjectFilesystem());
steps.add(javacStep);
buildableContext.recordArtifact(rDotJavaClassesFolder);
steps.add(new JarDirectoryStep(getProjectFilesystem(), outputJar, ImmutableSortedSet.of(rDotJavaClassesFolder), /* mainClass */
null, /* manifestFile */
null));
buildableContext.recordArtifact(outputJar);
steps.add(new CalculateAbiStep(buildableContext, getProjectFilesystem(), rDotJavaClassesFolder, pathToAbiOutputFile));
return steps.build();
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class AndroidResource method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
buildableContext.recordArtifact(Preconditions.checkNotNull(pathToTextSymbolsFile));
buildableContext.recordArtifact(Preconditions.checkNotNull(pathToRDotJavaPackageFile));
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), Preconditions.checkNotNull(pathToTextSymbolsDir)));
if (getRes() == null) {
return steps.add(new TouchStep(getProjectFilesystem(), pathToTextSymbolsFile)).add(new WriteFileStep(getProjectFilesystem(), rDotJavaPackageArgument == null ? "" : rDotJavaPackageArgument, pathToRDotJavaPackageFile, false)).build();
}
// from the AndroidManifest.xml.
if (rDotJavaPackageArgument == null) {
Preconditions.checkNotNull(manifestFile, "manifestFile cannot be null when res is non-null and rDotJavaPackageArgument is " + "null. This should already be enforced by the constructor.");
steps.add(new ExtractFromAndroidManifestStep(context.getSourcePathResolver().getAbsolutePath(manifestFile), getProjectFilesystem(), buildableContext, METADATA_KEY_FOR_R_DOT_JAVA_PACKAGE, Preconditions.checkNotNull(pathToRDotJavaPackageFile)));
} else {
steps.add(new WriteFileStep(getProjectFilesystem(), rDotJavaPackageArgument, pathToRDotJavaPackageFile, false));
}
ImmutableSet<Path> pathsToSymbolsOfDeps = symbolsOfDeps.get().stream().map(context.getSourcePathResolver()::getAbsolutePath).collect(MoreCollectors.toImmutableSet());
steps.add(new MiniAapt(context.getSourcePathResolver(), getProjectFilesystem(), Preconditions.checkNotNull(res), Preconditions.checkNotNull(pathToTextSymbolsFile), pathsToSymbolsOfDeps, resourceUnion, isGrayscaleImageProcessingEnabled));
return steps.build();
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class AndroidInstrumentationTest method runTests.
@Override
public ImmutableList<Step> runTests(ExecutionContext executionContext, TestRunningOptions options, SourcePathResolver pathResolver, TestReportingCallback testReportingCallback) {
Preconditions.checkArgument(executionContext.getAdbOptions().isPresent());
if (executionContext.getAdbOptions().get().isMultiInstallModeEnabled()) {
throw new HumanReadableException("Running android instrumentation tests with multiple devices is not supported.");
}
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Path pathToTestOutput = getPathToTestOutputDirectory();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));
steps.add(new ApkInstallStep(pathResolver, apk));
if (apk instanceof AndroidInstrumentationApk) {
steps.add(new ApkInstallStep(pathResolver, ((AndroidInstrumentationApk) apk).getApkUnderTest()));
}
AdbHelper adb = AdbHelper.get(executionContext, true);
IDevice device;
try {
device = adb.getSingleDevice();
} catch (InterruptedException e) {
throw new HumanReadableException("Unable to get connected device.");
}
steps.add(getInstrumentationStep(pathResolver, executionContext.getPathToAdbExecutable(), Optional.of(getProjectFilesystem().resolve(pathToTestOutput)), Optional.of(device.getSerialNumber()), Optional.empty(), getFilterString(options), Optional.empty()));
return steps.build();
}
Aggregations