Search in sources :

Example 16 with StepExecutionResult

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

the class JavacStepTest method missingBootclasspathDirFailsWithError.

@Test
public void missingBootclasspathDirFailsWithError() throws Exception {
    FakeJavac fakeJavac = new FakeJavac();
    BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").setBootclasspath("/no-such-dir").build();
    ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
    JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
    FakeProcess fakeJavacProcess = new FakeProcess(1, "javac stdout\n", "javac stderr\n");
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
    BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
    executionContext.getBuckEventBus().register(listener);
    StepExecutionResult result = step.execute(executionContext);
    assertThat(result, equalTo(StepExecutionResult.ERROR));
    assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("Invalid Java compiler options: Bootstrap classpath /no-such-dir " + "contains no valid entries")));
}
Also used : BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) FakeProcess(com.facebook.buck.util.FakeProcess) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Paths(java.nio.file.Paths) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 17 with StepExecutionResult

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

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

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

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

the class OcamlBuildStep method generateSources.

private StepExecutionResult generateSources(ExecutionContext context, Path workingDirectory) throws IOException, InterruptedException {
    MakeCleanDirectoryStep mkDir = new MakeCleanDirectoryStep(filesystem, ocamlContext.getGeneratedSourceDir());
    StepExecutionResult mkDirExecutionResult = mkDir.execute(context);
    if (!mkDirExecutionResult.isSuccess()) {
        return mkDirExecutionResult;
    }
    for (SourcePath yaccSource : ocamlContext.getYaccInput()) {
        SourcePath output = ocamlContext.getYaccOutput(ImmutableSet.of(yaccSource)).get(0);
        OcamlYaccStep yaccStep = new OcamlYaccStep(workingDirectory, resolver, new OcamlYaccStep.Args(ocamlContext.getYaccCompiler().get(), resolver.getAbsolutePath(output), resolver.getAbsolutePath(yaccSource)));
        StepExecutionResult yaccExecutionResult = yaccStep.execute(context);
        if (!yaccExecutionResult.isSuccess()) {
            return yaccExecutionResult;
        }
    }
    for (SourcePath lexSource : ocamlContext.getLexInput()) {
        SourcePath output = ocamlContext.getLexOutput(ImmutableSet.of(lexSource)).get(0);
        OcamlLexStep lexStep = new OcamlLexStep(workingDirectory, resolver, new OcamlLexStep.Args(ocamlContext.getLexCompiler().get(), resolver.getAbsolutePath(output), resolver.getAbsolutePath(lexSource)));
        StepExecutionResult lexExecutionResult = lexStep.execute(context);
        if (!lexExecutionResult.isSuccess()) {
            return lexExecutionResult;
        }
    }
    return StepExecutionResult.SUCCESS;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Aggregations

StepExecutionResult (com.facebook.buck.step.StepExecutionResult)24 ExecutionContext (com.facebook.buck.step.ExecutionContext)18 Path (java.nio.file.Path)15 SourcePath (com.facebook.buck.rules.SourcePath)13 AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)11 Step (com.facebook.buck.step.Step)11 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)11 ImmutableList (com.google.common.collect.ImmutableList)11 IOException (java.io.IOException)9 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)6 MkdirStep (com.facebook.buck.step.fs.MkdirStep)6 Test (org.junit.Test)6 BuckEventBusFactory (com.facebook.buck.event.BuckEventBusFactory)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)4 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)4 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)4 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)4 CopyStep (com.facebook.buck.step.fs.CopyStep)4 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)4