Search in sources :

Example 36 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep 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());
}
Also used : MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractMap(java.util.AbstractMap) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SymlinkFilesIntoDirectoryStep(com.facebook.buck.shell.SymlinkFilesIntoDirectoryStep) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionContext(com.facebook.buck.step.ExecutionContext) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 37 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep 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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) RmStep(com.facebook.buck.step.fs.RmStep) LIBRARY(com.facebook.buck.rules.BuildableProperties.Kind.LIBRARY) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) SourcePath(com.facebook.buck.rules.SourcePath) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Function(com.google.common.base.Function) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildableProperties(com.facebook.buck.rules.BuildableProperties) BuildableContext(com.facebook.buck.rules.BuildableContext) Set(java.util.Set) IOException(java.io.IOException) BuildTarget(com.facebook.buck.model.BuildTarget) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) ANDROID(com.facebook.buck.rules.BuildableProperties.Kind.ANDROID) List(java.util.List) BuildContext(com.facebook.buck.rules.BuildContext) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) BuildTargets(com.facebook.buck.model.BuildTargets) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Set(java.util.Set) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) IOException(java.io.IOException) RmStep(com.facebook.buck.step.fs.RmStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 38 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.

the class AndroidManifest method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    // Clear out the old file, if it exists.
    commands.add(new RmStep(getProjectFilesystem(), pathToOutputFile));
    // Make sure the directory for the output file exists.
    commands.add(new MkdirStep(getProjectFilesystem(), pathToOutputFile.getParent()));
    commands.add(new GenerateManifestStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(skeletonFile), context.getSourcePathResolver().getAllAbsolutePaths(manifestFiles), context.getSourcePathResolver().getRelativePath(getSourcePathToOutput())));
    buildableContext.recordArtifact(pathToOutputFile);
    return commands.build();
}
Also used : RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Example 39 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep 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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 40 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep 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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ZipStep(com.facebook.buck.zip.ZipStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ZipStep(com.facebook.buck.zip.ZipStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ShellStep(com.facebook.buck.shell.ShellStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) RmStep(com.facebook.buck.step.fs.RmStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Aggregations

MkdirStep (com.facebook.buck.step.fs.MkdirStep)61 Path (java.nio.file.Path)44 SourcePath (com.facebook.buck.rules.SourcePath)43 Step (com.facebook.buck.step.Step)41 ImmutableList (com.google.common.collect.ImmutableList)38 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)34 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)27 RmStep (com.facebook.buck.step.fs.RmStep)20 CopyStep (com.facebook.buck.step.fs.CopyStep)14 ExecutionContext (com.facebook.buck.step.ExecutionContext)13 AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)12 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)10 ImmutableMap (com.google.common.collect.ImmutableMap)10 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 IOException (java.io.IOException)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)6 BuildTarget (com.facebook.buck.model.BuildTarget)5 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)5 PathSourcePath (com.facebook.buck.rules.PathSourcePath)5