Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f9256fa authored by Joe Onorato's avatar Joe Onorato Committed by Android (Google) Code Review
Browse files

Merge "Add bit --refresh which updates module-info.json"

parents 8ed3fb9b 7acae74e
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@ struct Options {
    // For help
    bool runHelp;

    // For refreshing module-info.json
    bool runRefresh;

    // For tab completion
    bool runTab;
    string tabPattern;
@@ -93,6 +96,7 @@ struct Options {

Options::Options()
    :runHelp(false),
     runRefresh(false),
     runTab(false),
     noRestart(false),
     reboot(false),
@@ -418,6 +422,10 @@ print_usage(FILE* out) {
    fprintf(out, "      com.android.statusbartest/.NotificationBuilderTest activity.\n");
    fprintf(out, "\n");
    fprintf(out, "\n");
    fprintf(out, "usage: bit --refresh\n");
    fprintf(out, "\n");
    fprintf(out, "  Update module-info.json, the cache of make goals that can be built.\n");
    fprintf(out, "\n");
    fprintf(out, "usage: bit --tab ...\n");
    fprintf(out, "\n");
    fprintf(out, "  Lists the targets in a format for tab completion. To get tab\n");
@@ -450,6 +458,12 @@ parse_args(Options* options, int argc, const char** argv)
        return;
    }

    // Refresh
    if (argc == 2 && strcmp(argv[1], "--refresh") == 0) {
        options->runRefresh = true;
        return;
    }

    // Tab
    if (argc >= 4 && strcmp(argv[1], "--tab") == 0) {
        options->runTab = true;
@@ -669,6 +683,9 @@ run_phases(vector<Target*> targets, const Options& options)
            target->module = mod->second;
        } else {
            print_error("Error: Could not find module: %s", target->name.c_str());
            fprintf(stderr, "Try running %sbit --refresh%s if you recently added %s%s%s.\n",
                    g_escapeBold, g_escapeEndColor,
                    g_escapeBold, target->name.c_str(), g_escapeEndColor);
            err = 1;
        }
    }
@@ -1145,6 +1162,34 @@ run_phases(vector<Target*> targets, const Options& options)
    return !hasErrors;
}

/**
 * Refresh module-info.
 */
void
run_refresh()
{
    int err;

    print_status("Initializing");
    const string buildTop = get_required_env("ANDROID_BUILD_TOP", false);
    const string buildProduct = get_required_env("TARGET_PRODUCT", false);
    const string buildVariant = get_required_env("TARGET_BUILD_VARIANT", false);
    const string buildType = get_required_env("TARGET_BUILD_TYPE", false);
    const string buildOut = get_out_dir();
    chdir_or_exit(buildTop.c_str());

    BuildVars buildVars(buildOut, buildProduct, buildVariant, buildType);

    string buildDevice = buildVars.GetBuildVar("TARGET_DEVICE", false);

    vector<string> goals;
    goals.push_back(buildOut + "/target/product/" + buildDevice + "/module-info.json");

    print_status("Refreshing module-info.json");
    err = build_goals(goals);
    check_error(err);
}

/**
 * Implement tab completion of the target names from the all modules file.
 */
@@ -1188,6 +1233,9 @@ main(int argc, const char** argv)
        // Help
        print_usage(stdout);
        exit(0);
    } else if (options.runRefresh) {
        run_refresh();
        exit(0);
    } else if (options.runTab) {
        run_tab_completion(options.tabPattern);
        exit(0);