fix weird bug when out
would get overridden by unit tests
This commit is contained in:
parent
62b522ec3a
commit
984527f7bb
@ -11,7 +11,7 @@
|
||||
|
||||
fn main() {
|
||||
let args = env::args().skip(1).collect::<Vec<_>>();
|
||||
let config = Config::parse(&args);
|
||||
let config = Config::parse(&args, false);
|
||||
|
||||
// check_version warnings are not printed during setup
|
||||
let changelog_suggestion =
|
||||
|
@ -3,15 +3,15 @@
|
||||
use std::thread;
|
||||
|
||||
fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
|
||||
let mut config = Config::parse(&[cmd.to_owned()]);
|
||||
let mut config = Config::parse(&[cmd.to_owned()], true);
|
||||
// don't save toolstates
|
||||
config.save_toolstates = None;
|
||||
config.dry_run = true;
|
||||
config.ninja_in_file = false;
|
||||
// try to avoid spurious failures in dist where we create/delete each others file
|
||||
config.out = PathBuf::from(env::var_os("BOOTSTRAP_OUTPUT_DIRECTORY").unwrap());
|
||||
config.initial_rustc = PathBuf::from(env::var_os("RUSTC").unwrap());
|
||||
config.initial_cargo = PathBuf::from(env::var_os("BOOTSTRAP_INITIAL_CARGO").unwrap());
|
||||
// try to avoid spurious failures in dist where we create/delete each others file
|
||||
let dir = config
|
||||
.out
|
||||
.join("tmp-rustbuild-tests")
|
||||
|
@ -619,7 +619,7 @@ pub fn default_opts() -> Config {
|
||||
config
|
||||
}
|
||||
|
||||
pub fn parse(args: &[String]) -> Config {
|
||||
pub fn parse(args: &[String], unit_test: bool) -> Config {
|
||||
let flags = Flags::parse(&args);
|
||||
|
||||
let mut config = Config::default_opts();
|
||||
@ -682,11 +682,26 @@ pub fn parse(args: &[String]) -> Config {
|
||||
let build = toml.build.unwrap_or_default();
|
||||
|
||||
set(&mut config.out, build.build_dir.map(String::into));
|
||||
t!(fs::create_dir_all(&config.out));
|
||||
config.out = t!(
|
||||
config.out.canonicalize(),
|
||||
format!("failed to canonicalize {}", config.out.display())
|
||||
);
|
||||
// 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.
|
||||
|
||||
// FIXME: using `canonicalize()` makes this a lot more complicated than it needs to be -
|
||||
// if/when `std::path::absolute` lands, we should use that instead.
|
||||
|
||||
// HACK: in tests, we override the build directory manually.
|
||||
// Avoid creating a directory we won't actually need.
|
||||
// (The original motivation for this is that CI uses read-only directories.)
|
||||
if !config.out.is_absolute() && !unit_test {
|
||||
// canonicalize() gives a hard error if the directory doesn't exist
|
||||
t!(
|
||||
fs::create_dir_all(&config.out),
|
||||
format!("failed to create build dir: {}", config.out.display())
|
||||
);
|
||||
config.out = t!(
|
||||
config.out.canonicalize(),
|
||||
format!("failed to canonicalize {}", config.out.display())
|
||||
);
|
||||
}
|
||||
|
||||
if config.dry_run {
|
||||
let dir = config.out.join("tmp-dry-run");
|
||||
|
@ -343,7 +343,7 @@ pub fn parse(args: &[String]) -> Flags {
|
||||
|
||||
// All subcommands except `clean` can have an optional "Available paths" section
|
||||
if verbose {
|
||||
let config = Config::parse(&["build".to_string()]);
|
||||
let config = Config::parse(&["build".to_string()], false);
|
||||
let build = Build::new(config);
|
||||
|
||||
let maybe_rules_help = Builder::get_help(&build, subcommand.as_str());
|
||||
|
@ -2346,6 +2346,8 @@ fn run(self, builder: &Builder<'_>) {
|
||||
.current_dir(builder.src.join("src/bootstrap"))
|
||||
.env("RUSTFLAGS", "-Cdebuginfo=2")
|
||||
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
|
||||
// HACK: bootstrap's tests want to know the output directory, but there's no way to set
|
||||
// it except through config.toml. Set it through an env variable instead.
|
||||
.env("BOOTSTRAP_OUTPUT_DIRECTORY", &builder.config.out)
|
||||
.env("BOOTSTRAP_INITIAL_CARGO", &builder.config.initial_cargo)
|
||||
.env("RUSTC_BOOTSTRAP", "1")
|
||||
|
Loading…
Reference in New Issue
Block a user