Skip to content

bootstrap: rename 'user' profile to 'dist' #113068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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