Search in sources :

Example 41 with MkdirStep

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

the class JavaSymbolsRule method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    Step mkdirStep = new MkdirStep(getProjectFilesystem(), outputPath.getParent());
    Step extractSymbolsStep = new AbstractExecutionStep("java-symbols") {

        @Override
        public StepExecutionResult execute(ExecutionContext context) throws IOException {
            Symbols symbols = symbolsFinder.extractSymbols();
            Symbols symbolsToSerialize;
            if (generatedSymbols.isEmpty()) {
                symbolsToSerialize = symbols;
            } else {
                symbolsToSerialize = new Symbols(Iterables.concat(symbols.provided, generatedSymbols), symbols.required, symbols.exported);
            }
            try (OutputStream output = getProjectFilesystem().newFileOutputStream(outputPath)) {
                context.getObjectMapper().writeValue(output, symbolsToSerialize);
            }
            return StepExecutionResult.SUCCESS;
        }
    };
    return ImmutableList.of(mkdirStep, extractSymbolsStep);
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) OutputStream(java.io.OutputStream) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep)

Example 42 with MkdirStep

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

the class SrcZipAwareFileBundler method copy.

public void copy(ProjectFilesystem filesystem, final SourcePathResolver resolver, ImmutableList.Builder<Step> steps, Path destinationDir, ImmutableSortedSet<SourcePath> toCopy) {
    Map<Path, Path> relativeMap = createRelativeMap(filesystem, resolver, toCopy);
    for (Map.Entry<Path, Path> pathEntry : relativeMap.entrySet()) {
        Path relativePath = pathEntry.getKey();
        Path absolutePath = Preconditions.checkNotNull(pathEntry.getValue());
        Path destination = destinationDir.resolve(relativePath);
        if (relativePath.toString().endsWith(Javac.SRC_ZIP) || relativePath.toString().endsWith(Javac.SRC_JAR)) {
            steps.add(new UnzipStep(filesystem, absolutePath, destination.getParent()));
            continue;
        }
        if (destination.getParent() != null) {
            steps.add(new MkdirStep(filesystem, destination.getParent()));
        }
        steps.add(CopyStep.forFile(filesystem, absolutePath, destination));
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 43 with MkdirStep

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

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

Example 45 with MkdirStep

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

the class CxxInferCapture method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList<String> frontendCommand = getFrontendCommand();
    buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
    Path inputRelativePath = context.getSourcePathResolver().getRelativePath(input);
    return ImmutableList.<Step>builder().add(new MkdirStep(getProjectFilesystem(), resultsDir)).add(new MkdirStep(getProjectFilesystem(), output.getParent())).add(new WriteArgFileStep(inputRelativePath)).add(new DefaultShellStep(getProjectFilesystem().getRootPath(), frontendCommand, ImmutableMap.of())).build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) DefaultShellStep(com.facebook.buck.shell.DefaultShellStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

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