Search in sources :

Example 6 with RmStep

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

the class ExportFile method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    SourcePathResolver resolver = context.getSourcePathResolver();
    // This file is copied rather than symlinked so that when it is included in an archive zip and
    // unpacked on another machine, it is an ordinary file in both scenarios.
    ImmutableList.Builder<Step> builder = ImmutableList.builder();
    if (mode == ExportFileDescription.Mode.COPY) {
        Path out = getCopiedPath();
        builder.add(new MkdirStep(getProjectFilesystem(), out.getParent()));
        builder.add(new RmStep(getProjectFilesystem(), out, RmStep.Mode.RECURSIVE));
        if (resolver.getFilesystem(src).isDirectory(resolver.getRelativePath(src))) {
            builder.add(CopyStep.forDirectory(getProjectFilesystem(), resolver.getAbsolutePath(src), out, CopyStep.DirectoryMode.CONTENTS_ONLY));
        } else {
            builder.add(CopyStep.forFile(getProjectFilesystem(), resolver.getAbsolutePath(src), out));
        }
        buildableContext.recordArtifact(out);
    }
    return builder.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) 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) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 7 with RmStep

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

the class AppleBundle method appendDsymRenameStepToMatchBundleName.

private void appendDsymRenameStepToMatchBundleName(ImmutableList.Builder<Step> stepsBuilder, BuildableContext buildableContext, SourcePathResolver pathResolver) {
    Preconditions.checkArgument(hasBinary && appleDsym.isPresent());
    // rename dSYM bundle to match bundle name
    Path dsymPath = pathResolver.getRelativePath(appleDsym.get().getSourcePathToOutput());
    Path dsymSourcePath = bundleRoot.getParent().resolve(dsymPath.getFileName());
    Path dsymDestinationPath = bundleRoot.getParent().resolve(bundleRoot.getFileName() + "." + AppleBundleExtension.DSYM.toFileExtension());
    stepsBuilder.add(new RmStep(getProjectFilesystem(), dsymDestinationPath, RmStep.Mode.RECURSIVE));
    stepsBuilder.add(new MoveStep(getProjectFilesystem(), dsymSourcePath, dsymDestinationPath));
    String dwarfFilename = AppleDsym.getDwarfFilenameForDsymTarget(appleDsym.get().getBuildTarget());
    // rename DWARF file inside dSYM bundle to match bundle name
    Path dwarfFolder = dsymDestinationPath.resolve(AppleDsym.DSYM_DWARF_FILE_FOLDER);
    Path dwarfSourcePath = dwarfFolder.resolve(dwarfFilename);
    Path dwarfDestinationPath = dwarfFolder.resolve(MorePaths.getNameWithoutExtension(bundleRoot));
    stepsBuilder.add(new MoveStep(getProjectFilesystem(), dwarfSourcePath, dwarfDestinationPath));
    // record dSYM so we can fetch it from cache
    buildableContext.recordArtifact(dsymDestinationPath);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) RmStep(com.facebook.buck.step.fs.RmStep) NSString(com.dd.plist.NSString) MoveStep(com.facebook.buck.step.fs.MoveStep)

Example 8 with RmStep

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

the class AppleDsym method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(dsymOutputPath);
    Path unstrippedBinaryPath = context.getSourcePathResolver().getAbsolutePath(unstrippedBinarySourcePath);
    Path dwarfFileFolder = dsymOutputPath.resolve(DSYM_DWARF_FILE_FOLDER);
    return ImmutableList.of(new RmStep(getProjectFilesystem(), dsymOutputPath, RmStep.Mode.RECURSIVE), new DsymStep(getProjectFilesystem(), dsymutil.getEnvironment(context.getSourcePathResolver()), dsymutil.getCommandPrefix(context.getSourcePathResolver()), unstrippedBinaryPath, dsymOutputPath), new MoveStep(getProjectFilesystem(), dwarfFileFolder.resolve(unstrippedBinaryPath.getFileName()), dwarfFileFolder.resolve(getDwarfFilenameForDsymTarget(getBuildTarget()))));
}
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) MoveStep(com.facebook.buck.step.fs.MoveStep)

Example 9 with RmStep

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

the class PythonPackagedBinary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    Path binPath = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
    // Make sure the parent directory exists.
    steps.add(new MkdirStep(getProjectFilesystem(), binPath.getParent()));
    // Delete any other pex that was there (when switching between pex styles).
    steps.add(new RmStep(getProjectFilesystem(), binPath, RmStep.Mode.RECURSIVE));
    Path workingDirectory = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__working_directory");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), workingDirectory));
    SourcePathResolver resolver = context.getSourcePathResolver();
    // Generate and return the PEX build step.
    steps.add(new PexStep(getProjectFilesystem(), builder.getEnvironment(resolver), ImmutableList.<String>builder().addAll(builder.getCommandPrefix(resolver)).addAll(buildArgs).build(), pythonEnvironment.getPythonPath(), pythonEnvironment.getPythonVersion(), workingDirectory, binPath, mainModule, resolver.getMappedPaths(getComponents().getModules()), resolver.getMappedPaths(getComponents().getResources()), resolver.getMappedPaths(getComponents().getNativeLibraries()), ImmutableSet.copyOf(resolver.getAllAbsolutePaths(getComponents().getPrebuiltLibraries())), preloadLibraries, getComponents().isZipSafe().orElse(true)));
    // Record the executable package for caching.
    buildableContext.recordArtifact(binPath);
    return steps.build();
}
Also used : 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) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 10 with RmStep

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

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