Skip to content

Commit

Permalink
Allow capping lints with define-ex's --cap-lints
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Apr 2, 2018
1 parent 25e4ad0 commit a5a7b14
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -49,7 +49,7 @@ own rustup installation, crate mirrors, etc.

```
cargo run -- prepare-local --docker-env mini
cargo run -- define-ex --crate-select=demo stable beta
cargo run -- define-ex --crate-select=demo --cap-lints=forbid stable beta
cargo run -- prepare-ex
cargo run -- run
cargo run -- gen-report work/ex/default/
Expand Down
7 changes: 6 additions & 1 deletion src/cli.rs
Expand Up @@ -13,7 +13,7 @@ use crater::config::Config;
use crater::docker;
use crater::errors::*;
use crater::ex;
use crater::ex::{ExCrate, ExCrateSelect, ExMode};
use crater::ex::{ExCapLints, ExCrate, ExCrateSelect, ExMode};
use crater::ex_run;
use crater::lists;
use crater::report;
Expand Down Expand Up @@ -90,6 +90,9 @@ pub enum Crater {
default_value_raw = "ExCrateSelect::Demo.to_str()",
possible_values_raw = "ExCrateSelect::possible_values()")]
crates: ExCrateSelect,
#[structopt(name = "level", long = "cap-lints", required,
possible_values_raw = "ExCapLints::possible_values()")]
cap_lints: ExCapLints,
},

#[structopt(name = "prepare-ex", about = "prepare shared and local data for experiment")]
Expand Down Expand Up @@ -202,13 +205,15 @@ impl Crater {
ref tc2,
ref mode,
ref crates,
ref cap_lints,
} => {
ex::define(
ex::ExOpts {
name: ex.0.clone(),
toolchains: vec![tc1.clone(), tc2.clone()],
mode: mode.clone(),
crates: crates.clone(),
cap_lints: cap_lints.clone(),
},
&config,
)?;
Expand Down
6 changes: 6 additions & 0 deletions src/docker.rs
@@ -1,4 +1,5 @@
use errors::*;
use ex::ExCapLints;
use run::RunCommand;
use std::env;
use std::fmt::{self, Display, Formatter};
Expand Down Expand Up @@ -30,6 +31,7 @@ pub struct RustEnv<'a> {
pub cargo_home: (PathBuf, Perm),
pub rustup_home: (PathBuf, Perm),
pub target_dir: (PathBuf, Perm),
pub cap_lints: &'a ExCapLints,
}

pub struct MountConfig<'a> {
Expand Down Expand Up @@ -100,6 +102,10 @@ pub fn rust_container(config: RustEnv) -> ContainerConfig {
("CMD", config.args.join(" ")),
("CARGO_INCREMENTAL", "0".to_string()),
("RUST_BACKTRACE", "full".to_string()),
(
"RUSTFLAGS",
format!("--cap-lints={}", config.cap_lints.to_str()),
),
];

ContainerConfig {
Expand Down
35 changes: 30 additions & 5 deletions src/ex.rs
Expand Up @@ -64,6 +64,13 @@ string_enum!(pub enum ExCrateSelect {
Top100 => "top-100",
});

string_enum!(pub enum ExCapLints {
Allow => "allow",
Warn => "warn",
Deny => "deny",
Forbid => "forbid",
});

pub fn ex_dir(ex_name: &str) -> PathBuf {
EXPERIMENT_DIR.join(ex_name)
}
Expand Down Expand Up @@ -98,6 +105,7 @@ pub struct SerializableExperiment {
pub crates: Vec<Crate>,
pub toolchains: Vec<Toolchain>,
pub mode: ExMode,
pub cap_lints: ExCapLints,
}

pub struct Experiment {
Expand All @@ -106,6 +114,7 @@ pub struct Experiment {
pub toolchains: Vec<Toolchain>,
pub shas: Mutex<ShasMap>,
pub mode: ExMode,
pub cap_lints: ExCapLints,
}

impl Experiment {
Expand All @@ -115,6 +124,7 @@ impl Experiment {
crates: self.crates.clone(),
toolchains: self.toolchains.clone(),
mode: self.mode.clone(),
cap_lints: self.cap_lints.clone(),
}
}
}
Expand All @@ -124,6 +134,7 @@ pub struct ExOpts {
pub toolchains: Vec<Toolchain>,
pub mode: ExMode,
pub crates: ExCrateSelect,
pub cap_lints: ExCapLints,
}

pub fn define(opts: ExOpts, config: &Config) -> Result<()> {
Expand All @@ -134,7 +145,13 @@ pub fn define(opts: ExOpts, config: &Config) -> Result<()> {
ExCrateSelect::SmallRandom => small_random()?,
ExCrateSelect::Top100 => top_100()?,
};
define_(&opts.name, opts.toolchains, crates, opts.mode)
define_(
&opts.name,
opts.toolchains,
crates,
opts.mode,
opts.cap_lints,
)
}

fn demo_list(config: &Config) -> Result<Vec<Crate>> {
Expand Down Expand Up @@ -185,7 +202,13 @@ fn top_100() -> Result<Vec<Crate>> {
Ok(crates)
}

pub fn define_(ex_name: &str, tcs: Vec<Toolchain>, crates: Vec<Crate>, mode: ExMode) -> Result<()> {
pub fn define_(
ex_name: &str,
toolchains: Vec<Toolchain>,
crates: Vec<Crate>,
mode: ExMode,
cap_lints: ExCapLints,
) -> Result<()> {
info!(
"defining experiment {} for {} crates",
ex_name,
Expand All @@ -194,9 +217,10 @@ pub fn define_(ex_name: &str, tcs: Vec<Toolchain>, crates: Vec<Crate>, mode: ExM
let ex = Experiment {
name: ex_name.to_string(),
crates,
toolchains: tcs,
shas: Mutex::new(ShasMap::new(shafile(ex_name))?),
toolchains,
mode,
cap_lints,
};
fs::create_dir_all(&ex_dir(&ex.name))?;
let json = serde_json::to_string(&ex.serializable())?;
Expand Down Expand Up @@ -324,6 +348,7 @@ impl Experiment {
crates: data.crates,
toolchains: data.toolchains,
mode: data.mode,
cap_lints: data.cap_lints,
})
}

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

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

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

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/ex_run.rs
Expand Up @@ -222,14 +222,14 @@ pub fn run_test<DB: ExperimentResultDB>(

fn build(ex: &Experiment, source_path: &Path, toolchain: &Toolchain, quiet: bool) -> Result<()> {
toolchain.run_cargo(
&ex.name,
ex,
source_path,
&["build", "--frozen"],
CargoState::Locked,
quiet,
)?;
toolchain.run_cargo(
&ex.name,
ex,
source_path,
&["test", "--frozen", "--no-run"],
CargoState::Locked,
Expand All @@ -240,7 +240,7 @@ fn build(ex: &Experiment, source_path: &Path, toolchain: &Toolchain, quiet: bool

fn test(ex: &Experiment, source_path: &Path, toolchain: &Toolchain, quiet: bool) -> Result<()> {
toolchain.run_cargo(
&ex.name,
ex,
source_path,
&["test", "--frozen"],
CargoState::Locked,
Expand Down Expand Up @@ -290,7 +290,7 @@ pub fn test_check_only(
quiet: bool,
) -> Result<TestResult> {
let r = toolchain.run_cargo(
&ex.name,
ex,
source_path,
&["check", "--frozen", "--all", "--all-targets"],
CargoState::Locked,
Expand Down
6 changes: 4 additions & 2 deletions src/toolchain.rs
Expand Up @@ -2,6 +2,7 @@ use dirs::{CARGO_HOME, RUSTUP_HOME, TARGET_DIR, TOOLCHAIN_DIR};
use dl;
use docker;
use errors::*;
use ex::Experiment;
use reqwest;
use run::RunCommand;
use std::env::consts::EXE_SUFFIX;
Expand Down Expand Up @@ -239,14 +240,14 @@ impl Toolchain {

pub fn run_cargo(
&self,
ex_name: &str,
ex: &Experiment,
source_dir: &Path,
args: &[&str],
cargo_state: CargoState,
quiet: bool,
) -> Result<()> {
let toolchain_name = self.rustup_name();
let ex_target_dir = self.target_dir(ex_name);
let ex_target_dir = self.target_dir(&ex.name);

fs::create_dir_all(&ex_target_dir)?;

Expand All @@ -266,6 +267,7 @@ impl Toolchain {
rustup_home: (Path::new(&*RUSTUP_HOME).into(), docker::Perm::ReadOnly),
// This is configured as CARGO_TARGET_DIR by the docker container itself
target_dir: (ex_target_dir, docker::Perm::ReadWrite),
cap_lints: &ex.cap_lints,
};
docker::run(&docker::rust_container(rust_env), quiet)
}
Expand Down
4 changes: 0 additions & 4 deletions todo.md
@@ -1,7 +1,3 @@
# next

- RUSTFLAGS="--cap-lints=warn"

# not next

- custom toolchain support via rust-lang-ci
Expand Down

0 comments on commit a5a7b14

Please sign in to comment.