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;
}
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")));
}
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());
}
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();
}
Aggregations