use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class OcamlBuildStep method executeCCompilation.
private StepExecutionResult executeCCompilation(ExecutionContext context, ImmutableList.Builder<Path> linkerInputs) throws IOException, InterruptedException {
ImmutableList.Builder<String> cCompileFlags = ImmutableList.builder();
cCompileFlags.addAll(ocamlContext.getCCompileFlags());
cCompileFlags.addAll(ocamlContext.getCommonCFlags());
CxxPreprocessorInput cxxPreprocessorInput = ocamlContext.getCxxPreprocessorInput();
for (SourcePath cSrc : ocamlContext.getCInput()) {
Path outputPath = ocamlContext.getCOutput(resolver.getAbsolutePath(cSrc));
linkerInputs.add(outputPath);
Step compileStep = new OcamlCCompileStep(resolver, filesystem.getRootPath(), new OcamlCCompileStep.Args(cCompilerEnvironment, cCompiler, ocamlContext.getOcamlCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, cSrc, cCompileFlags.build(), cxxPreprocessorInput.getIncludes()));
StepExecutionResult compileExecutionResult = compileStep.execute(context);
if (!compileExecutionResult.isSuccess()) {
return compileExecutionResult;
}
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class OcamlBuildStep method executeMLNativeCompilation.
private StepExecutionResult executeMLNativeCompilation(ExecutionContext context, Path workingDirectory, ImmutableList<Path> sortedInput, ImmutableList.Builder<Path> linkerInputs) throws IOException, InterruptedException {
MakeCleanDirectoryStep mkDir = new MakeCleanDirectoryStep(filesystem, ocamlContext.getCompileNativeOutputDir());
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_CMX).replaceFirst(OcamlCompilables.OCAML_RE_REGEX, OcamlCompilables.OCAML_CMX).replaceFirst(OcamlCompilables.OCAML_MLI_REGEX, OcamlCompilables.OCAML_CMI).replaceFirst(OcamlCompilables.OCAML_REI_REGEX, OcamlCompilables.OCAML_CMI);
Path outputPath = ocamlContext.getCompileNativeOutputDir().resolve(outputFileName);
if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
linkerInputs.add(outputPath);
}
final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
false, /* excludeDeps */
false);
Step compileStep = new OcamlMLCompileStep(workingDirectory, resolver, new OcamlMLCompileStep.Args(filesystem::resolve, cCompilerEnvironment, cCompiler, ocamlContext.getOcamlCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, inputOutput, compileFlags));
StepExecutionResult compileExecutionResult = compileStep.execute(context);
if (!compileExecutionResult.isSuccess()) {
return compileExecutionResult;
}
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class OcamlBuildStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
if (hasGeneratedSources) {
StepExecutionResult genExecutionResult = generateSources(context, filesystem.getRootPath());
if (!genExecutionResult.isSuccess()) {
return genExecutionResult;
}
}
StepExecutionResult depToolExecutionResult = depToolStep.execute(context);
if (!depToolExecutionResult.isSuccess()) {
return depToolExecutionResult;
}
// OCaml requires module A to be present in command line to ocamlopt or ocamlc before
// module B if B depends on A. In OCaml circular dependencies are prohibited, so all
// dependency relations among modules form DAG. Topologically sorting this graph satisfies the
// requirement.
//
// To get the DAG we launch ocamldep tool which provides the direct dependency information, like
// module A depends on modules B, C, D.
ImmutableList<Path> sortedInput = sortDependency(depToolStep.getStdout(), ocamlContext.getSourcePathResolver().getAllAbsolutePaths(ocamlContext.getMLInput()));
ImmutableList.Builder<Path> nativeLinkerInputs = ImmutableList.builder();
if (!bytecodeOnly) {
StepExecutionResult mlCompileNativeExecutionResult = executeMLNativeCompilation(context, filesystem.getRootPath(), sortedInput, nativeLinkerInputs);
if (!mlCompileNativeExecutionResult.isSuccess()) {
return mlCompileNativeExecutionResult;
}
}
ImmutableList.Builder<Path> bytecodeLinkerInputs = ImmutableList.builder();
StepExecutionResult mlCompileBytecodeExecutionResult = executeMLBytecodeCompilation(context, filesystem.getRootPath(), sortedInput, bytecodeLinkerInputs);
if (!mlCompileBytecodeExecutionResult.isSuccess()) {
return mlCompileBytecodeExecutionResult;
}
ImmutableList.Builder<Path> cLinkerInputs = ImmutableList.builder();
StepExecutionResult cCompileExecutionResult = executeCCompilation(context, cLinkerInputs);
if (!cCompileExecutionResult.isSuccess()) {
return cCompileExecutionResult;
}
ImmutableList<Path> cObjects = cLinkerInputs.build();
if (!bytecodeOnly) {
nativeLinkerInputs.addAll(cObjects);
StepExecutionResult nativeLinkExecutionResult = executeNativeLinking(context, nativeLinkerInputs.build());
if (!nativeLinkExecutionResult.isSuccess()) {
return nativeLinkExecutionResult;
}
}
bytecodeLinkerInputs.addAll(cObjects);
StepExecutionResult bytecodeLinkExecutionResult = executeBytecodeLinking(context, bytecodeLinkerInputs.build());
if (!bytecodeLinkExecutionResult.isSuccess()) {
return bytecodeLinkExecutionResult;
}
if (!ocamlContext.isLibrary()) {
Step debugLauncher = new OcamlDebugLauncherStep(filesystem, resolver, new OcamlDebugLauncherStep.Args(ocamlContext.getOcamlDebug().get(), ocamlContext.getBytecodeOutput(), ocamlContext.getOcamlInput(), ocamlContext.getBytecodeIncludeFlags()));
return debugLauncher.execute(context);
} else {
return StepExecutionResult.SUCCESS;
}
}
use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class RunShTestAndRecordResultStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
TestResultSummary summary;
if (context.getPlatform() == Platform.WINDOWS) {
// Ignore sh_test on Windows.
summary = new TestResultSummary(getShortName(), "sh_test", /* type */
ResultType.SUCCESS, /* duration*/
0, /* message */
"sh_test ignored on Windows", /* stacktrace */
null, /* stdout */
null, /* stderr */
null);
} else {
ShellStep test = new ShellStep(filesystem.getRootPath()) {
boolean timedOut = false;
@Override
public String getShortName() {
return pathToShellScript.toString();
}
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
return ImmutableList.<String>builder().add(pathToShellScript.toString()).addAll(args).build();
}
@Override
public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
return ImmutableMap.<String, String>builder().put("NO_BUCKD", "1").putAll(env).build();
}
@Override
protected boolean shouldPrintStderr(Verbosity verbosity) {
// Do not stream this output because we want to capture it.
return false;
}
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
StepExecutionResult executionResult = super.execute(context);
if (timedOut) {
throw new HumanReadableException("Timed out running test: " + testCaseName + ", with exitCode: " + executionResult.getExitCode());
}
return executionResult;
}
@Override
protected Optional<Consumer<Process>> getTimeoutHandler(final ExecutionContext context) {
return Optional.of(process -> timedOut = true);
}
@Override
protected Optional<Long> getTimeout() {
return testRuleTimeoutMs;
}
@Override
protected boolean shouldPrintStdout(Verbosity verbosity) {
// Do not stream this output because we want to capture it.
return false;
}
};
StepExecutionResult executionResult = test.execute(context);
// Write test result.
boolean isSuccess = executionResult.isSuccess();
summary = new TestResultSummary(getShortName(), "sh_test", /* type */
isSuccess ? ResultType.SUCCESS : ResultType.FAILURE, test.getDuration(), /* message */
null, /* stacktrace */
null, test.getStdout(), test.getStderr());
}
ObjectMapper mapper = context.getObjectMapper();
try (OutputStream outputStream = filesystem.newFileOutputStream(pathToTestResultFile)) {
mapper.writeValue(outputStream, summary);
}
// should be zero.
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.step.StepExecutionResult in project buck by facebook.
the class WriteStringTemplateRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(output);
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
steps.add(new StringTemplateStep(context.getSourcePathResolver().getAbsolutePath(template), getProjectFilesystem(), output, st -> {
for (Map.Entry<String, String> ent : values.entrySet()) {
st = st.add(ent.getKey(), ent.getValue());
}
return st;
}));
if (executable) {
steps.add(new AbstractExecutionStep("chmod +x") {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException {
MoreFiles.makeExecutable(getProjectFilesystem().resolve(output));
return StepExecutionResult.of(0, Optional.empty());
}
});
}
return steps.build();
}
Aggregations