Search in sources :

Example 21 with StepExecutionResult

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

the class OcamlBuildStep method executeMLBytecodeCompilation.

private StepExecutionResult executeMLBytecodeCompilation(ExecutionContext context, Path workingDirectory, ImmutableList<Path> sortedInput, ImmutableList.Builder<Path> linkerInputs) throws IOException, InterruptedException {
    MakeCleanDirectoryStep mkDir = new MakeCleanDirectoryStep(filesystem, ocamlContext.getCompileBytecodeOutputDir());
    StepExecutionResult mkDirExecutionResult = mkDir.execute(context);
    if (!mkDirExecutionResult.isSuccess()) {
        return mkDirExecutionResult;
    }
    for (Path inputOutput : sortedInput) {
        String inputFileName = inputOutput.getFileName().toString();
        String outputFileName = inputFileName.replaceFirst(OcamlCompilables.OCAML_ML_REGEX, OcamlCompilables.OCAML_CMO).replaceFirst(OcamlCompilables.OCAML_RE_REGEX, OcamlCompilables.OCAML_CMO).replaceFirst(OcamlCompilables.OCAML_MLI_REGEX, OcamlCompilables.OCAML_CMI).replaceFirst(OcamlCompilables.OCAML_REI_REGEX, OcamlCompilables.OCAML_CMI);
        Path outputPath = ocamlContext.getCompileBytecodeOutputDir().resolve(outputFileName);
        if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
            linkerInputs.add(outputPath);
        }
        final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
        true, /* excludeDeps */
        false);
        Step compileBytecodeStep = new OcamlMLCompileStep(workingDirectory, resolver, new OcamlMLCompileStep.Args(filesystem::resolve, cCompilerEnvironment, cCompiler, ocamlContext.getOcamlBytecodeCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, inputOutput, compileFlags));
        StepExecutionResult compileExecutionResult = compileBytecodeStep.execute(context);
        if (!compileExecutionResult.isSuccess()) {
            return compileExecutionResult;
        }
    }
    return StepExecutionResult.SUCCESS;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) Arg(com.facebook.buck.rules.args.Arg) StringArg(com.facebook.buck.rules.args.StringArg) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 22 with StepExecutionResult

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

the class JavacStepTest method failedCompileSendsStdoutAndStderrToConsole.

@Test
public void failedCompileSendsStdoutAndStderrToConsole() 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").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);
    // JavacStep itself writes stdout to the console on error; we expect the Build class to write
    // the stderr stream returned in the StepExecutionResult
    assertThat(result, equalTo(StepExecutionResult.of(1, Optional.of("javac stderr\n"))));
    assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("javac stdout\n")));
}
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 23 with StepExecutionResult

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

the class JavacStepTest method existingBootclasspathDirSucceeds.

@Test
public void existingBootclasspathDirSucceeds() 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("/this-totally-exists").build();
    ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> true, 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(0, "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.SUCCESS));
    assertThat(listener.getLogMessages(), empty());
}
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 24 with StepExecutionResult

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

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