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

Lint on invalid values passed to x.py --warnings #62406

Merged
merged 1 commit into from
Jul 5, 2019
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
4 changes: 2 additions & 2 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ impl Config {
config.incremental = flags.incremental;
config.dry_run = flags.dry_run;
config.keep_stage = flags.keep_stage;
if let Some(value) = flags.warnings {
if let Some(value) = flags.deny_warnings {
config.deny_warnings = value;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So argument parsing here is some kind of two-stage process? &[String] -> Flags -> Config? And this is specifically for what gets passed on the cmdline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's correct -- configuration loading is a bit non-ideal.


Expand Down Expand Up @@ -571,7 +571,7 @@ impl Config {
config.rustc_default_linker = rust.default_linker.clone();
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust here refers to the config.toml?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh also, this inversion of priority won't disturb CI somehow? I don't know exactly how CI passes its parameters but I seem to recall it's not through config.toml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's true. CI doesn't pass the --warnings flag so it should be fine.

set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo);
Expand Down
24 changes: 21 additions & 3 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ pub struct Flags {
pub rustc_error_format: Option<String>,
pub dry_run: bool,

// true => deny
pub warnings: Option<bool>,
// This overrides the deny-warnings configuation option,
// which passes -Dwarnings to the compiler invocations.
//
// true => deny, false => allow
pub deny_warnings: Option<bool>,
}

pub enum Subcommand {
Expand Down Expand Up @@ -468,7 +471,7 @@ Arguments:
.into_iter()
.map(|p| p.into())
.collect::<Vec<_>>(),
warnings: matches.opt_str("warnings").map(|v| v == "deny"),
deny_warnings: parse_deny_warnings(&matches),
}
}
}
Expand Down Expand Up @@ -549,3 +552,18 @@ fn split(s: &[String]) -> Vec<String> {
.map(|s| s.to_string())
.collect()
}

fn parse_deny_warnings(matches: &getopts::Matches) -> Option<bool> {
match matches.opt_str("warnings").as_ref().map(|v| v.as_str()) {
Some("deny") => Some(true),
Some("allow") => Some(false),
Some(value) => {
eprintln!(
r#"invalid value for --warnings: {:?}, expected "allow" or "deny""#,
value,
);
process::exit(1);
},
None => None,
}
}