Rollup merge of #98745 - thomcc:build-dir-arg, r=jyn514
Add a `--build-dir` flag to rustbuild This adds an optional `--build-dir <path>` flag to rustbuild (to both the python and rust code in src/bootstrap). If provided, it overrides build directory from the config file (if any was provided). My reason for wanting this is that I often will make a change, save, and then go run `x.py check` or `x.py test` (or something). Because I've saved, vscode will start doing its thing in the background, but this will take the file lock, preventing `x.py` from running until vscode finishes whatever it's doing (since the manually invoked x.py won't be able to acquire said file lock). This is annoying, because I'd rather the command I explicitly invoke *not* wait for r-a to complete, as r-a's check is conceptually a background task (and one which can take quite some time to complete). Anyway, while there are likely other ways this could be handled, if you have the disk space an easy way is to just have vscode be configured to use a different build directory, and then they never have to block each-other. This can currently be arranged without this patch, by maintaining two `config.toml`s, one of which has a different build dir, and just exists to be passed into the overridden check command in vscode. Unfortunately, this has the downside of requiring I maintain two `config.toml`s and keep them (at least somewhat) in sync, aside from the build dir. I dislike for several reasons, not the least of which because I know myself well enough to know that these will inevitably get out of sync and confuse me in the future (perhaps this case would be different since I've thought about it enough to write this patch? Who knows, I'd rather not find out). Either way, it would be much easier for me to have a way for *only* the build directory to differ, which this patch provides by way of a new flag. I suggested this to `@jyn514` who indicated it sounded reasonable so long as it didn't add too much complexity, which I think I've achieved, but he can be the judge. Anyway, with this patch I can just use something like `["python3", "x.py", "check", "--build-dir", "build-vscode", "--json-output"]` as the overridden check command to rust-analyzer, and do not need to futz with any additional `config.toml`s. Which is very nice! I've tested this manually, and can confirm that it works. I'm not sure if it needs automated tests, or where I should add them if so. r? `@jyn514` (who has had to put up with my complaints about this... many times. <3)
This commit is contained in:
commit
335e7d3e33
@ -866,6 +866,7 @@ def bootstrap(help_triggered):
|
||||
|
||||
parser = argparse.ArgumentParser(description='Build rust')
|
||||
parser.add_argument('--config')
|
||||
parser.add_argument('--build-dir')
|
||||
parser.add_argument('--build')
|
||||
parser.add_argument('--color', choices=['always', 'never', 'auto'])
|
||||
parser.add_argument('--clean', action='store_true')
|
||||
@ -915,7 +916,7 @@ def bootstrap(help_triggered):
|
||||
|
||||
build.check_vendored_status()
|
||||
|
||||
build_dir = build.get_toml('build-dir', 'build') or 'build'
|
||||
build_dir = args.build_dir or build.get_toml('build-dir', 'build') or 'build'
|
||||
build.build_dir = os.path.abspath(build_dir)
|
||||
|
||||
with open(os.path.join(build.rust_root, "src", "stage0.json")) as f:
|
||||
|
@ -857,7 +857,7 @@ pub fn parse(args: &[String]) -> Config {
|
||||
let build = toml.build.unwrap_or_default();
|
||||
|
||||
set(&mut config.initial_rustc, build.rustc.map(PathBuf::from));
|
||||
set(&mut config.out, build.build_dir.map(PathBuf::from));
|
||||
set(&mut config.out, flags.build_dir.or_else(|| build.build_dir.map(PathBuf::from)));
|
||||
// NOTE: Bootstrap spawns various commands with different working directories.
|
||||
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
|
||||
if !config.out.is_absolute() {
|
||||
|
@ -51,6 +51,7 @@ pub struct Flags {
|
||||
pub host: Option<Vec<TargetSelection>>,
|
||||
pub target: Option<Vec<TargetSelection>>,
|
||||
pub config: Option<PathBuf>,
|
||||
pub build_dir: Option<PathBuf>,
|
||||
pub jobs: Option<u32>,
|
||||
pub cmd: Subcommand,
|
||||
pub incremental: bool,
|
||||
@ -174,6 +175,12 @@ pub fn parse(args: &[String]) -> Flags {
|
||||
opts.optflagmulti("v", "verbose", "use verbose output (-vv for very verbose)");
|
||||
opts.optflag("i", "incremental", "use incremental compilation");
|
||||
opts.optopt("", "config", "TOML configuration file for build", "FILE");
|
||||
opts.optopt(
|
||||
"",
|
||||
"build-dir",
|
||||
"Build directory, overrides `build.build-dir` in `config.toml`",
|
||||
"DIR",
|
||||
);
|
||||
opts.optopt("", "build", "build target of the stage0 compiler", "BUILD");
|
||||
opts.optmulti("", "host", "host targets to build", "HOST");
|
||||
opts.optmulti("", "target", "target targets to build", "TARGET");
|
||||
@ -649,6 +656,7 @@ pub fn parse(args: &[String]) -> Flags {
|
||||
None
|
||||
},
|
||||
config: matches.opt_str("config").map(PathBuf::from),
|
||||
build_dir: matches.opt_str("build-dir").map(PathBuf::from),
|
||||
jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")),
|
||||
cmd,
|
||||
incremental: matches.opt_present("incremental"),
|
||||
|
Loading…
Reference in New Issue
Block a user