use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class BaseCompileToJarStepFactory method addPostprocessClassesCommands.
/**
* Adds a BashStep for each postprocessClasses command that runs the command followed by the
* outputDirectory of javac outputs.
*
* The expectation is that the command will inspect and update the directory by
* modifying, adding, and deleting the .class files in the directory.
*
* The outputDirectory should be a valid java root. I.e., if outputDirectory
* is buck-out/bin/java/abc/lib__abc__classes/, then a contained class abc.AbcModule
* should be at buck-out/bin/java/abc/lib__abc__classes/abc/AbcModule.class
*
* @param filesystem the project filesystem.
* @param postprocessClassesCommands the list of commands to post-process .class files.
* @param outputDirectory the directory that will contain all the javac output.
* @param declaredClasspathEntries the list of classpath entries.
* @param bootClasspath the compilation boot classpath.
*/
@VisibleForTesting
static ImmutableList<Step> addPostprocessClassesCommands(ProjectFilesystem filesystem, List<String> postprocessClassesCommands, Path outputDirectory, ImmutableSortedSet<Path> declaredClasspathEntries, Optional<String> bootClasspath) {
if (postprocessClassesCommands.isEmpty()) {
return ImmutableList.of();
}
ImmutableList.Builder<Step> commands = new ImmutableList.Builder<Step>();
ImmutableMap.Builder<String, String> envVarBuilder = ImmutableMap.builder();
envVarBuilder.put("COMPILATION_CLASSPATH", Joiner.on(':').join(Iterables.transform(declaredClasspathEntries, filesystem::resolve)));
if (bootClasspath.isPresent()) {
envVarBuilder.put("COMPILATION_BOOTCLASSPATH", bootClasspath.get());
}
ImmutableMap<String, String> envVars = envVarBuilder.build();
for (final String postprocessClassesCommand : postprocessClassesCommands) {
BashStep bashStep = new BashStep(filesystem.getRootPath(), postprocessClassesCommand + " " + outputDirectory) {
@Override
public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
return envVars;
}
};
commands.add(bashStep);
}
return commands.build();
}
use of com.facebook.buck.step.ExecutionContext 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.ExecutionContext 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.ExecutionContext in project buck by facebook.
the class RustCompileRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext buildContext, BuildableContext buildableContext) {
Path output = getOutput();
buildableContext.recordArtifact(output);
SourcePathResolver resolver = buildContext.getSourcePathResolver();
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir), new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(), srcs.stream().map(resolver::getRelativePath).collect(MoreCollectors.toImmutableList()), scratchDir), new MakeCleanDirectoryStep(getProjectFilesystem(), getOutputDir(getBuildTarget(), getProjectFilesystem())), new ShellStep(getProjectFilesystem().getRootPath()) {
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
ImmutableList<String> linkerCmd = linker.getCommandPrefix(resolver);
ImmutableList.Builder<String> cmd = ImmutableList.builder();
Path src = scratchDir.resolve(resolver.getRelativePath(rootModule));
cmd.addAll(compiler.getCommandPrefix(resolver)).addAll(executionContext.getAnsi().isAnsiTerminal() ? ImmutableList.of("--color=always") : ImmutableList.of()).add(String.format("-Clinker=%s", linkerCmd.get(0))).addAll(processLinkerArgs(linkerCmd.subList(1, linkerCmd.size()))).addAll(processLinkerArgs(Arg.stringify(linkerArgs, buildContext.getSourcePathResolver()))).addAll(Arg.stringify(args, buildContext.getSourcePathResolver())).add("-o", output.toString()).add(src.toString());
return cmd.build();
}
/*
* Make sure all stderr output from rustc is emitted, since its either a warning or an
* error. In general Rust code should have zero warnings, or all warnings as errors.
* Regardless, respect requests for silence.
*/
@Override
protected boolean shouldPrintStderr(Verbosity verbosity) {
return !verbosity.isSilent();
}
@Override
public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
return compiler.getEnvironment(buildContext.getSourcePathResolver());
}
@Override
public String getShortName() {
return "rust-build";
}
});
}
use of com.facebook.buck.step.ExecutionContext 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