Search in sources :

Example 41 with MakeCleanDirectoryStep

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();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildableContext(com.facebook.buck.rules.BuildableContext) SourcePath(com.facebook.buck.rules.SourcePath) Hashing(com.google.common.hash.Hashing) ZipCompressionLevel(com.facebook.buck.zip.ZipCompressionLevel) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) ImmutableList(com.google.common.collect.ImmutableList) ZipStep(com.facebook.buck.zip.ZipStep) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) BuildContext(com.facebook.buck.rules.BuildContext) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildTargets(com.facebook.buck.model.BuildTargets) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) ZipStep(com.facebook.buck.zip.ZipStep) ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ZipStep(com.facebook.buck.zip.ZipStep) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step)

Example 42 with MakeCleanDirectoryStep

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()));
    }
}
Also used : Path(java.nio.file.Path) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) TouchStep(com.facebook.buck.step.fs.TouchStep)

Example 43 with MakeCleanDirectoryStep

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();
}
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 44 with MakeCleanDirectoryStep

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);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildContext(com.facebook.buck.rules.BuildContext) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) BuildableContext(com.facebook.buck.rules.BuildableContext) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 45 with MakeCleanDirectoryStep

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();
}
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

MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)69 Path (java.nio.file.Path)57 SourcePath (com.facebook.buck.rules.SourcePath)53 Step (com.facebook.buck.step.Step)51 ImmutableList (com.google.common.collect.ImmutableList)47 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)42 MkdirStep (com.facebook.buck.step.fs.MkdirStep)25 ExecutionContext (com.facebook.buck.step.ExecutionContext)18 CopyStep (com.facebook.buck.step.fs.CopyStep)13 RmStep (com.facebook.buck.step.fs.RmStep)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 BuildTarget (com.facebook.buck.model.BuildTarget)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)9 BuildContext (com.facebook.buck.rules.BuildContext)9 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)9 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)8 ShellStep (com.facebook.buck.shell.ShellStep)8 AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)8