Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --run-stage and --link-stage aliases #75167

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,27 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
};

// Some subcommands get extra options
match subcommand.as_str() {
let run_stage = |opts: &mut Options| {
opts.optopt(
"",
"run-stage",
"stage to run, in terms of which libraries it runs with (e.g. `--run-stage 1` means use `build/stage1/bin`). \
This is an alias for `--stage`.",
"N",
);
Some("run-stage")
};
let link_stage = |opts: &mut Options| {
opts.optopt(
"",
"link-stage",
"stage to use, in terms of what libraries it is linked to (e.g. `--link-stage 1` means use `build/stage1-<component>`). \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also feels confusing, because we never link to build/stage1-component, we always link to stageN/lib/rustlib/.../lib/... which is uplifted from stageN-components. (and in stage0 that directory is called stage0-sysroot, iirc, but I might be misremembering).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, how does this look then?

Suggested change
"stage to use, in terms of what libraries it is linked to (e.g. `--link-stage 1` means use `build/stage1-<component>`). \
"stage to use, in terms of what libraries it is linked to (e.g. `--link-stage 1` means to build `build/stage1-<component>` and uplift it to `build/stage2/lib/rustlib`). \

This is an alias for `--stage`.",
"N",
);
Some("link-stage")
};
let extra_stage_arg = match subcommand.as_str() {
"test" | "t" => {
opts.optflag("", "no-fail-fast", "Run all tests regardless of failure");
opts.optmulti("", "test-args", "extra arguments", "ARGS");
Expand Down Expand Up @@ -247,20 +267,26 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
"enable this to generate a Rustfix coverage file, which is saved in \
`/<build_base>/rustfix_missing_coverage.txt`",
);
run_stage(&mut opts)
}
"bench" => {
opts.optmulti("", "test-args", "extra arguments", "ARGS");
link_stage(&mut opts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels definitely wrong for bench and test to have different flags...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I chose this is by looking at whether src/rustc was built for that stage. Or in other words, whether it does any work when you pass it --stage 0. So build --stage 0 src/rustc does work; test --stage 0 src/test/ui does nothing (it runs the beta compiler); bench --stage 0 src/rustc does work; etc.

}
"build" | "b" => link_stage(&mut opts),
"doc" => {
opts.optflag("", "open", "open the docs in a browser");
run_stage(&mut opts)
}
"clean" => {
opts.optflag("", "all", "clean all build artifacts");
None
}
"fmt" => {
opts.optflag("", "check", "check formatting instead of applying.");
None
}
_ => {}
_ => None,
};

// Done specifying what options are possible, so do the getopts parsing
Expand Down Expand Up @@ -517,9 +543,21 @@ Arguments:
}
}

let parse_stage =
|name| -> Option<u32> { matches.opt_get(name).expect("`stage` should be a number") };
// We ensure above that `run-stage` and `link-stage` are mutually exclusive
let stage = match (parse_stage("stage"), extra_stage_arg.and_then(parse_stage)) {
(None, None) => None,
(Some(x), None) | (None, Some(x)) => Some(x),
(Some(_), Some(_)) => {
println!("--stage, --run-stage, and --link-stage are mutually exclusive");
process::exit(1);
}
};

Flags {
verbose: matches.opt_count("verbose"),
stage: matches.opt_str("stage").map(|j| j.parse().expect("`stage` should be a number")),
stage,
dry_run: matches.opt_present("dry-run"),
on_fail: matches.opt_str("on-fail"),
rustc_error_format: matches.opt_str("error-format"),
Expand Down