use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class SymlinkTreeTest method testSymlinkTreeBuildSteps.
@Test
public void testSymlinkTreeBuildSteps() throws IOException {
// Create the fake build contexts.
BuildContext buildContext = FakeBuildContext.withSourcePathResolver(pathResolver);
FakeBuildableContext buildableContext = new FakeBuildableContext();
ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
// Verify the build steps are as expected.
ImmutableList<Step> expectedBuildSteps = ImmutableList.of(new MakeCleanDirectoryStep(filesystem, outputPath), new SymlinkTreeStep(filesystem, outputPath, pathResolver.getMappedPaths(links)));
ImmutableList<Step> actualBuildSteps = symlinkTreeBuildRule.getBuildSteps(buildContext, buildableContext);
assertEquals(expectedBuildSteps, actualBuildSteps.subList(1, actualBuildSteps.size()));
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class AaptPackageResources method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// Copy manifest to a path named AndroidManifest.xml after replacing the manifest placeholders
// if needed. Do this before running any other commands to ensure that it is available at the
// desired path.
steps.add(new MkdirStep(getProjectFilesystem(), getAndroidManifestXml().getParent()));
Optional<ImmutableMap<String, String>> placeholders = manifestEntries.getPlaceholders();
if (placeholders.isPresent() && !placeholders.get().isEmpty()) {
steps.add(new ReplaceManifestPlaceholdersStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(manifest), getAndroidManifestXml(), placeholders.get()));
} else {
steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(manifest), getAndroidManifestXml()));
}
steps.add(new MkdirStep(getProjectFilesystem(), getResourceApkPath().getParent()));
Path rDotTxtDir = getPathToRDotTxtDir();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), rDotTxtDir));
Path pathToGeneratedProguardConfig = getPathToGeneratedProguardConfigFile();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToGeneratedProguardConfig.getParent()));
buildableContext.recordArtifact(pathToGeneratedProguardConfig);
steps.add(new AaptStep(getProjectFilesystem().getRootPath(), getAndroidManifestXml(), filteredResourcesProvider.getResDirectories(), context.getSourcePathResolver().getAllAbsolutePaths(assetsDirectories), getResourceApkPath(), rDotTxtDir, pathToGeneratedProguardConfig, /*
* In practice, it appears that if --no-crunch is used, resources will occasionally
* appear distorted in the APK produced by this command (and what's worse, a clean
* reinstall does not make the problem go away). This is not reliably reproducible, so
* for now, we categorically outlaw the use of --no-crunch so that developers do not get
* stuck in the distorted image state. One would expect the use of --no-crunch to allow
* for faster build times, so it would be nice to figure out a way to leverage it in
* debug mode that never results in distorted images.
*/
!skipCrunchPngs, /* && packageType.isCrunchPngFiles() */
includesVectorDrawables, manifestEntries), new ZipScrubberStep(getProjectFilesystem(), getResourceApkPath()));
// If we had an empty res directory, we won't generate an R.txt file. This ensures that it
// always exists.
steps.add(new TouchStep(getProjectFilesystem(), getPathToRDotTxtFile()));
if (hasRDotJava()) {
generateRDotJavaFiles(steps, buildableContext, context);
}
// Record the filtered resources dirs, since when we initialize ourselves from disk, we'll
// need to test whether this is empty or not without requiring the `ResourcesFilter` rule to
// be available.
buildableContext.addMetadata(FILTERED_RESOURCE_DIRS_KEY, FluentIterable.from(filteredResourcesProvider.getResDirectories()).transform(Object::toString).toSortedList(Ordering.natural()));
buildableContext.recordArtifact(getAndroidManifestXml());
buildableContext.recordArtifact(getResourceApkPath());
steps.add(new RecordFileSha1Step(getProjectFilesystem(), getResourceApkPath(), RESOURCE_PACKAGE_HASH_KEY, buildableContext));
return steps.build();
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class AndroidBinary method addFinalDxSteps.
/**
* Adds steps to do the final dexing or dex merging before building the apk.
*/
private DexFilesInfo addFinalDxSteps(BuildableContext buildableContext, SourcePathResolver resolver, ImmutableList.Builder<Step> steps) {
AndroidPackageableCollection packageableCollection = enhancementResult.getPackageableCollection();
ImmutableSet<Path> classpathEntriesToDex = Stream.concat(enhancementResult.getClasspathEntriesToDex().stream(), RichStream.of(enhancementResult.getCompiledUberRDotJava().getSourcePathToOutput())).map(resolver::getRelativePath).collect(MoreCollectors.toImmutableSet());
ImmutableMultimap.Builder<APKModule, Path> additionalDexStoreToJarPathMapBuilder = ImmutableMultimap.builder();
additionalDexStoreToJarPathMapBuilder.putAll(enhancementResult.getPackageableCollection().getModuleMappedClasspathEntriesToDex().entries().stream().map(input -> new AbstractMap.SimpleEntry<>(input.getKey(), resolver.getRelativePath(input.getValue()))).collect(MoreCollectors.toImmutableSet()));
ImmutableMultimap<APKModule, Path> additionalDexStoreToJarPathMap = additionalDexStoreToJarPathMapBuilder.build();
// Execute preprocess_java_classes_binary, if appropriate.
if (preprocessJavaClassesBash.isPresent()) {
// Symlink everything in dexTransitiveDependencies.classpathEntriesToDex to the input
// directory. Expect parallel outputs in the output directory and update classpathEntriesToDex
// to reflect that.
final Path preprocessJavaClassesInDir = getBinPath("java_classes_preprocess_in_%s");
final Path preprocessJavaClassesOutDir = getBinPath("java_classes_preprocess_out_%s");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), preprocessJavaClassesInDir));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), preprocessJavaClassesOutDir));
steps.add(new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(), classpathEntriesToDex, preprocessJavaClassesInDir));
classpathEntriesToDex = classpathEntriesToDex.stream().map(preprocessJavaClassesOutDir::resolve).collect(MoreCollectors.toImmutableSet());
AbstractGenruleStep.CommandString commandString = new AbstractGenruleStep.CommandString(/* cmd */
Optional.empty(), /* bash */
preprocessJavaClassesBash.map(macroExpander::apply), /* cmdExe */
Optional.empty());
steps.add(new AbstractGenruleStep(getProjectFilesystem(), this.getBuildTarget(), commandString, getProjectFilesystem().getRootPath().resolve(preprocessJavaClassesInDir)) {
@Override
protected void addEnvironmentVariables(ExecutionContext context, ImmutableMap.Builder<String, String> environmentVariablesBuilder) {
environmentVariablesBuilder.put("IN_JARS_DIR", getProjectFilesystem().resolve(preprocessJavaClassesInDir).toString());
environmentVariablesBuilder.put("OUT_JARS_DIR", getProjectFilesystem().resolve(preprocessJavaClassesOutDir).toString());
AndroidPlatformTarget platformTarget = context.getAndroidPlatformTarget();
String bootclasspath = Joiner.on(':').join(Iterables.transform(platformTarget.getBootclasspathEntries(), getProjectFilesystem()::resolve));
environmentVariablesBuilder.put("ANDROID_BOOTCLASSPATH", bootclasspath);
}
});
}
// Execute proguard if desired (transforms input classpaths).
if (packageType.isBuildWithObfuscation()) {
classpathEntriesToDex = addProguardCommands(classpathEntriesToDex, packageableCollection.getProguardConfigs().stream().map(resolver::getAbsolutePath).collect(MoreCollectors.toImmutableSet()), skipProguard, steps, buildableContext, resolver);
}
Supplier<ImmutableMap<String, HashCode>> classNamesToHashesSupplier;
boolean classFilesHaveChanged = preprocessJavaClassesBash.isPresent() || packageType.isBuildWithObfuscation();
if (classFilesHaveChanged) {
classNamesToHashesSupplier = addAccumulateClassNamesStep(classpathEntriesToDex, steps);
} else {
classNamesToHashesSupplier = packageableCollection.getClassNamesToHashesSupplier();
}
// Create the final DEX (or set of DEX files in the case of split dex).
// The APK building command needs to take a directory of raw files, so primaryDexPath
// can only contain .dex files from this build rule.
// Create dex artifacts. If split-dex is used, the assets/ directory should contain entries
// that look something like the following:
//
// assets/secondary-program-dex-jars/metadata.txt
// assets/secondary-program-dex-jars/secondary-1.dex.jar
// assets/secondary-program-dex-jars/secondary-2.dex.jar
// assets/secondary-program-dex-jars/secondary-3.dex.jar
//
// The contents of the metadata.txt file should look like:
// secondary-1.dex.jar fffe66877038db3af2cbd0fe2d9231ed5912e317 secondary.dex01.Canary
// secondary-2.dex.jar b218a3ea56c530fed6501d9f9ed918d1210cc658 secondary.dex02.Canary
// secondary-3.dex.jar 40f11878a8f7a278a3f12401c643da0d4a135e1a secondary.dex03.Canary
//
// The scratch directories that contain the metadata.txt and secondary-N.dex.jar files must be
// listed in secondaryDexDirectoriesBuilder so that their contents will be compressed
// appropriately for Froyo.
ImmutableSet.Builder<Path> secondaryDexDirectoriesBuilder = ImmutableSet.builder();
Optional<PreDexMerge> preDexMerge = enhancementResult.getPreDexMerge();
if (!preDexMerge.isPresent()) {
steps.add(new MkdirStep(getProjectFilesystem(), primaryDexPath.getParent()));
addDexingSteps(classpathEntriesToDex, classNamesToHashesSupplier, secondaryDexDirectoriesBuilder, steps, primaryDexPath, dexReorderToolFile, dexReorderDataDumpFile, additionalDexStoreToJarPathMap, resolver);
} else if (!ExopackageMode.enabledForSecondaryDexes(exopackageModes)) {
secondaryDexDirectoriesBuilder.addAll(preDexMerge.get().getSecondaryDexDirectories());
}
return new DexFilesInfo(primaryDexPath, secondaryDexDirectoriesBuilder.build());
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class AndroidBuildConfig method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Supplier<BuildConfigFields> totalFields;
if (valuesFile.isPresent()) {
final ReadValuesStep readValuesStep = new ReadValuesStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(valuesFile.get()));
steps.add(readValuesStep);
totalFields = Suppliers.memoize(() -> defaultValues.putAll(readValuesStep.get()));
} else {
totalFields = Suppliers.ofInstance(defaultValues);
}
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToOutputFile.getParent()));
steps.add(new GenerateBuildConfigStep(getProjectFilesystem(), getBuildTarget().getUnflavoredBuildTarget(), javaPackage, useConstantExpressions, totalFields, pathToOutputFile));
buildableContext.recordArtifact(pathToOutputFile);
return steps.build();
}
use of com.facebook.buck.step.fs.MakeCleanDirectoryStep in project buck by facebook.
the class NdkLibrary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
// .so files are written to the libs/ subdirectory of the output directory.
// All of them should be recorded via the BuildableContext.
Path binDirectory = buildArtifactsDirectory.resolve("libs");
steps.add(new RmStep(getProjectFilesystem(), makefile));
steps.add(new MkdirStep(getProjectFilesystem(), makefile.getParent()));
steps.add(new WriteFileStep(getProjectFilesystem(), makefileContents, makefile, false));
steps.add(new NdkBuildStep(getProjectFilesystem(), root, makefile, buildArtifactsDirectory, binDirectory, flags, macroExpander));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), genDirectory));
steps.add(CopyStep.forDirectory(getProjectFilesystem(), binDirectory, genDirectory, CopyStep.DirectoryMode.CONTENTS_ONLY));
buildableContext.recordArtifact(genDirectory);
// Some tools need to inspect .so files whose symbols haven't been stripped, so cache these too.
// However, the intermediate object files are huge and we have no interest in them, so filter
// them out.
steps.add(new AbstractExecutionStep("cache_unstripped_so") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
try {
Set<Path> unstrippedSharedObjs = getProjectFilesystem().getFilesUnderPath(buildArtifactsDirectory, input -> input.toString().endsWith(".so"));
for (Path path : unstrippedSharedObjs) {
buildableContext.recordArtifact(path);
}
} catch (IOException e) {
context.logError(e, "Failed to cache intermediate artifacts of %s.", getBuildTarget());
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
});
return steps.build();
}
Aggregations