Search in sources :

Example 1 with AppleConfig

use of com.facebook.buck.apple.AppleConfig in project buck by facebook.

the class InstallCommand method installAppleBundleForSimulator.

private InstallResult installAppleBundleForSimulator(CommandRunnerParams params, AppleBundle appleBundle, SourcePathResolver pathResolver, ProjectFilesystem projectFilesystem, ProcessExecutor processExecutor) throws IOException, InterruptedException {
    // TODO(bhamiltoncx): This should be shared with the build and passed down.
    AppleConfig appleConfig = new AppleConfig(params.getBuckConfig());
    Optional<Path> xcodeDeveloperPath = appleConfig.getAppleDeveloperDirectorySupplier(processExecutor).get();
    if (!xcodeDeveloperPath.isPresent()) {
        params.getConsole().printBuildFailure(String.format("Cannot install %s (Xcode not found)", appleBundle.getFullyQualifiedName()));
        return FAILURE;
    }
    UnixUserIdFetcher userIdFetcher = new UnixUserIdFetcher();
    AppleCoreSimulatorServiceController appleCoreSimulatorServiceController = new AppleCoreSimulatorServiceController(processExecutor);
    Optional<Path> coreSimulatorServicePath = appleCoreSimulatorServiceController.getCoreSimulatorServicePath(userIdFetcher);
    boolean shouldWaitForSimulatorsToShutdown = false;
    if (!coreSimulatorServicePath.isPresent() || !coreSimulatorServicePath.get().toRealPath().startsWith(xcodeDeveloperPath.get().toRealPath())) {
        LOG.warn("Core simulator service path %s does not match developer directory %s, " + "killing all simulators.", coreSimulatorServicePath, xcodeDeveloperPath.get());
        if (!appleCoreSimulatorServiceController.killSimulatorProcesses()) {
            params.getConsole().printBuildFailure("Could not kill running simulator processes.");
            return FAILURE;
        }
        shouldWaitForSimulatorsToShutdown = true;
    }
    Path simctlPath = xcodeDeveloperPath.get().resolve("usr/bin/simctl");
    Optional<AppleSimulator> appleSimulator = getAppleSimulatorForBundle(appleBundle, processExecutor, simctlPath);
    if (!appleSimulator.isPresent()) {
        params.getConsole().printBuildFailure(String.format("Cannot install %s (no appropriate simulator found)", appleBundle.getFullyQualifiedName()));
        return FAILURE;
    }
    Path iosSimulatorPath = null;
    Path xcodeApplicationsPath = xcodeDeveloperPath.get().resolve("Applications");
    for (String simulatorApp : APPLE_SIMULATOR_APPS) {
        Path resolvedSimulatorPath = xcodeApplicationsPath.resolve(simulatorApp);
        if (projectFilesystem.isDirectory(resolvedSimulatorPath)) {
            iosSimulatorPath = resolvedSimulatorPath;
            break;
        }
    }
    if (iosSimulatorPath == null) {
        params.getConsole().printBuildFailure(String.format("Cannot install %s (could not find simulator under %s, checked %s)", appleBundle.getFullyQualifiedName(), xcodeApplicationsPath, APPLE_SIMULATOR_APPS));
        return FAILURE;
    }
    AppleSimulatorController appleSimulatorController = new AppleSimulatorController(processExecutor, simctlPath, iosSimulatorPath);
    if (!appleSimulatorController.canStartSimulator(appleSimulator.get().getUdid())) {
        LOG.warn("Cannot start simulator %s, killing simulators and trying again.");
        if (!appleCoreSimulatorServiceController.killSimulatorProcesses()) {
            params.getConsole().printBuildFailure("Could not kill running simulator processes.");
            return FAILURE;
        }
        shouldWaitForSimulatorsToShutdown = true;
        // Killing the simulator can cause the UDIDs to change, so we need to fetch them again.
        appleSimulator = getAppleSimulatorForBundle(appleBundle, processExecutor, simctlPath);
        if (!appleSimulator.isPresent()) {
            params.getConsole().printBuildFailure(String.format("Cannot install %s (no appropriate simulator found)", appleBundle.getFullyQualifiedName()));
            return FAILURE;
        }
    }
    long remainingMillis = APPLE_SIMULATOR_WAIT_MILLIS;
    if (shouldWaitForSimulatorsToShutdown) {
        Optional<Long> shutdownMillis = appleSimulatorController.waitForSimulatorsToShutdown(remainingMillis);
        if (!shutdownMillis.isPresent()) {
            params.getConsole().printBuildFailure(String.format("Cannot install %s (simulators did not shut down within %d ms).", appleBundle.getFullyQualifiedName(), APPLE_SIMULATOR_WAIT_MILLIS));
            return FAILURE;
        }
        LOG.debug("Simulators shut down in %d millis.", shutdownMillis.get());
        remainingMillis -= shutdownMillis.get();
    }
    LOG.debug("Starting up simulator %s", appleSimulator.get());
    Optional<Long> startMillis = appleSimulatorController.startSimulator(appleSimulator.get().getUdid(), remainingMillis);
    if (!startMillis.isPresent()) {
        params.getConsole().printBuildFailure(String.format("Cannot install %s (could not start simulator %s within %d ms)", appleBundle.getFullyQualifiedName(), appleSimulator.get().getName(), APPLE_SIMULATOR_WAIT_MILLIS));
        return FAILURE;
    }
    LOG.debug("Simulator started in %d ms. Installing Apple bundle %s in simulator %s", startMillis.get(), appleBundle, appleSimulator.get());
    if (!appleSimulatorController.installBundleInSimulator(appleSimulator.get().getUdid(), pathResolver.getAbsolutePath(Preconditions.checkNotNull(appleBundle.getSourcePathToOutput())))) {
        params.getConsole().printBuildFailure(String.format("Cannot install %s (could not install bundle %s in simulator %s)", appleBundle.getFullyQualifiedName(), pathResolver.getAbsolutePath(appleBundle.getSourcePathToOutput()), appleSimulator.get().getName()));
        return FAILURE;
    }
    if (run) {
        return launchAppleBundle(params, appleBundle, appleSimulatorController, projectFilesystem, appleSimulator.get());
    } else {
        params.getBuckEventBus().post(ConsoleEvent.info(params.getConsole().getAnsi().asHighlightedSuccessText("Successfully installed %s. (Use `buck install -r %s` to run.)"), getArguments().get(0), getArguments().get(0)));
        return InstallResult.builder().setExitCode(0).build();
    }
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) AppleSimulator(com.facebook.buck.apple.simulator.AppleSimulator) UnixUserIdFetcher(com.facebook.buck.util.UnixUserIdFetcher) AppleSimulatorController(com.facebook.buck.apple.simulator.AppleSimulatorController) AppleCoreSimulatorServiceController(com.facebook.buck.apple.simulator.AppleCoreSimulatorServiceController)

Example 2 with AppleConfig

use of com.facebook.buck.apple.AppleConfig in project buck by facebook.

the class ProjectCommand method generateWorkspacesForTargets.

@VisibleForTesting
static ImmutableSet<BuildTarget> generateWorkspacesForTargets(final CommandRunnerParams params, final TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet, ImmutableSet<ProjectGenerator.Option> options, ImmutableList<String> buildWithBuckFlags, Optional<ImmutableSet<UnflavoredBuildTarget>> focusModules, Map<Path, ProjectGenerator> projectGenerators, boolean combinedProject, boolean buildWithBuck) throws IOException, InterruptedException {
    ImmutableSet<BuildTarget> targets;
    if (passedInTargetsSet.isEmpty()) {
        targets = targetGraphAndTargets.getProjectRoots().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet());
    } else {
        targets = passedInTargetsSet;
    }
    LOG.debug("Generating workspace for config targets %s", targets);
    ImmutableSet.Builder<BuildTarget> requiredBuildTargetsBuilder = ImmutableSet.builder();
    for (final BuildTarget inputTarget : targets) {
        TargetNode<?, ?> inputNode = targetGraphAndTargets.getTargetGraph().get(inputTarget);
        XcodeWorkspaceConfigDescription.Arg workspaceArgs;
        if (inputNode.getDescription() instanceof XcodeWorkspaceConfigDescription) {
            TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> castedWorkspaceNode = castToXcodeWorkspaceTargetNode(inputNode);
            workspaceArgs = castedWorkspaceNode.getConstructorArg();
        } else if (canGenerateImplicitWorkspaceForDescription(inputNode.getDescription())) {
            workspaceArgs = createImplicitWorkspaceArgs(inputNode);
        } else {
            throw new HumanReadableException("%s must be a xcode_workspace_config, apple_binary, apple_bundle, or apple_library", inputNode);
        }
        BuckConfig buckConfig = params.getBuckConfig();
        AppleConfig appleConfig = new AppleConfig(buckConfig);
        HalideBuckConfig halideBuckConfig = new HalideBuckConfig(buckConfig);
        CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(buckConfig);
        SwiftBuckConfig swiftBuckConfig = new SwiftBuckConfig(buckConfig);
        CxxPlatform defaultCxxPlatform = params.getCell().getKnownBuildRuleTypes().getDefaultCxxPlatforms();
        WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(params.getCell(), targetGraphAndTargets.getTargetGraph(), workspaceArgs, inputTarget, options, combinedProject, buildWithBuck, buildWithBuckFlags, focusModules, !appleConfig.getXcodeDisableParallelizeBuild(), new ExecutableFinder(), params.getEnvironment(), params.getCell().getKnownBuildRuleTypes().getCxxPlatforms(), defaultCxxPlatform, params.getBuckConfig().getView(ParserConfig.class).getBuildFileName(), input -> ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph().getSubgraph(ImmutableSet.of(input))).getResolver(), params.getBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
        ListeningExecutorService executorService = params.getExecutors().get(ExecutorPool.PROJECT);
        Preconditions.checkNotNull(executorService, "CommandRunnerParams does not have executor for PROJECT pool");
        generator.generateWorkspaceAndDependentProjects(projectGenerators, executorService);
        ImmutableSet<BuildTarget> requiredBuildTargetsForWorkspace = generator.getRequiredBuildTargets();
        LOG.debug("Required build targets for workspace %s: %s", inputTarget, requiredBuildTargetsForWorkspace);
        requiredBuildTargetsBuilder.addAll(requiredBuildTargetsForWorkspace);
    }
    return requiredBuildTargetsBuilder.build();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) TargetNode(com.facebook.buck.rules.TargetNode) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) WorkspaceAndProjectGenerator(com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableSet(com.google.common.collect.ImmutableSet) XcodeWorkspaceConfigDescription(com.facebook.buck.apple.XcodeWorkspaceConfigDescription) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with AppleConfig

use of com.facebook.buck.apple.AppleConfig in project buck by facebook.

the class ProjectGeneratorTest method setUp.

@Before
public void setUp() throws InterruptedException, IOException {
    assumeTrue(Platform.detect() == Platform.MACOS || Platform.detect() == Platform.LINUX);
    clock = new SettableFakeClock(0, 0);
    fakeProjectFilesystem = new FakeProjectFilesystem(clock);
    projectCell = (new TestCellBuilder()).setFilesystem(fakeProjectFilesystem).build();
    projectFilesystem = projectCell.getFilesystem();
    rootPath = projectFilesystem.getRootPath();
    // Add files and directories used to test resources.
    projectFilesystem.createParentDirs(Paths.get("foodir", "foo.png"));
    projectFilesystem.writeContentsToPath("", Paths.get("foodir", "foo.png"));
    projectFilesystem.writeContentsToPath("", Paths.get("bar.png"));
    fakeProjectFilesystem.touch(Paths.get("Base.lproj", "Bar.storyboard"));
    halideBuckConfig = HalideLibraryBuilder.createDefaultHalideConfig(fakeProjectFilesystem);
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("cflags", "-Wno-deprecated -Wno-conversion", "cxxflags", "-Wundeclared-selector -Wno-objc-designated-initializers"), "apple", ImmutableMap.of("force_dsym_mode_in_build_with_buck", "false"), "swift", ImmutableMap.of("version", "1.23"));
    BuckConfig config = FakeBuckConfig.builder().setSections(sections).build();
    cxxBuckConfig = new CxxBuckConfig(config);
    appleConfig = new AppleConfig(config);
    swiftBuckConfig = new SwiftBuckConfig(config);
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ReactNativeBuckConfig(com.facebook.buck.js.ReactNativeBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Before(org.junit.Before)

Example 4 with AppleConfig

use of com.facebook.buck.apple.AppleConfig in project buck by facebook.

the class InstallCommand method getInstallHelperTargets.

private ImmutableSet<String> getInstallHelperTargets(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildTargetException, BuildFileParseException {
    ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
    ImmutableSet.Builder<String> installHelperTargets = ImmutableSet.builder();
    for (int index = 0; index < getArguments().size(); index++) {
        // TODO(ryu2): Cache argument parsing
        TargetNodeSpec spec = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()).get(index);
        BuildTarget target = FluentIterable.from(params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(spec), SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode())).transformAndConcat(Functions.identity()).first().get();
        TargetNode<?, ?> node = params.getParser().getTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, target);
        if (node != null && Description.getBuildRuleType(node.getDescription()).equals(Description.getBuildRuleType(AppleBundleDescription.class))) {
            for (Flavor flavor : node.getBuildTarget().getFlavors()) {
                if (ApplePlatform.needsInstallHelper(flavor.getName())) {
                    AppleConfig appleConfig = new AppleConfig(params.getBuckConfig());
                    Optional<BuildTarget> deviceHelperTarget = appleConfig.getAppleDeviceHelperTarget();
                    Optionals.addIfPresent(Optionals.bind(deviceHelperTarget, input -> !input.toString().isEmpty() ? Optional.of(input.toString()) : Optional.empty()), installHelperTargets);
                }
            }
        }
    }
    return installHelperTargets.build();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) AppleSimulatorDiscovery(com.facebook.buck.apple.simulator.AppleSimulatorDiscovery) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AdbOptions(com.facebook.buck.step.AdbOptions) AdbHelper(com.facebook.buck.android.AdbHelper) InstallEvent(com.facebook.buck.event.InstallEvent) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AppleConfig(com.facebook.buck.apple.AppleConfig) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FluentIterable(com.google.common.collect.FluentIterable) ApplePlatform(com.facebook.buck.apple.ApplePlatform) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Locale(java.util.Locale) AppleCoreSimulatorServiceController(com.facebook.buck.apple.simulator.AppleCoreSimulatorServiceController) Path(java.nio.file.Path) Optionals(com.facebook.buck.util.Optionals) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AppleSimulator(com.facebook.buck.apple.simulator.AppleSimulator) BuildTargetException(com.facebook.buck.model.BuildTargetException) Option(org.kohsuke.args4j.Option) AppleInfoPlistParsing(com.facebook.buck.apple.AppleInfoPlistParsing) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) List(java.util.List) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription) AppleSimulatorController(com.facebook.buck.apple.simulator.AppleSimulatorController) UninstallOptions(com.facebook.buck.cli.UninstallCommand.UninstallOptions) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Description(com.facebook.buck.rules.Description) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Assertions(com.facebook.infer.annotation.Assertions) Build(com.facebook.buck.command.Build) MoreExceptions(com.facebook.buck.util.MoreExceptions) SourcePath(com.facebook.buck.rules.SourcePath) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) Lists(com.google.common.collect.Lists) AppleDeviceHelper(com.facebook.buck.apple.device.AppleDeviceHelper) ParserConfig(com.facebook.buck.parser.ParserConfig) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Nullable(javax.annotation.Nullable) Logger(com.facebook.buck.log.Logger) Functions(com.google.common.base.Functions) UnixUserIdFetcher(com.facebook.buck.util.UnixUserIdFetcher) TargetNode(com.facebook.buck.rules.TargetNode) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) AppleBundle(com.facebook.buck.apple.AppleBundle) HasInstallableApk(com.facebook.buck.android.HasInstallableApk) SpeculativeParsing(com.facebook.buck.parser.SpeculativeParsing) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InputStream(java.io.InputStream) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) Flavor(com.facebook.buck.model.Flavor) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 5 with AppleConfig

use of com.facebook.buck.apple.AppleConfig in project buck by facebook.

the class InstallCommand method installAppleBundleForDevice.

private InstallResult installAppleBundleForDevice(CommandRunnerParams params, AppleBundle appleBundle, ProjectFilesystem projectFilesystem, ProcessExecutor processExecutor, SourcePathResolver pathResolver) throws IOException, NoSuchBuildTargetException {
    // TODO(bhamiltoncx): This should be shared with the build and passed down.
    AppleConfig appleConfig = new AppleConfig(params.getBuckConfig());
    final Path helperPath;
    Optional<BuildTarget> helperTarget = appleConfig.getAppleDeviceHelperTarget();
    if (helperTarget.isPresent()) {
        BuildRuleResolver resolver = super.getBuild().getRuleResolver();
        BuildRule buildRule = resolver.requireRule(helperTarget.get());
        if (buildRule == null) {
            params.getConsole().printBuildFailure(String.format("Cannot install %s (could not resolve build rule for device helper target %s)", appleBundle.getFullyQualifiedName(), helperTarget.get().getBaseName()));
            return FAILURE;
        }
        SourcePath buildRuleOutputPath = buildRule.getSourcePathToOutput();
        if (buildRuleOutputPath == null) {
            params.getConsole().printBuildFailure(String.format("Cannot install %s (device helper target %s does not specify an output)", appleBundle.getFullyQualifiedName(), helperTarget.get().getBaseName()));
            return FAILURE;
        }
        helperPath = pathResolver.getAbsolutePath(buildRuleOutputPath);
    } else {
        Optional<Path> helperOverridePath = appleConfig.getAppleDeviceHelperAbsolutePath();
        if (helperOverridePath.isPresent()) {
            helperPath = helperOverridePath.get();
        } else {
            params.getConsole().printBuildFailure(String.format("Cannot install %s (could not find path to device install helper tool)", appleBundle.getFullyQualifiedName()));
            return FAILURE;
        }
    }
    AppleDeviceHelper helper = new AppleDeviceHelper(processExecutor, helperPath);
    ImmutableMap<String, String> connectedDevices = helper.getConnectedDevices();
    if (connectedDevices.size() == 0) {
        params.getConsole().printBuildFailure(String.format("Cannot install %s (no connected devices found)", appleBundle.getFullyQualifiedName()));
        return FAILURE;
    }
    String selectedUdid = null;
    if (targetDeviceOptions().getSerialNumber().isPresent()) {
        String udidPrefix = Assertions.assertNotNull(targetDeviceOptions().getSerialNumber().get()).toLowerCase();
        for (String udid : connectedDevices.keySet()) {
            if (udid.startsWith(udidPrefix)) {
                selectedUdid = udid;
                break;
            }
        }
        if (selectedUdid == null) {
            params.getConsole().printBuildFailure(String.format("Cannot install %s to the device %s (no connected devices with that UDID/prefix)", appleBundle.getFullyQualifiedName(), udidPrefix));
            return FAILURE;
        }
    } else {
        if (connectedDevices.size() > 1) {
            LOG.warn("More than one connected device found, and no device ID specified.  A device will be" + " arbitrarily picked.");
        }
        selectedUdid = connectedDevices.keySet().iterator().next();
    }
    LOG.info("Installing " + appleBundle.getFullyQualifiedName() + " to device " + selectedUdid + " (" + connectedDevices.get(selectedUdid) + ")");
    if (helper.installBundleOnDevice(selectedUdid, pathResolver.getAbsolutePath(Preconditions.checkNotNull(appleBundle.getSourcePathToOutput())))) {
        params.getConsole().printSuccess("Installed " + appleBundle.getFullyQualifiedName() + " to device " + selectedUdid + " (" + connectedDevices.get(selectedUdid) + ")");
        if (run) {
            Optional<String> appleBundleId;
            try (InputStream bundlePlistStream = projectFilesystem.getInputStreamForRelativePath(appleBundle.getInfoPlistPath())) {
                appleBundleId = AppleInfoPlistParsing.getBundleIdFromPlistStream(bundlePlistStream);
            }
            if (!appleBundleId.isPresent()) {
                params.getConsole().printBuildFailure(String.format("Cannot run %s (could not get bundle ID from %s)", appleBundle.getFullyQualifiedName(), appleBundle.getInfoPlistPath()));
                return FAILURE;
            }
            if (waitForDebugger) {
                LOG.warn(WAIT_FOR_DEBUGGER_LONG_ARG + " not yet implemented for devices.");
            }
            if (helper.runBundleOnDevice(selectedUdid, appleBundleId.get())) {
                return InstallResult.builder().setExitCode(0).build();
            } else {
                params.getConsole().printBuildFailure("Failed to run " + appleBundle.getFullyQualifiedName() + " on device " + selectedUdid + " (" + connectedDevices.get(selectedUdid) + ")");
                return FAILURE;
            }
        } else {
            return InstallResult.builder().setExitCode(0).build();
        }
    } else {
        params.getConsole().printBuildFailure("Failed to install " + appleBundle.getFullyQualifiedName() + " to device " + selectedUdid + " (" + connectedDevices.get(selectedUdid) + ")");
        return FAILURE;
    }
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) InputStream(java.io.InputStream) AppleDeviceHelper(com.facebook.buck.apple.device.AppleDeviceHelper) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule)

Aggregations

AppleConfig (com.facebook.buck.apple.AppleConfig)8 Path (java.nio.file.Path)5 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)4 HalideBuckConfig (com.facebook.buck.halide.HalideBuckConfig)4 BuildTarget (com.facebook.buck.model.BuildTarget)4 SwiftBuckConfig (com.facebook.buck.swift.SwiftBuckConfig)4 SourcePath (com.facebook.buck.rules.SourcePath)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)3 AppleBundleDescription (com.facebook.buck.apple.AppleBundleDescription)2 AppleDeviceHelper (com.facebook.buck.apple.device.AppleDeviceHelper)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 Flavor (com.facebook.buck.model.Flavor)2 BuildRule (com.facebook.buck.rules.BuildRule)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 InputStream (java.io.InputStream)2 Option (org.kohsuke.args4j.Option)2 NSString (com.dd.plist.NSString)1 AdbHelper (com.facebook.buck.android.AdbHelper)1