Skip to content
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

Split x setup sub-actions to CLI arguments (Clap edition) #108135

Closed
wants to merge 4 commits into from
Closed
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
91 changes: 73 additions & 18 deletions src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ version = "0.0.0"
dependencies = [
"build_helper",
"cc",
"clap",
"cmake",
"fd-lock",
"filetime",
"getopts",
"hex",
"ignore",
"libc",
Expand Down Expand Up @@ -87,6 +87,40 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "clap"
version = "4.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
dependencies = [
"bitflags",
"clap_derive",
"clap_lex",
"once_cell",
]

[[package]]
name = "clap_derive"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]

[[package]]
name = "clap_lex"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade"
dependencies = [
"os_str_bytes",
]

[[package]]
name = "cmake"
version = "0.1.48"
Expand Down Expand Up @@ -256,15 +290,6 @@ dependencies = [
"version_check",
]

[[package]]
name = "getopts"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
dependencies = [
"unicode-width",
]

[[package]]
name = "globset"
version = "0.4.8"
Expand All @@ -278,6 +303,12 @@ dependencies = [
"regex",
]

[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"

[[package]]
name = "hermit-abi"
version = "0.1.19"
Expand Down Expand Up @@ -424,6 +455,12 @@ dependencies = [
"winapi",
]

[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"

[[package]]
name = "output_vt100"
version = "0.1.3"
Expand Down Expand Up @@ -451,6 +488,30 @@ dependencies = [
"yansi",
]

[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]

[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]

[[package]]
name = "proc-macro2"
version = "1.0.46"
Expand Down Expand Up @@ -526,9 +587,9 @@ checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"

[[package]]
name = "rustix"
version = "0.36.3"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e"
checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03"
dependencies = [
"bitflags",
"errno",
Expand Down Expand Up @@ -668,12 +729,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"

[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"

[[package]]
name = "version_check"
version = "0.9.4"
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ build_helper = { path = "../tools/build_helper" }
cmake = "0.1.38"
fd-lock = "3.0.8"
filetime = "0.2"
getopts = "0.2.19"
cc = "1.0.69"
clap = { version = "4.1.4", features = ["std", "usage", "help", "derive", "error-context"], default-features = false}
libc = "0.2"
hex = "0.4"
object = { version = "0.29.0", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }
Expand Down
32 changes: 19 additions & 13 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,19 +546,24 @@ impl<'a> ShouldRun<'a> {
}
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, clap::ValueEnum)]
pub enum Kind {
#[clap(aliases = ["b"])]
Build,
#[clap(aliases = ["c"])]
Check,
Clippy,
Fix,
Format,
#[clap(aliases = ["t"])]
Test,
Bench,
#[clap(aliases = ["d"])]
Doc,
Clean,
Dist,
Install,
#[clap(aliases = ["r"])]
Run,
Setup,
}
Expand Down Expand Up @@ -792,7 +797,7 @@ impl<'a> Builder<'a> {
run::CollectLicenseMetadata,
run::GenerateCopyright,
),
Kind::Setup => describe!(setup::Profile),
Kind::Setup => describe!(setup::Profile, setup::Hook, setup::Link, setup::Vscode),
Kind::Clean => describe!(clean::CleanAll, clean::Rustc, clean::Std),
// special-cased in Build::build()
Kind::Format => vec![],
Expand Down Expand Up @@ -846,18 +851,19 @@ impl<'a> Builder<'a> {
}

pub fn new(build: &Build) -> Builder<'_> {
let paths = &build.config.paths;
let (kind, paths) = match build.config.cmd {
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
Subcommand::Clippy { ref paths, .. } => (Kind::Clippy, &paths[..]),
Subcommand::Fix { ref paths } => (Kind::Fix, &paths[..]),
Subcommand::Doc { ref paths, .. } => (Kind::Doc, &paths[..]),
Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),
Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
Subcommand::Run { ref paths, .. } => (Kind::Run, &paths[..]),
Subcommand::Clean { ref paths, .. } => (Kind::Clean, &paths[..]),
Subcommand::Build => (Kind::Build, &paths[..]),
Subcommand::Check { .. } => (Kind::Check, &paths[..]),
Subcommand::Clippy { .. } => (Kind::Clippy, &paths[..]),
Subcommand::Fix => (Kind::Fix, &paths[..]),
Subcommand::Doc { .. } => (Kind::Doc, &paths[..]),
Subcommand::Test { .. } => (Kind::Test, &paths[..]),
Subcommand::Bench { .. } => (Kind::Bench, &paths[..]),
Subcommand::Dist => (Kind::Dist, &paths[..]),
Subcommand::Install => (Kind::Install, &paths[..]),
Subcommand::Run { .. } => (Kind::Run, &paths[..]),
Subcommand::Clean { .. } => (Kind::Clean, &paths[..]),
Subcommand::Format { .. } => (Kind::Format, &[][..]),
Subcommand::Setup { profile: ref path } => (
Kind::Setup,
Expand Down
19 changes: 11 additions & 8 deletions src/bootstrap/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ mod defaults {
fn doc_default() {
let mut config = configure("doc", &["A"], &["A"]);
config.compiler_docs = true;
config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false };
config.cmd = Subcommand::Doc { open: false, json: false };
let mut cache = run_build(&[], config);
let a = TargetSelection::from_user("A");

Expand Down Expand Up @@ -545,19 +545,21 @@ mod dist {
fn test_with_no_doc_stage0() {
let mut config = configure(&["A"], &["A"]);
config.stage = 0;
config.paths = vec!["library/std".into()];
config.cmd = Subcommand::Test {
paths: vec!["library/std".into()],
test_args: vec![],
rustc_args: vec![],
fail_fast: true,
doc_tests: DocTests::No,
no_fail_fast: false,
no_doc: true,
doc: false,
bless: false,
force_rerun: false,
compare_mode: None,
rustfix_coverage: false,
pass: None,
run: None,
only_modified: false,
skip: vec![],
};

let build = Build::new(config);
Expand Down Expand Up @@ -588,7 +590,7 @@ mod dist {
fn doc_ci() {
let mut config = configure(&["A"], &["A"]);
config.compiler_docs = true;
config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false };
config.cmd = Subcommand::Doc { open: false, json: false };
let build = Build::new(config);
let mut builder = Builder::new(&build);
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
Expand Down Expand Up @@ -617,18 +619,19 @@ mod dist {
// Behavior of `x.py test` doing various documentation tests.
let mut config = configure(&["A"], &["A"]);
config.cmd = Subcommand::Test {
paths: vec![],
test_args: vec![],
rustc_args: vec![],
fail_fast: true,
doc_tests: DocTests::Yes,
no_fail_fast: false,
doc: true,
no_doc: false,
bless: false,
force_rerun: false,
compare_mode: None,
rustfix_coverage: false,
pass: None,
run: None,
only_modified: false,
skip: vec![],
};
// Make sure rustfmt binary not being found isn't an error.
config.channel = "beta".to_string();
Expand Down
18 changes: 5 additions & 13 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
arr.iter().copied().map(String::from)
}

if let Subcommand::Clippy {
fix,
clippy_lint_allow,
clippy_lint_deny,
clippy_lint_warn,
clippy_lint_forbid,
..
} = &builder.config.cmd
{
if let Subcommand::Clippy { fix, allow, deny, warn, forbid, .. } = &builder.config.cmd {
// disable the most spammy clippy lints
let ignored_lints = vec![
"many_single_char_names", // there are a lot in stdarch
Expand All @@ -53,10 +45,10 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
args.extend(strings(&["--", "--cap-lints", "warn"]));
args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
let mut clippy_lint_levels: Vec<String> = Vec::new();
clippy_lint_allow.iter().for_each(|v| clippy_lint_levels.push(format!("-A{}", v)));
clippy_lint_deny.iter().for_each(|v| clippy_lint_levels.push(format!("-D{}", v)));
clippy_lint_warn.iter().for_each(|v| clippy_lint_levels.push(format!("-W{}", v)));
clippy_lint_forbid.iter().for_each(|v| clippy_lint_levels.push(format!("-F{}", v)));
allow.iter().for_each(|v| clippy_lint_levels.push(format!("-A{}", v)));
deny.iter().for_each(|v| clippy_lint_levels.push(format!("-D{}", v)));
warn.iter().for_each(|v| clippy_lint_levels.push(format!("-W{}", v)));
forbid.iter().for_each(|v| clippy_lint_levels.push(format!("-F{}", v)));
args.extend(clippy_lint_levels);
args.extend(builder.config.free_args.clone());
args
Expand Down
24 changes: 16 additions & 8 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ pub struct Config {
pub initial_rustfmt: RefCell<RustfmtState>,
pub out: PathBuf,
pub rust_info: channel::GitInfo,

pub paths: Vec<PathBuf>,
}

#[derive(Default, Deserialize)]
Expand Down Expand Up @@ -366,6 +368,12 @@ pub struct TargetSelection {
file: Option<Interned<String>>,
}

impl<'a> From<&'a str> for TargetSelection {
fn from(s: &'a str) -> Self {
Self::from_user(s)
}
}

impl TargetSelection {
pub fn from_user(selection: &str) -> Self {
let path = Path::new(selection);
Expand Down Expand Up @@ -854,25 +862,26 @@ impl Config {
}

fn parse_inner<'a>(args: &[String], get_toml: impl 'a + Fn(&Path) -> TomlConfig) -> Config {
let flags = Flags::parse(&args);
let mut flags = Flags::parse(&args);
let mut config = Config::default_opts();

// Set flags.
config.paths = std::mem::take(&mut flags.paths);
config.free_args = std::mem::take(&mut flags.free_args);
config.exclude = flags.exclude.into_iter().map(|path| TaskPath::parse(path)).collect();
config.include_default_paths = flags.include_default_paths;
config.rustc_error_format = flags.rustc_error_format;
config.rustc_error_format = flags.error_format;
config.json_output = flags.json_output;
config.on_fail = flags.on_fail;
config.jobs = flags.jobs.map(threads_from_config);
config.jobs = Some(threads_from_config(flags.jobs as u32));
config.cmd = flags.cmd;
config.incremental = flags.incremental;
config.dry_run = if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled };
config.keep_stage = flags.keep_stage;
config.keep_stage_std = flags.keep_stage_std;
config.color = flags.color;
config.free_args = flags.free_args.clone().unwrap_or_default();
if let Some(value) = flags.deny_warnings {
config.deny_warnings = value;
if matches!(flags.deny_warnings, crate::flags::Warnings::Deny) {
config.deny_warnings = true;
}
config.llvm_profile_use = flags.llvm_profile_use;
config.llvm_profile_generate = flags.llvm_profile_generate;
Expand Down Expand Up @@ -1045,7 +1054,7 @@ impl Config {
set(&mut config.print_step_rusage, build.print_step_rusage);
set(&mut config.patch_binaries_for_nix, build.patch_binaries_for_nix);

config.verbose = cmp::max(config.verbose, flags.verbose);
config.verbose = cmp::max(config.verbose, flags.verbose as usize);

if let Some(install) = toml.install {
config.prefix = install.prefix.map(PathBuf::from);
Expand Down Expand Up @@ -1123,7 +1132,6 @@ impl Config {
config.rustc_default_linker = rust.default_linker;
config.musl_root = rust.musl_root.map(PathBuf::from);
config.save_toolstates = rust.save_toolstates.map(PathBuf::from);
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings));
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
config.rust_thin_lto_import_instr_limit = rust.thin_lto_import_instr_limit;
Expand Down
Loading