Skip to content

Commit

Permalink
Auto merge of #654 - Enselic:rustdocflags, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Allow to specify `RUSTDOCFLAGS` independently

Currently, if you to run this experiment:

```
cargo run -- define-ex --ex rustdoc-json-broken --mode rustdoc \
    --cap-lints warn --crate-select list:serde \
    "nightly-2022-06-01+rustflags=-Z unstable-options --output-format json" \
    "nightly+rustflags=-Z unstable-options --output-format json" \
```

crater will mix up `RUSTFLAGS` and `RUSTDOCFLAGS` and you will get the following error:

```
[INFO] [stderr]   process didn't exit successfully: `rustc - --crate-name ___ \
    --print=file-names --cap-lints=warn -Z unstable-options --output-format json \
    --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib \
    --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` \
    (exit status: 1)
[INFO] [stderr]   --- stderr
[INFO] [stderr]   error: Unrecognized option: 'output-format'
```

Solve this by allowing `rustdoc` and `rustdocflags` to be specified independently. After this change, this works without unexpected errors:

```
cargo run -- define-ex --ex rustdoc-json-ice --mode rustdoc \
    --cap-lints warn --crate-select list:serde \
    "nightly-2022-06-01+rustdocflags=-Z unstable-options --output-format json" \
    "nightly+rustdocflags=-Z unstable-options --output-format json"
```

Not sure if this change breaks compatibility in some way, but it seems like a rather generic and future-proof solution to me.
  • Loading branch information
bors committed Jul 28, 2022
2 parents a082ad4 + 885ec83 commit b219427
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/runner/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ fn run_cargo<DB: WriteResults>(
rustflags.push_str(tc_rustflags);
}

let rustflags_env = if let Some(&"doc") = args.first() {
"RUSTDOCFLAGS"
} else {
"RUSTFLAGS"
};
let mut rustdocflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
if let Some(ref tc_rustdocflags) = ctx.toolchain.rustdocflags {
rustdocflags.push(' ');
rustdocflags.push_str(tc_rustdocflags);
}

let mut did_ice = false;
let mut did_network = false;
Expand Down Expand Up @@ -170,7 +170,8 @@ fn run_cargo<DB: WriteResults>(
.args(&args)
.env("CARGO_INCREMENTAL", "0")
.env("RUST_BACKTRACE", "full")
.env(rustflags_env, rustflags);
.env("RUSTFLAGS", rustflags)
.env("RUSTDOCFLAGS", rustdocflags);
for (var, data) in env {
command = command.env(var, data);
}
Expand Down
2 changes: 2 additions & 0 deletions src/server/routes/webhooks/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ pub fn run(
detected_start = Some(Toolchain {
source: RustwideToolchain::ci(&build.base_sha, false),
rustflags: None,
rustdocflags: None,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
});
detected_end = Some(Toolchain {
source: RustwideToolchain::ci(&build.merge_sha, false),
rustflags: None,
rustdocflags: None,
cargoflags: None,
ci_try: true,
patches: Vec::new(),
Expand Down
27 changes: 27 additions & 0 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lazy_static! {
pub(crate) static ref MAIN_TOOLCHAIN: Toolchain = Toolchain {
source: RustwideToolchain::dist("stable"),
rustflags: None,
rustdocflags: None,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
Expand All @@ -19,6 +20,7 @@ lazy_static! {
pub(crate) static ref TEST_TOOLCHAIN: Toolchain = Toolchain {
source: RustwideToolchain::dist("beta"),
rustflags: None,
rustdocflags: None,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
Expand All @@ -29,6 +31,7 @@ lazy_static! {
pub struct Toolchain {
pub source: RustwideToolchain,
pub rustflags: Option<String>,
pub rustdocflags: Option<String>,
pub cargoflags: Option<String>,
pub ci_try: bool,
pub patches: Vec<CratePatch>,
Expand Down Expand Up @@ -68,6 +71,10 @@ impl fmt::Display for Toolchain {
write!(f, "+rustflags={}", flag)?;
}

if let Some(ref flag) = self.rustdocflags {
write!(f, "+rustdocflags={}", flag)?;
}

if let Some(ref flag) = self.cargoflags {
write!(f, "+cargoflags={}", flag)?;
}
Expand Down Expand Up @@ -121,6 +128,7 @@ impl FromStr for Toolchain {
};

let mut rustflags = None;
let mut rustdocflags = None;
let mut cargoflags = None;
let mut patches: Vec<CratePatch> = vec![];
for part in parts {
Expand All @@ -134,6 +142,7 @@ impl FromStr for Toolchain {

match flag {
"rustflags" => rustflags = Some(value),
"rustdocflags" => rustdocflags = Some(value),
"cargoflags" => cargoflags = Some(value),
"patch" => patches.push(value.parse()?),
unknown => return Err(ToolchainParseError::InvalidFlag(unknown.to_string())),
Expand All @@ -146,6 +155,7 @@ impl FromStr for Toolchain {
Ok(Toolchain {
source,
rustflags,
rustdocflags,
cargoflags,
ci_try,
patches,
Expand Down Expand Up @@ -199,6 +209,7 @@ mod tests {
test_from_str!($str => Toolchain {
source: $source,
rustflags: None,
rustdocflags: None,
cargoflags: None,
ci_try: $ci_try,
patches: Vec::new(),
Expand All @@ -208,6 +219,17 @@ mod tests {
test_from_str!(concat!($str, "+rustflags=foo bar") => Toolchain {
source: $source,
rustflags: Some("foo bar".to_string()),
rustdocflags: None,
cargoflags: None,
ci_try: $ci_try,
patches: Vec::new(),
});

// Test parsing with rustdocflags
test_from_str!(concat!($str, "+rustdocflags=-Zunstable-options -wjson") => Toolchain {
source: $source,
rustflags: None,
rustdocflags: Some("-Zunstable-options -wjson".to_string()),
cargoflags: None,
ci_try: $ci_try,
patches: Vec::new(),
Expand All @@ -217,6 +239,7 @@ mod tests {
test_from_str!(concat!($str, "+cargoflags=foo bar") => Toolchain {
source: $source,
rustflags: None,
rustdocflags: None,
cargoflags: Some("foo bar".to_string()),
ci_try: $ci_try,
patches: Vec::new(),
Expand All @@ -226,6 +249,7 @@ mod tests {
test_from_str!(concat!($str, "+patch=example=https://git.example.com/some/repo=master") => Toolchain {
source: $source,
rustflags: None,
rustdocflags: None,
cargoflags: None,
ci_try: $ci_try,
patches: vec![CratePatch {
Expand All @@ -239,6 +263,7 @@ mod tests {
test_from_str!(concat!($str, "+rustflags=foo bar+patch=example=https://git.example.com/some/repo=master") => Toolchain {
source: $source,
rustflags: Some("foo bar".to_string()),
rustdocflags: None,
cargoflags: None,
ci_try: $ci_try,
patches: vec![CratePatch {
Expand Down Expand Up @@ -291,6 +316,8 @@ mod tests {
assert!(Toolchain::from_str("foo#0000000000000000000000000000000000000000").is_err());
assert!(Toolchain::from_str("stable+rustflags").is_err());
assert!(Toolchain::from_str("stable+rustflags=").is_err());
assert!(Toolchain::from_str("stable+rustdocflags").is_err());
assert!(Toolchain::from_str("stable+rustdocflags=").is_err());
assert!(Toolchain::from_str("stable+donotusethisflag=ever").is_err());
assert!(Toolchain::from_str("stable+patch=").is_err())
}
Expand Down

0 comments on commit b219427

Please sign in to comment.