Skip to content

Commit

Permalink
bootstrap: rename 'user' profile to 'dist'
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Jun 26, 2023
1 parent 6f8c27a commit 85c4ea0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
19 changes: 19 additions & 0 deletions src/bootstrap/config/tests.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions src/bootstrap/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum Profile {
Codegen,
Library,
Tools,
User,
Dist,
None,
}

Expand All @@ -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 {
Expand All @@ -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()
Expand All @@ -73,7 +73,7 @@ impl Profile {
Profile::Codegen => "codegen",
Profile::Library => "library",
Profile::Tools => "tools",
Profile::User => "user",
Profile::Dist => "dist",
Profile::None => "none",
}
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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!();
Expand All @@ -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"
);
Expand Down

0 comments on commit 85c4ea0

Please sign in to comment.