Search in sources :

Example 16 with RmStep

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

the class JavaSourceJar method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    JavaPackageFinder packageFinder = context.getJavaPackageFinder();
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    steps.add(new RmStep(getProjectFilesystem(), output));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
    Set<Path> seenPackages = Sets.newHashSet();
    for (Path source : context.getSourcePathResolver().filterInputsToCompareToOutput(sources)) {
        Path packageFolder = packageFinder.findJavaPackageFolder(source);
        Path packageDir = temp.resolve(packageFolder);
        if (seenPackages.add(packageDir)) {
            steps.add(new MkdirStep(getProjectFilesystem(), packageDir));
        }
        steps.add(CopyStep.forFile(getProjectFilesystem(), source, packageDir.resolve(source.getFileName())));
    }
    steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.of(), /* junk paths */
    false, DEFAULT_COMPRESSION_LEVEL, temp));
    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) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) ZipStep(com.facebook.buck.zip.ZipStep) 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) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ZipStep(com.facebook.buck.zip.ZipStep)

Example 17 with RmStep

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

the class JsBundle method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    final SourcePathResolver sourcePathResolver = context.getSourcePathResolver();
    final SourcePath jsOutputDir = getSourcePathToOutput();
    final SourcePath sourceMapFile = getSourcePathToSourceMap();
    String jobArgs = Stream.concat(Stream.of("bundle", JsFlavors.bundleJobArgs(getBuildTarget().getFlavors()), JsUtil.resolveMapJoin(libraries, sourcePathResolver, p -> "--lib " + p), String.format("--sourcemap %s", sourcePathResolver.getAbsolutePath(sourceMapFile)), String.format("--out %s/%s", sourcePathResolver.getAbsolutePath(jsOutputDir), bundleName)), entryPoints.stream()).filter(s -> !s.isEmpty()).collect(Collectors.joining(" "));
    buildableContext.recordArtifact(sourcePathResolver.getRelativePath(jsOutputDir));
    buildableContext.recordArtifact(sourcePathResolver.getRelativePath(sourceMapFile));
    return ImmutableList.of(new RmStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(getOutputRoot())), new MkdirStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(jsOutputDir)), new MkdirStep(getProjectFilesystem(), sourcePathResolver.getAbsolutePath(sourceMapFile).getParent()), JsUtil.workerShellStep(worker, jobArgs, getBuildTarget(), sourcePathResolver, getProjectFilesystem()));
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Step(com.facebook.buck.step.Step) BuildableContext(com.facebook.buck.rules.BuildableContext) SourcePath(com.facebook.buck.rules.SourcePath) Collectors(java.util.stream.Collectors) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildContext(com.facebook.buck.rules.BuildContext) WorkerTool(com.facebook.buck.shell.WorkerTool) BuildTargets(com.facebook.buck.model.BuildTargets) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) RmStep(com.facebook.buck.step.fs.RmStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 18 with RmStep

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

the class JsLibrary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    final SourcePathResolver sourcePathResolver = context.getSourcePathResolver();
    final Path outputPath = sourcePathResolver.getAbsolutePath(getSourcePathToOutput());
    final String jobArgs = String.format("library %s --out %s %s", JsUtil.resolveMapJoin(libraryDependencies, sourcePathResolver, p -> "--lib " + p), outputPath, JsUtil.resolveMapJoin(sources, sourcePathResolver, Path::toString));
    return ImmutableList.of(new RmStep(getProjectFilesystem(), outputPath), JsUtil.workerShellStep(worker, jobArgs, getBuildTarget(), sourcePathResolver, getProjectFilesystem()));
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) RmStep(com.facebook.buck.step.fs.RmStep) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Step(com.facebook.buck.step.Step) BuildableContext(com.facebook.buck.rules.BuildableContext) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildContext(com.facebook.buck.rules.BuildContext) WorkerTool(com.facebook.buck.shell.WorkerTool) BuildTargets(com.facebook.buck.model.BuildTargets) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) RmStep(com.facebook.buck.step.fs.RmStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 19 with RmStep

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

the class DexProducedFromJavaLibrary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new RmStep(getProjectFilesystem(), getPathToDex()));
    // Make sure that the buck-out/gen/ directory exists for this.buildTarget.
    steps.add(new MkdirStep(getProjectFilesystem(), getPathToDex().getParent()));
    // If there are classes, run dx.
    final ImmutableSortedMap<String, HashCode> classNamesToHashes = javaLibrary.getClassNamesToHashes();
    final boolean hasClassesToDx = !classNamesToHashes.isEmpty();
    final Supplier<Integer> weightEstimate;
    @Nullable final DxStep dx;
    if (hasClassesToDx) {
        Path pathToOutputFile = context.getSourcePathResolver().getAbsolutePath(javaLibrarySourcePath);
        EstimateDexWeightStep estimate = new EstimateDexWeightStep(getProjectFilesystem(), pathToOutputFile);
        steps.add(estimate);
        weightEstimate = estimate;
        // To be conservative, use --force-jumbo for these intermediate .dex files so that they can be
        // merged into a final classes.dex that uses jumbo instructions.
        dx = new DxStep(getProjectFilesystem(), getPathToDex(), Collections.singleton(pathToOutputFile), EnumSet.of(DxStep.Option.USE_CUSTOM_DX_IF_AVAILABLE, DxStep.Option.RUN_IN_PROCESS, DxStep.Option.NO_OPTIMIZE, DxStep.Option.FORCE_JUMBO));
        steps.add(dx);
        // The `DxStep` delegates to android tools to build a ZIP with timestamps in it, making
        // the output non-deterministic.  So use an additional scrubbing step to zero these out.
        steps.add(new ZipScrubberStep(getProjectFilesystem(), getPathToDex()));
    } else {
        dx = null;
        weightEstimate = Suppliers.ofInstance(0);
    }
    // Run a step to record artifacts and metadata. The values recorded depend upon whether dx was
    // run.
    String stepName = hasClassesToDx ? "record_dx_success" : "record_empty_dx";
    AbstractExecutionStep recordArtifactAndMetadataStep = new AbstractExecutionStep(stepName) {

        @Override
        public StepExecutionResult execute(ExecutionContext context) throws IOException {
            if (hasClassesToDx) {
                buildableContext.recordArtifact(getPathToDex());
                @Nullable Collection<String> referencedResources = dx.getResourcesReferencedInCode();
                if (referencedResources != null) {
                    buildableContext.addMetadata(REFERENCED_RESOURCES, Ordering.natural().immutableSortedCopy(referencedResources));
                }
            }
            buildableContext.addMetadata(WEIGHT_ESTIMATE, String.valueOf(weightEstimate.get()));
            // Record the classnames to hashes map.
            buildableContext.addMetadata(CLASSNAMES_TO_HASHES, context.getObjectMapper().writeValueAsString(Maps.transformValues(classNamesToHashes, Object::toString)));
            return StepExecutionResult.SUCCESS;
        }
    };
    steps.add(recordArtifactAndMetadataStep);
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) 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) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) EstimateDexWeightStep(com.facebook.buck.dalvik.EstimateDexWeightStep) RmStep(com.facebook.buck.step.fs.RmStep) HashCode(com.google.common.hash.HashCode) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) ExecutionContext(com.facebook.buck.step.ExecutionContext) EstimateDexWeightStep(com.facebook.buck.dalvik.EstimateDexWeightStep) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) Nullable(javax.annotation.Nullable)

Example 20 with RmStep

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

the class HaskellPackageRule method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    // Setup the scratch dir.
    Path scratchDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
    // Setup the package DB directory.
    final Path packageDb = getPackageDb();
    steps.add(new RmStep(getProjectFilesystem(), packageDb, RmStep.Mode.RECURSIVE));
    buildableContext.recordArtifact(packageDb);
    // Create the registration file.
    Path registrationFile = scratchDir.resolve("registration-file");
    steps.add(getWriteRegistrationFileStep(context.getSourcePathResolver(), registrationFile, packageDb));
    // Build the the package DB.
    steps.add(new GhcPkgStep(context.getSourcePathResolver(), ImmutableList.of("init", packageDb.toString()), ImmutableMap.of()));
    steps.add(new GhcPkgStep(context.getSourcePathResolver(), ImmutableList.of("-v0", "register", "--package-conf=" + packageDb, "--no-expand-pkgroot", registrationFile.toString()), ImmutableMap.of("GHC_PACKAGE_PATH", depPackages.values().stream().map(input -> context.getSourcePathResolver().getAbsolutePath(input.getPackageDb()).toString()).collect(Collectors.joining(":")))));
    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) 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) ShellStep(com.facebook.buck.shell.ShellStep) 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