Search in sources :

Example 51 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams 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"));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) BuildTarget(com.facebook.buck.model.BuildTarget) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 52 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams 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 53 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams 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 54 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams 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 55 with ProcessExecutorParams

use of com.facebook.buck.util.ProcessExecutorParams 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)

Aggregations

ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)72 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)32 FakeProcess (com.facebook.buck.util.FakeProcess)30 Test (org.junit.Test)30 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)21 ExecutionContext (com.facebook.buck.step.ExecutionContext)19 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)19 IOException (java.io.IOException)18 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)12 TestConsole (com.facebook.buck.testutil.TestConsole)12 Path (java.nio.file.Path)11 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)8 ListeningProcessExecutor (com.facebook.buck.util.ListeningProcessExecutor)6 HumanReadableException (com.facebook.buck.util.HumanReadableException)5 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 Matcher (java.util.regex.Matcher)4