use of com.facebook.buck.step.Step 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.Step 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.Step in project buck by facebook.
the class LuaStandaloneBinary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
buildableContext.recordArtifact(output);
// Make sure the parent directory exists.
steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
// Delete any other pex that was there (when switching between pex styles).
steps.add(new RmStep(getProjectFilesystem(), output, RmStep.Mode.RECURSIVE));
SourcePathResolver resolver = context.getSourcePathResolver();
steps.add(new ShellStep(getProjectFilesystem().getRootPath()) {
@Override
protected Optional<String> getStdin(ExecutionContext context) {
try {
return Optional.of(context.getObjectMapper().writeValueAsString(ImmutableMap.of("modules", Maps.transformValues(components.getModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "pythonModules", Maps.transformValues(components.getPythonModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "nativeLibraries", Maps.transformValues(components.getNativeLibraries(), Functions.compose(Object::toString, resolver::getAbsolutePath)))));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
ImmutableList.Builder<String> command = ImmutableList.builder();
command.addAll(builder.getCommandPrefix(resolver));
command.addAll(builderArgs);
command.add("--entry-point", mainModule);
command.add("--interpreter");
if (starter.isPresent()) {
command.add(resolver.getAbsolutePath(starter.get()).toString());
} else {
command.add(lua.getCommandPrefix(resolver).get(0));
}
command.add(getProjectFilesystem().resolve(output).toString());
return command.build();
}
@Override
public String getShortName() {
return "lua_package";
}
});
return steps.build();
}
use of com.facebook.buck.step.Step in project buck by facebook.
the class ShTest method runTests.
@Override
public ImmutableList<Step> runTests(ExecutionContext executionContext, TestRunningOptions options, SourcePathResolver pathResolver, TestReportingCallback testReportingCallback) {
Step mkdirClean = new MakeCleanDirectoryStep(getProjectFilesystem(), getPathToTestOutputDirectory());
// Return a single command that runs an .sh file with no arguments.
Step runTest = new RunShTestAndRecordResultStep(getProjectFilesystem(), pathResolver.getAbsolutePath(test), Arg.stringify(args, pathResolver), Arg.stringify(env, pathResolver), testRuleTimeoutMs, getBuildTarget().getFullyQualifiedName(), getPathToTestOutputResult());
return ImmutableList.of(mkdirClean, runTest);
}
use of com.facebook.buck.step.Step in project buck by facebook.
the class ExportFile method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
SourcePathResolver resolver = context.getSourcePathResolver();
// This file is copied rather than symlinked so that when it is included in an archive zip and
// unpacked on another machine, it is an ordinary file in both scenarios.
ImmutableList.Builder<Step> builder = ImmutableList.builder();
if (mode == ExportFileDescription.Mode.COPY) {
Path out = getCopiedPath();
builder.add(new MkdirStep(getProjectFilesystem(), out.getParent()));
builder.add(new RmStep(getProjectFilesystem(), out, RmStep.Mode.RECURSIVE));
if (resolver.getFilesystem(src).isDirectory(resolver.getRelativePath(src))) {
builder.add(CopyStep.forDirectory(getProjectFilesystem(), resolver.getAbsolutePath(src), out, CopyStep.DirectoryMode.CONTENTS_ONLY));
} else {
builder.add(CopyStep.forFile(getProjectFilesystem(), resolver.getAbsolutePath(src), out));
}
buildableContext.recordArtifact(out);
}
return builder.build();
}
Aggregations