Search in sources :

Example 26 with ProcessExecutor

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));
}
Also used : Path(java.nio.file.Path) FakeExecutableFinder(com.facebook.buck.io.FakeExecutableFinder) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Matchers.containsString(org.hamcrest.Matchers.containsString) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Before(org.junit.Before)

Example 27 with ProcessExecutor

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"));
    }
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 28 with ProcessExecutor

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);
    }
}
Also used : NSObject(com.dd.plist.NSObject) NSData(com.dd.plist.NSData) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) HashCode(com.google.common.hash.HashCode) ImmutableSet(com.google.common.collect.ImmutableSet) NSDate(com.dd.plist.NSDate) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) Date(java.util.Date) NSDate(com.dd.plist.NSDate) ImmutableMap(com.google.common.collect.ImmutableMap) IOException(java.io.IOException) HashFunction(com.google.common.hash.HashFunction) NSObject(com.dd.plist.NSObject)

Example 29 with ProcessExecutor

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;
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 30 with ProcessExecutor

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());
    }
}
Also used : Path(java.nio.file.Path) HumanReadableException(com.facebook.buck.util.HumanReadableException) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ProcessExecutor (com.facebook.buck.util.ProcessExecutor)38 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)20 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)18 TestConsole (com.facebook.buck.testutil.TestConsole)13 IOException (java.io.IOException)13 Path (java.nio.file.Path)12 Test (org.junit.Test)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4 Verbosity (com.facebook.buck.util.Verbosity)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)3 BuckConfig (com.facebook.buck.cli.BuckConfig)3 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStreamReader (java.io.InputStreamReader)3 PrintStream (java.io.PrintStream)3 NSDate (com.dd.plist.NSDate)2