use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class CxxPreprocessAndCompileStep method executeCompilation.
private int executeCompilation(ExecutionContext context) throws Exception {
ProcessExecutorParams.Builder builder = makeSubprocessBuilder(context, ImmutableMap.of());
if (useArgfile) {
filesystem.writeLinesToPath(Iterables.transform(getArguments(context.getAnsi().isAnsiTerminal()), Escaper.ARGFILE_ESCAPER), getArgfile());
builder.setCommand(ImmutableList.<String>builder().addAll(getCommandPrefix()).add("@" + getArgfile()).build());
} else {
builder.setCommand(ImmutableList.<String>builder().addAll(getCommandPrefix()).addAll(getArguments(context.getAnsi().isAnsiTerminal())).build());
}
ProcessExecutorParams params = builder.build();
LOG.debug("Running command (pwd=%s): %s", params.getDirectory(), getDescription(context));
// Start the process.
ProcessExecutor executor = new DefaultProcessExecutor(Console.createNullConsole());
ProcessExecutor.LaunchedProcess process = executor.launchProcess(params);
// We buffer error messages in memory, as these are typically small.
ByteArrayOutputStream error = new ByteArrayOutputStream();
// Fire up managed threads to process the stdout and stderr lines.
int exitCode;
try {
try (LineProcessorRunnable errorProcessor = createErrorTransformerFactory(context).createTransformerThread(context, compiler.getErrorStream(process), error)) {
errorProcessor.start();
errorProcessor.waitFor();
} catch (Throwable thrown) {
executor.destroyLaunchedProcess(process);
throw thrown;
}
exitCode = executor.waitForLaunchedProcess(process).getExitCode();
} finally {
executor.destroyLaunchedProcess(process);
executor.waitForLaunchedProcess(process);
}
// If we generated any error output, print that to the console.
String err = new String(error.toByteArray());
if (!err.isEmpty()) {
context.getBuckEventBus().post(createConsoleEvent(context, preprocessorCommand.map(Optional::of).orElse(compilerCommand).get().supportsColorsInDiagnostics(), exitCode == 0 ? Level.WARNING : Level.SEVERE, err));
}
return exitCode;
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class JavacExecutionContextSerializer method deserialize.
@SuppressWarnings("unchecked")
public static JavacExecutionContext deserialize(Map<String, Object> data, JavacEventSink eventSink, PrintStream stdErr, ClassLoaderCache classLoaderCache, ObjectMapper objectMapper, Console console) {
Verbosity verbosity = Verbosity.valueOf((String) Preconditions.checkNotNull(data.get(VERBOSITY)));
CellPathResolver cellPathResolver = CellPathResolverSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CELL_PATH_RESOLVER)));
JavaPackageFinder javaPackageFinder = JavaPackageFinderSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(JAVA_PACKAGE_FINDER)));
ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get((String) Preconditions.checkNotNull(data.get(PROJECT_FILE_SYSTEM_ROOT))));
ClassUsageFileWriter classUsageFileWriter = ClassUsageFileWriterSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CLASS_USAGE_FILE_WRITER)));
ProcessExecutor processExecutor = ProcessExecutorSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(PROCESS_EXECUTOR)), console);
ImmutableList<Path> absolutePathsForInputs = ImmutableList.copyOf(((List<String>) Preconditions.checkNotNull(data.get(ABSOLUTE_PATHS_FOR_INPUTS))).stream().map(s -> Paths.get(s)).iterator());
Optional<DirectToJarOutputSettings> directToJarOutputSettings = Optional.empty();
if (data.containsKey(DIRECT_TO_JAR_SETTINGS)) {
directToJarOutputSettings = Optional.of(DirectToJarOutputSettingsSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(DIRECT_TO_JAR_SETTINGS))));
}
return JavacExecutionContext.of(eventSink, stdErr, classLoaderCache, objectMapper, verbosity, cellPathResolver, javaPackageFinder, projectFilesystem, classUsageFileWriter, (Map<String, String>) Preconditions.checkNotNull(data.get(ENVIRONMENT), "Missing environment when deserializing JavacExectionContext"), processExecutor, absolutePathsForInputs, directToJarOutputSettings);
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class BuiltinApplePackageIntegrationTest method packageSupportsFatBinaries.
@Test
public void packageSupportsFatBinaries() throws IOException, InterruptedException {
assumeTrue(Platform.detect() == Platform.MACOS);
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple_application_bundle_no_debug", tmp);
workspace.setUp();
BuildTarget packageTarget = BuildTargetFactory.newInstance("//:DemoAppPackage#iphonesimulator-i386,iphonesimulator-x86_64");
workspace.runBuckCommand("build", packageTarget.getFullyQualifiedName()).assertSuccess();
Unzip.extractZipFile(workspace.getPath(BuildTargets.getGenPath(filesystem, packageTarget, "%s.ipa")), workspace.getDestPath(), Unzip.ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES);
ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("lipo", "-info", workspace.getDestPath().resolve("Payload/DemoApp.app/DemoApp").toString())).build();
// Specify that stdout is expected, or else output may be wrapped in Ansi escape chars.
Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT, ProcessExecutor.Option.IS_SILENT);
ProcessExecutor.Result result = executor.launchAndExecute(processExecutorParams, options, /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeOutHandler */
Optional.empty());
assertEquals(result.getExitCode(), 0);
assertTrue(result.getStdout().isPresent());
String output = result.getStdout().get();
assertTrue(output.contains("i386"));
assertTrue(output.contains("x86_64"));
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class AppleNativeIntegrationTestUtils method discoverSystemSdkPaths.
private static ImmutableMap<AppleSdk, AppleSdkPaths> discoverSystemSdkPaths(BuckConfig buckConfig) {
AppleConfig appleConfig = new AppleConfig(buckConfig);
ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
return appleConfig.getAppleSdkPaths(executor);
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class ProvisioningProfileMetadataTest method testProvisioningProfileReadCommandOverride.
@Test
public void testProvisioningProfileReadCommandOverride() throws Exception {
ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
Path testdataDir = TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles");
ProvisioningProfileMetadata data = ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, ImmutableList.of(testdataDir.resolve("fake_read_command.sh").toString()), Paths.get("unused"));
assertThat(data.getAppID(), is(equalTo(new Pair<>("0000000000", "com.example.override"))));
}
Aggregations