Skip to content

Commit a5a7b14

Browse files
committed
Allow capping lints with define-ex's --cap-lints
1 parent 25e4ad0 commit a5a7b14

File tree

7 files changed

+51
-17
lines changed

7 files changed

+51
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ own rustup installation, crate mirrors, etc.
4949

5050
```
5151
cargo run -- prepare-local --docker-env mini
52-
cargo run -- define-ex --crate-select=demo stable beta
52+
cargo run -- define-ex --crate-select=demo --cap-lints=forbid stable beta
5353
cargo run -- prepare-ex
5454
cargo run -- run
5555
cargo run -- gen-report work/ex/default/

src/cli.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crater::config::Config;
1313
use crater::docker;
1414
use crater::errors::*;
1515
use crater::ex;
16-
use crater::ex::{ExCrate, ExCrateSelect, ExMode};
16+
use crater::ex::{ExCapLints, ExCrate, ExCrateSelect, ExMode};
1717
use crater::ex_run;
1818
use crater::lists;
1919
use crater::report;
@@ -90,6 +90,9 @@ pub enum Crater {
9090
default_value_raw = "ExCrateSelect::Demo.to_str()",
9191
possible_values_raw = "ExCrateSelect::possible_values()")]
9292
crates: ExCrateSelect,
93+
#[structopt(name = "level", long = "cap-lints", required,
94+
possible_values_raw = "ExCapLints::possible_values()")]
95+
cap_lints: ExCapLints,
9396
},
9497

9598
#[structopt(name = "prepare-ex", about = "prepare shared and local data for experiment")]
@@ -202,13 +205,15 @@ impl Crater {
202205
ref tc2,
203206
ref mode,
204207
ref crates,
208+
ref cap_lints,
205209
} => {
206210
ex::define(
207211
ex::ExOpts {
208212
name: ex.0.clone(),
209213
toolchains: vec![tc1.clone(), tc2.clone()],
210214
mode: mode.clone(),
211215
crates: crates.clone(),
216+
cap_lints: cap_lints.clone(),
212217
},
213218
&config,
214219
)?;

src/docker.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use errors::*;
2+
use ex::ExCapLints;
23
use run::RunCommand;
34
use std::env;
45
use std::fmt::{self, Display, Formatter};
@@ -30,6 +31,7 @@ pub struct RustEnv<'a> {
3031
pub cargo_home: (PathBuf, Perm),
3132
pub rustup_home: (PathBuf, Perm),
3233
pub target_dir: (PathBuf, Perm),
34+
pub cap_lints: &'a ExCapLints,
3335
}
3436

3537
pub struct MountConfig<'a> {
@@ -100,6 +102,10 @@ pub fn rust_container(config: RustEnv) -> ContainerConfig {
100102
("CMD", config.args.join(" ")),
101103
("CARGO_INCREMENTAL", "0".to_string()),
102104
("RUST_BACKTRACE", "full".to_string()),
105+
(
106+
"RUSTFLAGS",
107+
format!("--cap-lints={}", config.cap_lints.to_str()),
108+
),
103109
];
104110

105111
ContainerConfig {

src/ex.rs

+30-5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ string_enum!(pub enum ExCrateSelect {
6464
Top100 => "top-100",
6565
});
6666

67+
string_enum!(pub enum ExCapLints {
68+
Allow => "allow",
69+
Warn => "warn",
70+
Deny => "deny",
71+
Forbid => "forbid",
72+
});
73+
6774
pub fn ex_dir(ex_name: &str) -> PathBuf {
6875
EXPERIMENT_DIR.join(ex_name)
6976
}
@@ -98,6 +105,7 @@ pub struct SerializableExperiment {
98105
pub crates: Vec<Crate>,
99106
pub toolchains: Vec<Toolchain>,
100107
pub mode: ExMode,
108+
pub cap_lints: ExCapLints,
101109
}
102110

103111
pub struct Experiment {
@@ -106,6 +114,7 @@ pub struct Experiment {
106114
pub toolchains: Vec<Toolchain>,
107115
pub shas: Mutex<ShasMap>,
108116
pub mode: ExMode,
117+
pub cap_lints: ExCapLints,
109118
}
110119

111120
impl Experiment {
@@ -115,6 +124,7 @@ impl Experiment {
115124
crates: self.crates.clone(),
116125
toolchains: self.toolchains.clone(),
117126
mode: self.mode.clone(),
127+
cap_lints: self.cap_lints.clone(),
118128
}
119129
}
120130
}
@@ -124,6 +134,7 @@ pub struct ExOpts {
124134
pub toolchains: Vec<Toolchain>,
125135
pub mode: ExMode,
126136
pub crates: ExCrateSelect,
137+
pub cap_lints: ExCapLints,
127138
}
128139

129140
pub fn define(opts: ExOpts, config: &Config) -> Result<()> {
@@ -134,7 +145,13 @@ pub fn define(opts: ExOpts, config: &Config) -> Result<()> {
134145
ExCrateSelect::SmallRandom => small_random()?,
135146
ExCrateSelect::Top100 => top_100()?,
136147
};
137-
define_(&opts.name, opts.toolchains, crates, opts.mode)
148+
define_(
149+
&opts.name,
150+
opts.toolchains,
151+
crates,
152+
opts.mode,
153+
opts.cap_lints,
154+
)
138155
}
139156

140157
fn demo_list(config: &Config) -> Result<Vec<Crate>> {
@@ -185,7 +202,13 @@ fn top_100() -> Result<Vec<Crate>> {
185202
Ok(crates)
186203
}
187204

188-
pub fn define_(ex_name: &str, tcs: Vec<Toolchain>, crates: Vec<Crate>, mode: ExMode) -> Result<()> {
205+
pub fn define_(
206+
ex_name: &str,
207+
toolchains: Vec<Toolchain>,
208+
crates: Vec<Crate>,
209+
mode: ExMode,
210+
cap_lints: ExCapLints,
211+
) -> Result<()> {
189212
info!(
190213
"defining experiment {} for {} crates",
191214
ex_name,
@@ -194,9 +217,10 @@ pub fn define_(ex_name: &str, tcs: Vec<Toolchain>, crates: Vec<Crate>, mode: ExM
194217
let ex = Experiment {
195218
name: ex_name.to_string(),
196219
crates,
197-
toolchains: tcs,
198220
shas: Mutex::new(ShasMap::new(shafile(ex_name))?),
221+
toolchains,
199222
mode,
223+
cap_lints,
200224
};
201225
fs::create_dir_all(&ex_dir(&ex.name))?;
202226
let json = serde_json::to_string(&ex.serializable())?;
@@ -324,6 +348,7 @@ impl Experiment {
324348
crates: data.crates,
325349
toolchains: data.toolchains,
326350
mode: data.mode,
351+
cap_lints: data.cap_lints,
327352
})
328353
}
329354

@@ -560,7 +585,7 @@ fn capture_lockfile(
560585
) -> Result<()> {
561586
let args = &["generate-lockfile", "--manifest-path", "Cargo.toml"];
562587
toolchain
563-
.run_cargo(&ex.name, path, args, CargoState::Unlocked, false)
588+
.run_cargo(ex, path, args, CargoState::Unlocked, false)
564589
.chain_err(|| format!("unable to generate lockfile for {}", crate_))?;
565590

566591
let src_lockfile = &path.join("Cargo.lock");
@@ -610,7 +635,7 @@ pub fn fetch_deps(ex: &Experiment, crates: &[ExCrate], toolchain: &Toolchain) ->
610635

611636
let args = &["fetch", "--locked", "--manifest-path", "Cargo.toml"];
612637
toolchain
613-
.run_cargo(&ex.name, path, args, CargoState::Unlocked, false)
638+
.run_cargo(ex, path, args, CargoState::Unlocked, false)
614639
.chain_err(|| format!("unable to fetch deps for {}", c))?;
615640

616641
Ok(())

src/ex_run.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ pub fn run_test<DB: ExperimentResultDB>(
222222

223223
fn build(ex: &Experiment, source_path: &Path, toolchain: &Toolchain, quiet: bool) -> Result<()> {
224224
toolchain.run_cargo(
225-
&ex.name,
225+
ex,
226226
source_path,
227227
&["build", "--frozen"],
228228
CargoState::Locked,
229229
quiet,
230230
)?;
231231
toolchain.run_cargo(
232-
&ex.name,
232+
ex,
233233
source_path,
234234
&["test", "--frozen", "--no-run"],
235235
CargoState::Locked,
@@ -240,7 +240,7 @@ fn build(ex: &Experiment, source_path: &Path, toolchain: &Toolchain, quiet: bool
240240

241241
fn test(ex: &Experiment, source_path: &Path, toolchain: &Toolchain, quiet: bool) -> Result<()> {
242242
toolchain.run_cargo(
243-
&ex.name,
243+
ex,
244244
source_path,
245245
&["test", "--frozen"],
246246
CargoState::Locked,
@@ -290,7 +290,7 @@ pub fn test_check_only(
290290
quiet: bool,
291291
) -> Result<TestResult> {
292292
let r = toolchain.run_cargo(
293-
&ex.name,
293+
ex,
294294
source_path,
295295
&["check", "--frozen", "--all", "--all-targets"],
296296
CargoState::Locked,

src/toolchain.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use dirs::{CARGO_HOME, RUSTUP_HOME, TARGET_DIR, TOOLCHAIN_DIR};
22
use dl;
33
use docker;
44
use errors::*;
5+
use ex::Experiment;
56
use reqwest;
67
use run::RunCommand;
78
use std::env::consts::EXE_SUFFIX;
@@ -239,14 +240,14 @@ impl Toolchain {
239240

240241
pub fn run_cargo(
241242
&self,
242-
ex_name: &str,
243+
ex: &Experiment,
243244
source_dir: &Path,
244245
args: &[&str],
245246
cargo_state: CargoState,
246247
quiet: bool,
247248
) -> Result<()> {
248249
let toolchain_name = self.rustup_name();
249-
let ex_target_dir = self.target_dir(ex_name);
250+
let ex_target_dir = self.target_dir(&ex.name);
250251

251252
fs::create_dir_all(&ex_target_dir)?;
252253

@@ -266,6 +267,7 @@ impl Toolchain {
266267
rustup_home: (Path::new(&*RUSTUP_HOME).into(), docker::Perm::ReadOnly),
267268
// This is configured as CARGO_TARGET_DIR by the docker container itself
268269
target_dir: (ex_target_dir, docker::Perm::ReadWrite),
270+
cap_lints: &ex.cap_lints,
269271
};
270272
docker::run(&docker::rust_container(rust_env), quiet)
271273
}

todo.md

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# next
2-
3-
- RUSTFLAGS="--cap-lints=warn"
4-
51
# not next
62

73
- custom toolchain support via rust-lang-ci

0 commit comments

Comments
 (0)