about summary refs log tree commit diff
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2023-06-26 20:17:08 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2023-06-26 22:54:47 +0000
commit85c4ea0138fcca2e8cf4515a063cd3b762d64aec (patch)
treea5c9843279acbf237b25b5bdeecda579cc833aec
parent6f8c27ae89dfd32895419d7ef5b89844bcad1bcd (diff)
downloadrust-85c4ea0138fcca2e8cf4515a063cd3b762d64aec.tar.gz
rust-85c4ea0138fcca2e8cf4515a063cd3b762d64aec.zip
bootstrap: rename 'user' profile to 'dist'
-rw-r--r--src/bootstrap/bootstrap.py8
-rw-r--r--src/bootstrap/bootstrap_test.py2
-rw-r--r--src/bootstrap/config.rs8
-rw-r--r--src/bootstrap/config/tests.rs19
-rwxr-xr-xsrc/bootstrap/configure.py2
-rw-r--r--src/bootstrap/defaults/config.dist.toml (renamed from src/bootstrap/defaults/config.user.toml)0
-rw-r--r--src/bootstrap/setup.rs14
7 files changed, 43 insertions, 10 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 5351c80eab9..149350e62a0 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -1052,7 +1052,13 @@ def bootstrap(args):
 
     profile = RustBuild.get_toml_static(config_toml, 'profile')
     if profile is not None:
-        include_file = 'config.{}.toml'.format(profile)
+        # Allows creating alias for profile names, allowing
+        # profiles to be renamed while maintaining back compatibility
+        # Keep in sync with `profile_aliases` in config.rs
+        profile_aliases = {
+            "user": "dist"
+        }
+        include_file = 'config.{}.toml'.format(profile_aliases.get(profile) or profile)
         include_dir = os.path.join(rust_root, 'src', 'bootstrap', 'defaults')
         include_path = os.path.join(include_dir, include_file)
         # HACK: This works because `self.get_toml()` returns the first match it finds for a
diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py
index 815b32eb991..1294ca9df0d 100644
--- a/src/bootstrap/bootstrap_test.py
+++ b/src/bootstrap/bootstrap_test.py
@@ -98,7 +98,7 @@ class GenerateAndParseConfig(unittest.TestCase):
     def test_no_args(self):
         build = serialize_and_parse([])
         self.assertEqual(build.get_toml("changelog-seen"), '2')
-        self.assertEqual(build.get_toml("profile"), 'user')
+        self.assertEqual(build.get_toml("profile"), 'dist')
         self.assertIsNone(build.get_toml("llvm.download-ci-llvm"))
 
     def test_set_section(self):
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index 8ee63e561ba..b91275e73e9 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -1129,6 +1129,14 @@ impl Config {
         };
 
         if let Some(include) = &toml.profile {
+            // Allows creating alias for profile names, allowing
+            // profiles to be renamed while maintaining back compatibility
+            // Keep in sync with `profile_aliases` in bootstrap.py
+            let profile_aliases = HashMap::from([("user", "dist")]);
+            let include = match profile_aliases.get(include.as_str()) {
+                Some(alias) => alias,
+                None => include.as_str(),
+            };
             let mut include_path = config.src.clone();
             include_path.push("src");
             include_path.push("bootstrap");
diff --git a/src/bootstrap/config/tests.rs b/src/bootstrap/config/tests.rs
index 4de84b543ed..3bee659abd1 100644
--- a/src/bootstrap/config/tests.rs
+++ b/src/bootstrap/config/tests.rs
@@ -1,5 +1,8 @@
+use crate::config::TomlConfig;
+
 use super::{Config, Flags};
 use clap::CommandFactory;
+use serde::Deserialize;
 use std::{env, path::Path};
 
 fn parse(config: &str) -> Config {
@@ -159,3 +162,19 @@ fn override_toml_duplicate() {
         |&_| toml::from_str("changelog-seen = 0").unwrap(),
     );
 }
+
+#[test]
+fn profile_user_dist() {
+    fn get_toml(file: &Path) -> TomlConfig {
+        let contents = if file.ends_with("config.toml") {
+            "profile = \"user\"".to_owned()
+        } else {
+            assert!(file.ends_with("config.dist.toml"));
+            std::fs::read_to_string(dbg!(file)).unwrap()
+        };
+        toml::from_str(&contents)
+            .and_then(|table: toml::Value| TomlConfig::deserialize(table))
+            .unwrap()
+    }
+    Config::parse_inner(&["check".to_owned()], get_toml);
+}
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
index a5a1385dc0d..e8eebdfb5a5 100755
--- a/src/bootstrap/configure.py
+++ b/src/bootstrap/configure.py
@@ -437,7 +437,7 @@ def parse_example_config(known_args, config):
         targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", "'{}'".format(target) if "." in target else target)
 
     if 'profile' not in config:
-        set('profile', 'user', config)
+        set('profile', 'dist', config)
     configure_file(sections, top_level_keys, targets, config)
     return section_order, sections, targets
 
diff --git a/src/bootstrap/defaults/config.user.toml b/src/bootstrap/defaults/config.dist.toml
index 25d9e649f23..25d9e649f23 100644
--- a/src/bootstrap/defaults/config.user.toml
+++ b/src/bootstrap/defaults/config.dist.toml
diff --git a/src/bootstrap/setup.rs b/src/bootstrap/setup.rs
index 9811cf163e5..34c6ccf1365 100644
--- a/src/bootstrap/setup.rs
+++ b/src/bootstrap/setup.rs
@@ -20,7 +20,7 @@ pub enum Profile {
     Codegen,
     Library,
     Tools,
-    User,
+    Dist,
     None,
 }
 
@@ -43,7 +43,7 @@ impl Profile {
     pub fn all() -> impl Iterator<Item = Self> {
         use Profile::*;
         // N.B. these are ordered by how they are displayed, not alphabetically
-        [Library, Compiler, Codegen, Tools, User, None].iter().copied()
+        [Library, Compiler, Codegen, Tools, Dist, None].iter().copied()
     }
 
     pub fn purpose(&self) -> String {
@@ -53,7 +53,7 @@ impl Profile {
             Compiler => "Contribute to the compiler itself",
             Codegen => "Contribute to the compiler, and also modify LLVM or codegen",
             Tools => "Contribute to tools which depend on the compiler, but do not modify it directly (e.g. rustdoc, clippy, miri)",
-            User => "Install Rust from source",
+            Dist => "Install Rust from source",
             None => "Do not modify `config.toml`"
         }
         .to_string()
@@ -73,7 +73,7 @@ impl Profile {
             Profile::Codegen => "codegen",
             Profile::Library => "library",
             Profile::Tools => "tools",
-            Profile::User => "user",
+            Profile::Dist => "dist",
             Profile::None => "none",
         }
     }
@@ -87,7 +87,7 @@ impl FromStr for Profile {
             "lib" | "library" => Ok(Profile::Library),
             "compiler" => Ok(Profile::Compiler),
             "llvm" | "codegen" => Ok(Profile::Codegen),
-            "maintainer" | "user" => Ok(Profile::User),
+            "maintainer" | "dist" | "user" => Ok(Profile::Dist),
             "tools" | "tool" | "rustdoc" | "clippy" | "miri" | "rustfmt" | "rls" => {
                 Ok(Profile::Tools)
             }
@@ -160,7 +160,7 @@ pub fn setup(config: &Config, profile: Profile) {
             "test src/tools/rustfmt",
         ],
         Profile::Library => &["check", "build", "test library/std", "doc"],
-        Profile::User => &["dist", "build"],
+        Profile::Dist => &["dist", "build"],
     };
 
     println!();
@@ -170,7 +170,7 @@ pub fn setup(config: &Config, profile: Profile) {
         println!("- `x.py {}`", cmd);
     }
 
-    if profile != Profile::User {
+    if profile != Profile::Dist {
         println!(
             "For more suggestions, see https://rustc-dev-guide.rust-lang.org/building/suggested.html"
         );