Search in sources :

Example 1 with HasInstallableApk

use of com.facebook.buck.android.HasInstallableApk in project buck by facebook.

the class InstallCommand method install.

private int install(CommandRunnerParams params) throws IOException, InterruptedException, NoSuchBuildTargetException {
    Build build = super.getBuild();
    int exitCode = 0;
    for (BuildTarget buildTarget : getBuildTargets()) {
        BuildRule buildRule = build.getRuleResolver().requireRule(buildTarget);
        SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(build.getRuleResolver()));
        if (buildRule instanceof HasInstallableApk) {
            ExecutionContext executionContext = ExecutionContext.builder().from(build.getExecutionContext()).setAdbOptions(Optional.of(adbOptions(params.getBuckConfig()))).setTargetDeviceOptions(Optional.of(targetDeviceOptions())).setExecutors(params.getExecutors()).setCellPathResolver(params.getCell().getCellPathResolver()).build();
            exitCode = installApk(params, (HasInstallableApk) buildRule, executionContext, pathResolver);
            if (exitCode != 0) {
                return exitCode;
            }
        } else if (buildRule instanceof AppleBundle) {
            AppleBundle appleBundle = (AppleBundle) buildRule;
            InstallEvent.Started started = InstallEvent.started(appleBundle.getBuildTarget());
            params.getBuckEventBus().post(started);
            InstallResult installResult = installAppleBundle(params, appleBundle, appleBundle.getProjectFilesystem(), build.getExecutionContext().getProcessExecutor(), pathResolver);
            params.getBuckEventBus().post(InstallEvent.finished(started, installResult.getExitCode() == 0, installResult.getLaunchedPid(), Optional.empty()));
            exitCode = installResult.getExitCode();
            if (exitCode != 0) {
                return exitCode;
            }
        } else {
            params.getBuckEventBus().post(ConsoleEvent.severe(String.format("Specified rule %s must be of type android_binary() or apk_genrule() or " + "apple_bundle() but was %s().\n", buildRule.getFullyQualifiedName(), buildRule.getType())));
            return 1;
        }
    }
    return exitCode;
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) Build(com.facebook.buck.command.Build) BuildTarget(com.facebook.buck.model.BuildTarget) AppleBundle(com.facebook.buck.apple.AppleBundle) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) HasInstallableApk(com.facebook.buck.android.HasInstallableApk)

Example 2 with HasInstallableApk

use of com.facebook.buck.android.HasInstallableApk in project buck by facebook.

the class UninstallCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    // Parse all of the build targets specified by the user.
    BuildRuleResolver resolver;
    ImmutableSet<BuildTarget> buildTargets;
    try (CommandThreadManager pool = new CommandThreadManager("Uninstall", getConcurrencyLimit(params.getBuckConfig()))) {
        TargetGraphAndBuildTargets result = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), /* ignoreBuckAutodepsFiles */
        false);
        buildTargets = result.getBuildTargets();
        resolver = Preconditions.checkNotNull(params.getActionGraphCache().getActionGraph(params.getBuckEventBus(), params.getBuckConfig().isActionGraphCheckingEnabled(), params.getBuckConfig().isSkipActionGraphCache(), result.getTargetGraph(), params.getBuckConfig().getKeySeed())).getResolver();
    } catch (BuildTargetException | BuildFileParseException e) {
        params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
        return 1;
    }
    // Make sure that only one build target is specified.
    if (buildTargets.size() != 1) {
        params.getBuckEventBus().post(ConsoleEvent.severe("Must specify exactly one android_binary() rule."));
        return 1;
    }
    BuildTarget buildTarget = Iterables.get(buildTargets, 0);
    // Find the android_binary() rule from the parse.
    BuildRule buildRule;
    try {
        buildRule = resolver.requireRule(buildTarget);
    } catch (NoSuchBuildTargetException e) {
        throw new HumanReadableException(e.getHumanReadableErrorMessage());
    }
    if (!(buildRule instanceof HasInstallableApk)) {
        params.getBuckEventBus().post(ConsoleEvent.severe(String.format("Specified rule %s must be of type android_binary() or apk_genrule() but was %s().\n", buildRule.getFullyQualifiedName(), buildRule.getType())));
        return 1;
    }
    HasInstallableApk hasInstallableApk = (HasInstallableApk) buildRule;
    // We need this in case adb isn't already running.
    try (ExecutionContext context = createExecutionContext(params)) {
        final AdbHelper adbHelper = new AdbHelper(adbOptions(params.getBuckConfig()), targetDeviceOptions(), context, params.getConsole(), params.getBuckEventBus(), params.getBuckConfig().getRestartAdbOnFailure());
        // Find application package name from manifest and uninstall from matching devices.
        SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
        String appId = AdbHelper.tryToExtractPackageNameFromManifest(pathResolver, hasInstallableApk.getApkInfo());
        return adbHelper.uninstallApp(appId, uninstallOptions().shouldKeepUserData()) ? 0 : 1;
    }
}
Also used : NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildTargetException(com.facebook.buck.model.BuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule) AdbHelper(com.facebook.buck.android.AdbHelper) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) HasInstallableApk(com.facebook.buck.android.HasInstallableApk)

Aggregations

HasInstallableApk (com.facebook.buck.android.HasInstallableApk)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 BuildRule (com.facebook.buck.rules.BuildRule)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 ExecutionContext (com.facebook.buck.step.ExecutionContext)2 AdbHelper (com.facebook.buck.android.AdbHelper)1 AppleBundle (com.facebook.buck.apple.AppleBundle)1 Build (com.facebook.buck.command.Build)1 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)1 BuildTargetException (com.facebook.buck.model.BuildTargetException)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 TargetGraphAndBuildTargets (com.facebook.buck.rules.TargetGraphAndBuildTargets)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1