Search in sources :

Example 11 with RmStep

use of com.facebook.buck.step.fs.RmStep 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 12 with RmStep

use of com.facebook.buck.step.fs.RmStep 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 13 with RmStep

use of com.facebook.buck.step.fs.RmStep 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)

Example 14 with RmStep

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

the class Zip method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    Path output = getOutput();
    Path scratchDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.zip.scratch");
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new RmStep(getProjectFilesystem(), output));
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
    SrcZipAwareFileBundler bundler = new SrcZipAwareFileBundler(getBuildTarget());
    bundler.copy(getProjectFilesystem(), context.getSourcePathResolver(), steps, scratchDir, sources);
    steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSortedSet.of(), /* junk paths */
    false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, scratchDir));
    buildableContext.recordArtifact(output);
    return steps.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) 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) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Example 15 with RmStep

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

the class CxxLink method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    Optional<Path> linkerMapPath = getLinkerMapPath();
    if (linkerMapPath.isPresent() && LinkerMapMode.isLinkerMapEnabledForBuildTarget(getBuildTarget())) {
        buildableContext.recordArtifact(linkerMapPath.get());
    }
    Path scratchDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s-tmp");
    Path argFilePath = getProjectFilesystem().getRootPath().resolve(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.argsfile"));
    Path fileListPath = getProjectFilesystem().getRootPath().resolve(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s__filelist.txt"));
    // Try to find all the cell roots used during the link.  This isn't technically correct since,
    // in theory not all inputs need to come from build rules, but it probably works in practice.
    // One way that we know would work is exposing every known cell root paths, since the only rules
    // that we built (and therefore need to scrub) will be in one of those roots.
    ImmutableSet.Builder<Path> cellRoots = ImmutableSet.builder();
    for (BuildRule dep : getDeps()) {
        cellRoots.add(dep.getProjectFilesystem().getRootPath());
    }
    return ImmutableList.of(new MkdirStep(getProjectFilesystem(), output.getParent()), new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir), new RmStep(getProjectFilesystem(), argFilePath), new RmStep(getProjectFilesystem(), fileListPath), CxxPrepareForLinkStep.create(argFilePath, fileListPath, linker.fileList(fileListPath), output, args, linker, getBuildTarget().getCellPath(), context.getSourcePathResolver()), new CxxLinkStep(getProjectFilesystem().getRootPath(), linker.getEnvironment(context.getSourcePathResolver()), linker.getCommandPrefix(context.getSourcePathResolver()), argFilePath, getProjectFilesystem().getRootPath().resolve(scratchDir)), new FileScrubberStep(getProjectFilesystem(), output, linker.getScrubbers(cellRoots.build())), new LogContentsOfFileStep(getProjectFilesystem().resolve(argFilePath), Level.FINEST), new RmStep(getProjectFilesystem(), argFilePath), new LogContentsOfFileStep(getProjectFilesystem().resolve(fileListPath), Level.FINEST), new RmStep(getProjectFilesystem(), fileListPath), new RmStep(getProjectFilesystem(), scratchDir, RmStep.Mode.RECURSIVE));
}
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) ImmutableSet(com.google.common.collect.ImmutableSet) MkdirStep(com.facebook.buck.step.fs.MkdirStep) LogContentsOfFileStep(com.facebook.buck.step.fs.LogContentsOfFileStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep)

Aggregations

RmStep (com.facebook.buck.step.fs.RmStep)24 Step (com.facebook.buck.step.Step)20 MkdirStep (com.facebook.buck.step.fs.MkdirStep)19 ImmutableList (com.google.common.collect.ImmutableList)18 SourcePath (com.facebook.buck.rules.SourcePath)17 Path (java.nio.file.Path)16 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)15 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)10 CopyStep (com.facebook.buck.step.fs.CopyStep)8 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)7 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)5 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)4 BuildContext (com.facebook.buck.rules.BuildContext)4 ExecutionContext (com.facebook.buck.step.ExecutionContext)4 ZipStep (com.facebook.buck.zip.ZipStep)4 BuildTargets (com.facebook.buck.model.BuildTargets)3 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)3 BuildableContext (com.facebook.buck.rules.BuildableContext)3 ShellStep (com.facebook.buck.shell.ShellStep)3