Skip to content

Commit

Permalink
Auto merge of #626 - willcrichton:master, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Add cargoflags to toolchain configuration

I am trying to test the new [scrape examples](rust-lang/rust#88791) feature using Crater. Because it's gated behind a Cargo flag `-Zrustdoc-scrape-examples`, I added the ability for Crater to take as input a new `+cargoflags=...` configuration for toolchains, similar to how `+rustflags` works.

One possible implementation issue: I'm doing `cargoflags.split(' ')` to split up the provided flags so as to pass them into the command builder. A more robust method would be to use a crate like [shlex](https://docs.rs/shlex/latest/shlex/). I'm not sure if this is important enough to add the dependency, or if there's a better way to do this.
  • Loading branch information
bors committed Apr 24, 2022
2 parents 75c8513 + 250680b commit 34be8a1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/bot-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ You can specify a toolchain using a rustup name or `branch#sha`, and use the
following flags:
* `+rustflags={flags}`: sets the `RUSTFLAGS` environment variable to `{flags}` when
building with this toolchain, e.g. `+rustflags=-Zverbose`
* `+cargoflags={flags}`: appends the given `{flags}` to the Cargo command specified
by the experiment mode, e.g. `+cargoflags=-Zavoid-dev-deps`
* `+patch={crate_name}={git_repo_url}={branch}`: patches all crates built by
this toolchain to resolve the given crate from the given git repository and branch.

Expand Down
7 changes: 6 additions & 1 deletion src/runner/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ fn run_cargo<DB: WriteResults>(
check_errors: bool,
local_packages_id: &HashSet<PackageId>,
) -> Fallible<()> {
let mut args = args.to_vec();
if let Some(ref tc_cargoflags) = ctx.toolchain.cargoflags {
args.extend(tc_cargoflags.split(' '));
}

let mut rustflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
if let Some(ref tc_rustflags) = ctx.toolchain.rustflags {
rustflags.push(' ');
Expand Down Expand Up @@ -158,7 +163,7 @@ fn run_cargo<DB: WriteResults>(

let mut command = build_env
.cargo()
.args(args)
.args(&args)
.env("CARGO_INCREMENTAL", "0")
.env("RUST_BACKTRACE", "full")
.env(rustflags_env, rustflags);
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,12 +72,14 @@ pub fn run(
detected_start = Some(Toolchain {
source: RustwideToolchain::ci(&build.base_sha, false),
rustflags: None,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
});
detected_end = Some(Toolchain {
source: RustwideToolchain::ci(&build.merge_sha, false),
rustflags: None,
cargoflags: None,
ci_try: true,
patches: Vec::new(),
});
Expand Down
25 changes: 24 additions & 1 deletion 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,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
};
Expand All @@ -18,6 +19,7 @@ lazy_static! {
pub(crate) static ref TEST_TOOLCHAIN: Toolchain = Toolchain {
source: RustwideToolchain::dist("beta"),
rustflags: None,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
};
Expand All @@ -27,6 +29,7 @@ lazy_static! {
pub struct Toolchain {
pub source: RustwideToolchain,
pub rustflags: Option<String>,
pub cargoflags: Option<String>,
pub ci_try: bool,
pub patches: Vec<CratePatch>,
}
Expand Down Expand Up @@ -65,6 +68,10 @@ impl fmt::Display for Toolchain {
write!(f, "+rustflags={}", flag)?;
}

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

for patch in self.patches.iter() {
write!(f, "+patch={}", patch)?;
}
Expand Down Expand Up @@ -114,6 +121,7 @@ impl FromStr for Toolchain {
};

let mut rustflags = None;
let mut cargoflags = None;
let mut patches: Vec<CratePatch> = vec![];
for part in parts {
if let Some(equal_idx) = part.find('=') {
Expand All @@ -126,6 +134,7 @@ impl FromStr for Toolchain {

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

// Test parsing with flags
// Test parsing with rustflags
test_from_str!(concat!($str, "+rustflags=foo bar") => Toolchain {
source: $source,
rustflags: Some("foo bar".to_string()),
cargoflags: None,
ci_try: $ci_try,
patches: Vec::new(),
});

// Test parsing with cargoflags
test_from_str!(concat!($str, "+cargoflags=foo bar") => Toolchain {
source: $source,
rustflags: None,
cargoflags: Some("foo bar".to_string()),
ci_try: $ci_try,
patches: Vec::new(),
});
Expand All @@ -205,6 +226,7 @@ mod tests {
test_from_str!(concat!($str, "+patch=example=https://git.example.com/some/repo=master") => Toolchain {
source: $source,
rustflags: None,
cargoflags: None,
ci_try: $ci_try,
patches: vec![CratePatch {
name: "example".to_string(),
Expand All @@ -217,6 +239,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()),
cargoflags: None,
ci_try: $ci_try,
patches: vec![CratePatch {
name: "example".to_string(),
Expand Down

0 comments on commit 34be8a1

Please sign in to comment.