X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fbootstrap%2Fconfig.rs;h=7e6eecaaa884f5f4102aeb50c1f448bab7c03479;hb=88609e51265a563552e8fb4509f83a99e15451b2;hp=73a855ae4d72aa38660d475725987524be3ac2e4;hpb=ec09e70ee1d662553a70b4826a07cb8d2e1083ac;p=rust.git diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 73a855ae4d7..7e6eecaaa88 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -362,11 +362,13 @@ fn do_merge(x: &mut Option, y: Option) { // We are using a decl macro instead of a derive proc macro here to reduce the compile time of // rustbuild. -macro_rules! derive_merge { +macro_rules! define_config { ($(#[$attr:meta])* struct $name:ident { $($field:ident: $field_ty:ty,)* }) => { $(#[$attr])* + #[derive(Deserialize)] + #[serde(deny_unknown_fields, rename_all = "kebab-case")] struct $name { $($field: $field_ty,)* } @@ -383,10 +385,9 @@ fn merge(&mut self, other: Self) { } } -derive_merge! { +define_config! { /// TOML representation of various global build decisions. - #[derive(Deserialize, Default)] - #[serde(deny_unknown_fields, rename_all = "kebab-case")] + #[derive(Default)] struct Build { build: Option, host: Option>, @@ -429,10 +430,8 @@ struct Build { } } -derive_merge! { +define_config! { /// TOML representation of various global install decisions. - #[derive(Deserialize)] - #[serde(deny_unknown_fields, rename_all = "kebab-case")] struct Install { prefix: Option, sysconfdir: Option, @@ -444,10 +443,8 @@ struct Install { } } -derive_merge! { +define_config! { /// TOML representation of how the LLVM build is configured. - #[derive(Deserialize)] - #[serde(deny_unknown_fields, rename_all = "kebab-case")] struct Llvm { skip_rebuild: Option, optimize: Option, @@ -479,9 +476,7 @@ struct Llvm { } } -derive_merge! { - #[derive(Deserialize)] - #[serde(deny_unknown_fields, rename_all = "kebab-case")] +define_config! { struct Dist { sign_folder: Option, gpg_password_file: Option, @@ -505,10 +500,8 @@ fn default() -> StringOrBool { } } -derive_merge! { +define_config! { /// TOML representation of how the Rust build is configured. - #[derive(Deserialize)] - #[serde(deny_unknown_fields, rename_all = "kebab-case")] struct Rust { optimize: Option, debug: Option, @@ -560,10 +553,8 @@ struct Rust { } } -derive_merge! { +define_config! { /// TOML representation of how each build target is configured. - #[derive(Deserialize)] - #[serde(deny_unknown_fields, rename_all = "kebab-case")] struct TomlTarget { cc: Option, cxx: Option, @@ -647,7 +638,8 @@ pub fn parse(args: &[String]) -> Config { let get_toml = |file: &Path| { use std::process; - let contents = t!(fs::read_to_string(file), "`include` config not found"); + let contents = + t!(fs::read_to_string(file), format!("config file {} not found", file.display())); match toml::from_str(&contents) { Ok(table) => table, Err(err) => { @@ -657,14 +649,24 @@ pub fn parse(args: &[String]) -> Config { } }; - // check --config first, then `$RUST_BOOTSTRAP_CONFIG` first, then `config.toml` + // Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`, then `config.toml` in the root directory. let toml_path = flags .config .clone() - .or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from)) - .unwrap_or_else(|| PathBuf::from("config.toml")); - let mut toml = - if toml_path.exists() { get_toml(&toml_path) } else { TomlConfig::default() }; + .or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from)); + let using_default_path = toml_path.is_none(); + let mut toml_path = toml_path.unwrap_or_else(|| PathBuf::from("config.toml")); + if using_default_path && !toml_path.exists() { + toml_path = config.src.join(toml_path); + } + + // Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path, + // but not if `config.toml` hasn't been created. + let mut toml = if !using_default_path || toml_path.exists() { + get_toml(&toml_path) + } else { + TomlConfig::default() + }; if let Some(include) = &toml.profile { let mut include_path = config.src.clone();