Search in sources :

Example 11 with AbstractExecutionStep

use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.

the class JavaTest method getPostBuildSteps.

@Override
public ImmutableList<Step> getPostBuildSteps(BuildContext buildContext) {
    return ImmutableList.<Step>builder().add(new MkdirStep(getProjectFilesystem(), getClassPathFile().getParent())).add(new AbstractExecutionStep("write classpath file") {

        @Override
        public StepExecutionResult execute(ExecutionContext context) throws IOException {
            ImmutableSet<Path> classpathEntries = ImmutableSet.<Path>builder().addAll(compiledTestsLibrary.getTransitiveClasspaths().stream().map(buildContext.getSourcePathResolver()::getAbsolutePath).collect(MoreCollectors.toImmutableSet())).addAll(additionalClasspathEntries.stream().map(e -> e.isLeft() ? buildContext.getSourcePathResolver().getAbsolutePath(e.getLeft()) : e.getRight()).collect(MoreCollectors.toImmutableSet())).addAll(getBootClasspathEntries(context)).build();
            getProjectFilesystem().writeLinesToPath(Iterables.transform(classpathEntries, Object::toString), getClassPathFile());
            return StepExecutionResult.SUCCESS;
        }
    }).build();
}
Also used : Path(java.nio.file.Path) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Example 12 with AbstractExecutionStep

use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.

the class RelinkerRule method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
    final ImmutableList.Builder<Step> relinkerSteps = ImmutableList.builder();
    if (linker != null) {
        ImmutableList<Arg> args = ImmutableList.<Arg>builder().addAll(linkerArgs).add(StringArg.of("-Wl,--version-script=" + getRelativeVersionFilePath().toString())).build();
        relinkerSteps.addAll(new CxxLink(buildRuleParams.withAppendedFlavor(InternalFlavor.of("cxx-link")).withoutFlavor(LinkerMapMode.NO_LINKER_MAP.getFlavor()), linker, getLibFilePath(), args, cxxBuckConfig.getLinkScheduleInfo(), cxxBuckConfig.shouldCacheLinks()).getBuildSteps(context, buildableContext));
        buildableContext.recordArtifact(getRelativeVersionFilePath());
    }
    buildableContext.recordArtifact(getSymbolsNeededOutPath());
    return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), getScratchDirPath()), new AbstractExecutionStep("xdso-dce relinker") {

        @Override
        public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
            ImmutableSet<String> symbolsNeeded = readSymbolsNeeded();
            if (linker == null) {
                getProjectFilesystem().copyFile(getBaseLibPath(), getLibFilePath());
                buildableContext.recordArtifact(getLibFilePath());
            } else {
                writeVersionScript(context.getProcessExecutor(), symbolsNeeded);
                for (Step s : relinkerSteps.build()) {
                    StepExecutionResult executionResult = s.execute(context);
                    if (!executionResult.isSuccess()) {
                        return StepExecutionResult.ERROR;
                    }
                }
            }
            writeSymbols(getSymbolsNeededOutPath(), Sets.union(symbolsNeeded, getSymbols(context.getProcessExecutor(), getLibFilePath()).undefined));
            return StepExecutionResult.SUCCESS;
        }
    });
}
Also used : AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) IOException(java.io.IOException) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableSet(com.google.common.collect.ImmutableSet) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) CxxLink(com.facebook.buck.cxx.CxxLink)

Example 13 with AbstractExecutionStep

use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.

the class CopyNativeLibraries method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), getBinPath()));
    final Path pathToNativeLibs = getPathToNativeLibsDir();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToNativeLibs));
    final Path pathToNativeLibsAssets = getPathToNativeLibsAssetsDir();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToNativeLibsAssets));
    for (SourcePath nativeLibDir : nativeLibDirectories.asList().reverse()) {
        copyNativeLibrary(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(nativeLibDir), pathToNativeLibs, cpuFilters, steps);
    }
    addStepsForCopyingStrippedNativeLibrariesOrAssets(context.getSourcePathResolver(), getProjectFilesystem(), stripLibRules, pathToNativeLibs, steps);
    addStepsForCopyingStrippedNativeLibrariesOrAssets(context.getSourcePathResolver(), getProjectFilesystem(), stripLibAssetRules, pathToNativeLibsAssets, steps);
    final Path pathToMetadataTxt = getPathToMetadataTxt();
    steps.add(new AbstractExecutionStep("hash_native_libs") {

        @Override
        public StepExecutionResult execute(ExecutionContext context) {
            ProjectFilesystem filesystem = getProjectFilesystem();
            ImmutableList.Builder<String> metadataLines = ImmutableList.builder();
            try {
                for (Path nativeLib : filesystem.getFilesUnderPath(getPathToAllLibsDir())) {
                    Sha1HashCode filesha1 = filesystem.computeSha1(nativeLib);
                    Path relativePath = getPathToAllLibsDir().relativize(nativeLib);
                    metadataLines.add(String.format("%s %s", relativePath, filesha1));
                }
                filesystem.writeLinesToPath(metadataLines.build(), pathToMetadataTxt);
            } catch (IOException e) {
                context.logError(e, "There was an error hashing native libraries.");
                return StepExecutionResult.ERROR;
            }
            return StepExecutionResult.SUCCESS;
        }
    });
    buildableContext.recordArtifact(pathToNativeLibs);
    buildableContext.recordArtifact(pathToNativeLibsAssets);
    buildableContext.recordArtifact(pathToMetadataTxt);
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) 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) IOException(java.io.IOException) SourcePath(com.facebook.buck.rules.SourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 14 with AbstractExecutionStep

use of com.facebook.buck.step.AbstractExecutionStep 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 15 with AbstractExecutionStep

use of com.facebook.buck.step.AbstractExecutionStep in project buck by facebook.

the class ResourcesFilter method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    final ImmutableList.Builder<Path> filteredResDirectoriesBuilder = ImmutableList.builder();
    ImmutableSet<Path> whitelistedStringPaths = whitelistedStringDirs.stream().map(context.getSourcePathResolver()::getRelativePath).collect(MoreCollectors.toImmutableSet());
    ImmutableList<Path> resPaths = resDirectories.stream().map(context.getSourcePathResolver()::getRelativePath).collect(MoreCollectors.toImmutableList());
    final FilterResourcesStep filterResourcesStep = createFilterResourcesStep(resPaths, whitelistedStringPaths, locales, filteredResDirectoriesBuilder);
    steps.add(filterResourcesStep);
    final ImmutableList.Builder<Path> stringFilesBuilder = ImmutableList.builder();
    // The list of strings.xml files is only needed to build string assets
    if (resourceCompressionMode.isStoreStringsAsAssets()) {
        GetStringsFilesStep getStringsFilesStep = new GetStringsFilesStep(getProjectFilesystem(), resPaths, stringFilesBuilder);
        steps.add(getStringsFilesStep);
    }
    final ImmutableList<Path> filteredResDirectories = filteredResDirectoriesBuilder.build();
    for (Path outputResourceDir : filteredResDirectories) {
        buildableContext.recordArtifact(outputResourceDir);
    }
    steps.add(new AbstractExecutionStep("record_build_output") {

        @Override
        public StepExecutionResult execute(ExecutionContext context) {
            buildableContext.addMetadata(RES_DIRECTORIES_KEY, filteredResDirectories.stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
            buildableContext.addMetadata(STRING_FILES_KEY, stringFilesBuilder.build().stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
            return StepExecutionResult.SUCCESS;
        }
    });
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) ExecutionContext(com.facebook.buck.step.ExecutionContext)

Aggregations

AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)15 ExecutionContext (com.facebook.buck.step.ExecutionContext)15 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)11 Path (java.nio.file.Path)11 SourcePath (com.facebook.buck.rules.SourcePath)10 Step (com.facebook.buck.step.Step)10 ImmutableList (com.google.common.collect.ImmutableList)10 MkdirStep (com.facebook.buck.step.fs.MkdirStep)9 IOException (java.io.IOException)9 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)6 CopyStep (com.facebook.buck.step.fs.CopyStep)4 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)4 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)3 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 RmStep (com.facebook.buck.step.fs.RmStep)2 HashCode (com.google.common.hash.HashCode)2 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)2