use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class LuaBinaryIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
// We don't currently support windows.
assumeThat(Platform.detect(), Matchers.not(Platform.WINDOWS));
// Verify that a Lua interpreter is available on the system.
LuaBuckConfig fakeConfig = new LuaBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder());
Optional<Path> luaOptional = fakeConfig.getSystemLua();
assumeTrue(luaOptional.isPresent());
lua = luaOptional.get();
// Try to detect if a Lua devel package is available, which is needed to C/C++ support.
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(Platform.detect(), new FakeProjectFilesystem(), new CxxBuckConfig(FakeBuckConfig.builder().build()));
ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(ImmutableList.<String>builder().addAll(cxxPlatform.getCc().resolve(resolver).getCommandPrefix(new SourcePathResolver(new SourcePathRuleFinder(resolver)))).add("-includelua.h", "-E", "-").build()).setRedirectInput(ProcessBuilder.Redirect.PIPE).build();
ProcessExecutor executor = new DefaultProcessExecutor(Console.createNullConsole());
ProcessExecutor.LaunchedProcess launchedProcess = executor.launchProcess(params);
launchedProcess.getOutputStream().close();
int exitCode = executor.waitForLaunchedProcess(launchedProcess).getExitCode();
luaDevel = exitCode == 0;
if (starterType == LuaBinaryDescription.StarterType.NATIVE) {
assumeTrue("Lua devel package required for native starter", luaDevel);
}
// Setup the workspace.
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "lua_binary", tmp);
workspace.setUp();
workspace.writeContentsToPath(Joiner.on(System.lineSeparator()).join(ImmutableList.of("[lua]", " starter_type = " + starterType.toString().toLowerCase(), " native_link_strategy = " + nativeLinkStrategy.toString().toLowerCase(), "[cxx]", " sandbox_sources =" + sandboxSources)), ".buckconfig");
LuaBuckConfig config = getLuaBuckConfig();
assertThat(config.getStarterType(), Matchers.equalTo(Optional.of(starterType)));
assertThat(config.getNativeLinkStrategy(), Matchers.equalTo(nativeLinkStrategy));
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class Symbols method runObjdump.
private static void runObjdump(ProcessExecutor executor, Tool objdump, SourcePathResolver resolver, Path lib, ImmutableList<String> flags, LineProcessor<Void> lineProcessor) throws IOException, InterruptedException {
ImmutableList<String> args = ImmutableList.<String>builder().addAll(objdump.getCommandPrefix(resolver)).addAll(flags).add(lib.toString()).build();
ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(args).setRedirectError(ProcessBuilder.Redirect.INHERIT).build();
ProcessExecutor.LaunchedProcess p = executor.launchProcess(params);
BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
CharStreams.readLines(output, lineProcessor);
ProcessExecutor.Result result = executor.waitForLaunchedProcess(p);
if (result.getExitCode() != 0) {
throw new RuntimeException(result.getMessageForUnexpectedResult("Objdump"));
}
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class AbstractProvisioningProfileMetadata method fromProvisioningProfilePath.
public static ProvisioningProfileMetadata fromProvisioningProfilePath(ProcessExecutor executor, ImmutableList<String> readCommand, Path profilePath) throws IOException, InterruptedException {
Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT);
// Extract the XML from its signed message wrapper.
ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(readCommand).addCommand(profilePath.toString()).build();
ProcessExecutor.Result result;
result = executor.launchAndExecute(processExecutorParams, options, /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeOutHandler */
Optional.empty());
if (result.getExitCode() != 0) {
throw new IOException(result.getMessageForResult("Invalid provisioning profile: " + profilePath));
}
try {
NSDictionary plist = (NSDictionary) PropertyListParser.parse(result.getStdout().get().getBytes());
Date expirationDate = ((NSDate) plist.get("ExpirationDate")).getDate();
String uuid = ((NSString) plist.get("UUID")).getContent();
ImmutableSet.Builder<HashCode> certificateFingerprints = ImmutableSet.builder();
NSArray certificates = (NSArray) plist.get("DeveloperCertificates");
HashFunction hasher = Hashing.sha1();
if (certificates != null) {
for (NSObject item : certificates.getArray()) {
certificateFingerprints.add(hasher.hashBytes(((NSData) item).bytes()));
}
}
ImmutableMap.Builder<String, NSObject> builder = ImmutableMap.builder();
NSDictionary entitlements = ((NSDictionary) plist.get("Entitlements"));
for (String key : entitlements.keySet()) {
builder = builder.put(key, entitlements.objectForKey(key));
}
String appID = entitlements.get("application-identifier").toString();
ProvisioningProfileMetadata.Builder provisioningProfileMetadata = ProvisioningProfileMetadata.builder();
if (plist.get("Platform") != null) {
for (Object platform : (Object[]) plist.get("Platform").toJavaObject()) {
provisioningProfileMetadata.addPlatforms((String) platform);
}
}
return provisioningProfileMetadata.setAppID(ProvisioningProfileMetadata.splitAppID(appID)).setExpirationDate(expirationDate).setUUID(uuid).setProfilePath(profilePath).setEntitlements(builder.build()).setDeveloperCertificateFingerprints(certificateFingerprints.build()).build();
} catch (Exception e) {
throw new IllegalArgumentException("Malformed embedded plist: " + e);
}
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class CodeSignStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
if (dryRunResultsPath.isPresent()) {
try {
NSDictionary dryRunResult = new NSDictionary();
dryRunResult.put("relative-path-to-sign", dryRunResultsPath.get().getParent().relativize(pathToSign).toString());
dryRunResult.put("use-entitlements", pathToSigningEntitlements.isPresent());
dryRunResult.put("identity", getIdentityArg(codeSignIdentitySupplier.get()));
filesystem.writeContentsToPath(dryRunResult.toXMLPropertyList(), dryRunResultsPath.get());
return StepExecutionResult.SUCCESS;
} catch (IOException e) {
context.logError(e, "Failed when trying to write dry run results: %s", getDescription(context));
return StepExecutionResult.ERROR;
}
}
ProcessExecutorParams.Builder paramsBuilder = ProcessExecutorParams.builder();
if (codesignAllocatePath.isPresent()) {
ImmutableList<String> commandPrefix = codesignAllocatePath.get().getCommandPrefix(resolver);
paramsBuilder.setEnvironment(ImmutableMap.of("CODESIGN_ALLOCATE", Joiner.on(" ").join(commandPrefix)));
}
ImmutableList.Builder<String> commandBuilder = ImmutableList.builder();
commandBuilder.addAll(codesign.getCommandPrefix(resolver));
commandBuilder.add("--force", "--sign", getIdentityArg(codeSignIdentitySupplier.get()));
if (pathToSigningEntitlements.isPresent()) {
commandBuilder.add("--entitlements", pathToSigningEntitlements.get().toString());
}
commandBuilder.add(pathToSign.toString());
ProcessExecutorParams processExecutorParams = paramsBuilder.setCommand(commandBuilder.build()).setDirectory(filesystem.getRootPath()).build();
// Must 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.Result result;
try {
ProcessExecutor processExecutor = context.getProcessExecutor();
result = processExecutor.launchAndExecute(processExecutorParams, options, /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeOutHandler */
Optional.empty());
} catch (InterruptedException | IOException e) {
context.logError(e, "Could not execute codesign.");
return StepExecutionResult.ERROR;
}
if (result.getExitCode() != 0) {
return StepExecutionResult.of(result);
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.util.ProcessExecutor in project buck by facebook.
the class GoBuckConfig method getGoEnvFromTool.
private String getGoEnvFromTool(ProcessExecutor processExecutor, String env) {
Path goTool = getGoToolPath();
Optional<ImmutableMap<String, String>> goRootEnv = delegate.getPath(SECTION, "root").map(input -> ImmutableMap.of("GOROOT", input.toString()));
try {
ProcessExecutor.Result goToolResult = processExecutor.launchAndExecute(ProcessExecutorParams.builder().addCommand(goTool.toString(), "env", env).setEnvironment(goRootEnv).build(), EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT), /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeoutHandler */
Optional.empty());
if (goToolResult.getExitCode() == 0) {
return CharMatcher.whitespace().trimFrom(goToolResult.getStdout().get());
} else {
throw new HumanReadableException(goToolResult.getStderr().get());
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new HumanReadableException(e, "Could not run \"%s env %s\": %s", goTool, env, e.getMessage());
}
}
Aggregations