Search in sources :

Example 76 with Step

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

the class AndroidBuildConfig method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    Supplier<BuildConfigFields> totalFields;
    if (valuesFile.isPresent()) {
        final ReadValuesStep readValuesStep = new ReadValuesStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(valuesFile.get()));
        steps.add(readValuesStep);
        totalFields = Suppliers.memoize(() -> defaultValues.putAll(readValuesStep.get()));
    } else {
        totalFields = Suppliers.ofInstance(defaultValues);
    }
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToOutputFile.getParent()));
    steps.add(new GenerateBuildConfigStep(getProjectFilesystem(), getBuildTarget().getUnflavoredBuildTarget(), javaPackage, useConstantExpressions, totalFields, pathToOutputFile));
    buildableContext.recordArtifact(pathToOutputFile);
    return steps.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildConfigFields(com.facebook.buck.rules.coercer.BuildConfigFields)

Example 77 with Step

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

Example 78 with Step

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

the class PackageStringAssets method getBuildSteps.

// TODO(russellporter): Add an integration test for packaging string assets
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    if (filteredResourcesProvider.getResDirectories().isEmpty()) {
        // There is no zip file, but we still need to provide a consistent hash to
        // ComputeExopackageDepsAbi in this case.
        buildableContext.addMetadata(STRING_ASSETS_ZIP_HASH, Hashing.sha1().hashInt(0).toString());
        return ImmutableList.of();
    }
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    // We need to generate a zip file with the following dir structure:
    // /assets/strings/*.fbstr
    Path pathToBaseDir = getPathToStringAssetsDir();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToBaseDir));
    Path pathToDirContainingAssetsDir = pathToBaseDir.resolve("string_assets");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToDirContainingAssetsDir));
    final Path pathToStrings = pathToDirContainingAssetsDir.resolve("assets").resolve("strings");
    Function<String, Path> assetPathBuilder = locale -> pathToStrings.resolve(locale + STRING_ASSET_FILE_EXTENSION);
    Path pathToStringAssetsZip = getPathToStringAssetsZip();
    Path pathToAllLocalesStringAssetsZip = getPathToAllLocalesStringAssetsZip();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToStrings));
    steps.add(new CompileStringsStep(getProjectFilesystem(), filteredResourcesProvider.getStringFiles(), aaptPackageResources.getPathToRDotTxtDir(), assetPathBuilder));
    steps.add(new ZipStep(getProjectFilesystem(), pathToAllLocalesStringAssetsZip, ImmutableSet.of(), false, ZipCompressionLevel.MAX_COMPRESSION_LEVEL, pathToDirContainingAssetsDir));
    steps.add(new ZipStep(getProjectFilesystem(), pathToStringAssetsZip, locales.stream().map(assetPathBuilder::apply).collect(MoreCollectors.toImmutableSet()), false, ZipCompressionLevel.MAX_COMPRESSION_LEVEL, pathToDirContainingAssetsDir));
    steps.add(new RecordFileSha1Step(getProjectFilesystem(), pathToStringAssetsZip, STRING_ASSETS_ZIP_HASH, buildableContext));
    buildableContext.recordArtifact(pathToAllLocalesStringAssetsZip);
    buildableContext.recordArtifact(pathToStringAssetsZip);
    return steps.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildableContext(com.facebook.buck.rules.BuildableContext) SourcePath(com.facebook.buck.rules.SourcePath) Hashing(com.google.common.hash.Hashing) ZipCompressionLevel(com.facebook.buck.zip.ZipCompressionLevel) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) ImmutableList(com.google.common.collect.ImmutableList) ZipStep(com.facebook.buck.zip.ZipStep) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) BuildContext(com.facebook.buck.rules.BuildContext) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildTargets(com.facebook.buck.model.BuildTargets) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) ZipStep(com.facebook.buck.zip.ZipStep) ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ZipStep(com.facebook.buck.zip.ZipStep) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step)

Example 79 with Step

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

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

Aggregations

Step (com.facebook.buck.step.Step)143 ImmutableList (com.google.common.collect.ImmutableList)82 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)65 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)62 Test (org.junit.Test)54 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)49 MkdirStep (com.facebook.buck.step.fs.MkdirStep)44 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)42 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)41 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)40 BuildTarget (com.facebook.buck.model.BuildTarget)39 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)36 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)35 ExecutionContext (com.facebook.buck.step.ExecutionContext)34 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)31 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)30 BuildContext (com.facebook.buck.rules.BuildContext)25 RmStep (com.facebook.buck.step.fs.RmStep)24 CopyStep (com.facebook.buck.step.fs.CopyStep)23