Skip to content

Commit 1d3eba4

Browse files
authored
Merge pull request #300 from pietroalbini/toolchain-refactoring
Toolchain refactorings
2 parents 49d709a + 8bc36aa commit 1d3eba4

File tree

14 files changed

+434
-203
lines changed

14 files changed

+434
-203
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ walkdir = "2"
5050
winapi = "0.3"
5151
regex = "0.2.10"
5252
ring = "0.12.1"
53-
rusqlite = { version = "0.13.0", features = ["chrono", "bundled"] }
53+
rusqlite = { version = "0.14.0", features = ["chrono", "functions", "bundled"] }
5454
r2d2 = "0.8.2"
55-
r2d2_sqlite = "0.5.0"
55+
r2d2_sqlite = "0.5.1"
5656
base64 = "0.9.0"
5757
tera = "0.11.7"
5858
minifier = "0.0.11"

src/cli.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crater::report;
2222
use crater::results::FileDB;
2323
use crater::run_graph;
2424
use crater::server;
25-
use crater::toolchain::Toolchain;
25+
use crater::toolchain::{Toolchain, MAIN_TOOLCHAIN};
2626
use std::env;
2727
use std::path::PathBuf;
2828
use std::str::FromStr;
@@ -246,8 +246,7 @@ impl Crater {
246246
Crater::CreateLists => lists::create_all_lists(true)?,
247247
Crater::PrepareLocal { ref env } => {
248248
let docker_env = &env.0;
249-
let stable_tc = Toolchain::Dist("stable".into());
250-
stable_tc.prepare()?;
249+
MAIN_TOOLCHAIN.prepare()?;
251250
docker::build_container(docker_env)?;
252251
lists::create_all_lists(false)?;
253252
}
@@ -264,7 +263,7 @@ impl Crater {
264263
ex::define(
265264
ex::ExOpts {
266265
name: ex.0.clone(),
267-
toolchains: vec![tc1.clone(), tc2.clone()],
266+
toolchains: [tc1.clone(), tc2.clone()],
268267
mode: *mode,
269268
crates: *crates,
270269
cap_lints: *cap_lints,

src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,13 @@ error_chain! {
4242
ServerUnavailable {
4343
description("the server is not available at the moment")
4444
}
45+
46+
EmptyToolchainName {
47+
description("empty toolchain name")
48+
}
49+
InvalidToolchainSourceName(name: String) {
50+
description("invalid toolchain source name")
51+
display("invalid toolchain source name: {}", name)
52+
}
4553
}
4654
}

src/ex.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ fn froml_path(ex_name: &str, name: &str, vers: &str) -> PathBuf {
5656
pub struct Experiment {
5757
pub name: String,
5858
pub crates: Vec<Crate>,
59-
pub toolchains: Vec<Toolchain>,
59+
pub toolchains: [Toolchain; 2],
6060
pub mode: ExMode,
6161
pub cap_lints: ExCapLints,
6262
}
6363

6464
pub struct ExOpts {
6565
pub name: String,
66-
pub toolchains: Vec<Toolchain>,
66+
pub toolchains: [Toolchain; 2],
6767
pub mode: ExMode,
6868
pub crates: ExCrateSelect,
6969
pub cap_lints: ExCapLints,
@@ -141,7 +141,7 @@ fn top_100() -> Result<Vec<Crate>> {
141141

142142
pub fn define_(
143143
ex_name: &str,
144-
toolchains: Vec<Toolchain>,
144+
toolchains: [Toolchain; 2],
145145
crates: Vec<Crate>,
146146
mode: ExMode,
147147
cap_lints: ExCapLints,
@@ -158,6 +158,9 @@ pub fn define_(
158158
mode,
159159
cap_lints,
160160
};
161+
162+
ex.validate()?;
163+
161164
fs::create_dir_all(&ex_dir(&ex.name))?;
162165
let json = serde_json::to_string(&ex)?;
163166
info!("writing ex config to {}", config_file(ex_name).display());
@@ -166,6 +169,14 @@ pub fn define_(
166169
}
167170

168171
impl Experiment {
172+
pub fn validate(&self) -> Result<()> {
173+
if self.toolchains[0] == self.toolchains[1] {
174+
bail!("reusing the same toolchain isn't supported");
175+
}
176+
177+
Ok(())
178+
}
179+
169180
pub fn fetch_repo_crates(&self) -> Result<()> {
170181
for repo in self.crates.iter().filter_map(|krate| krate.github()) {
171182
if let Err(e) = git::shallow_clone_or_pull(&repo.url(), &repo.mirror_dir()) {
@@ -434,3 +445,36 @@ pub fn delete(ex_name: &str) -> Result<()> {
434445

435446
Ok(())
436447
}
448+
449+
#[cfg(test)]
450+
mod tests {
451+
use super::{ExCapLints, ExMode, Experiment};
452+
use toolchain::{MAIN_TOOLCHAIN, TEST_TOOLCHAIN};
453+
454+
#[test]
455+
fn test_validate_experiment() {
456+
// Correct experiment
457+
assert!(
458+
Experiment {
459+
name: "foo".to_string(),
460+
crates: vec![],
461+
toolchains: [MAIN_TOOLCHAIN.clone(), TEST_TOOLCHAIN.clone()],
462+
mode: ExMode::BuildAndTest,
463+
cap_lints: ExCapLints::Forbid,
464+
}.validate()
465+
.is_ok()
466+
);
467+
468+
// Experiment with the same toolchain
469+
assert!(
470+
Experiment {
471+
name: "foo".to_string(),
472+
crates: vec![],
473+
toolchains: [MAIN_TOOLCHAIN.clone(), MAIN_TOOLCHAIN.clone()],
474+
mode: ExMode::BuildAndTest,
475+
cap_lints: ExCapLints::Forbid,
476+
}.validate()
477+
.is_err()
478+
);
479+
}
480+
}

src/report/mod.rs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ struct BuildTestResult {
8282

8383
fn crate_to_path_fragment(toolchain: &Toolchain, krate: &Crate, encode: bool) -> PathBuf {
8484
let mut path = PathBuf::new();
85-
path.push(toolchain.rustup_name());
85+
if encode {
86+
path.push(url_encode(&toolchain.to_string()));
87+
} else {
88+
path.push(toolchain.to_string());
89+
}
8690

8791
match *krate {
8892
Crate::Registry(ref details) => {
@@ -116,8 +120,6 @@ pub fn generate_report<DB: ReadResults>(
116120
ex: &Experiment,
117121
) -> Result<TestResults> {
118122
let shas = db.load_all_shas(ex)?;
119-
assert_eq!(ex.toolchains.len(), 2);
120-
121123
let res = ex
122124
.crates
123125
.clone()
@@ -342,7 +344,7 @@ mod tests {
342344
use ex::{ExCapLints, ExMode, Experiment};
343345
use results::{DummyDB, TestResult};
344346
use std::collections::HashMap;
345-
use toolchain::Toolchain;
347+
use toolchain::{MAIN_TOOLCHAIN, TEST_TOOLCHAIN};
346348

347349
#[derive(Default)]
348350
pub struct DummyWriter {
@@ -394,7 +396,6 @@ mod tests {
394396

395397
#[test]
396398
fn test_crate_to_path_fragment() {
397-
let tc = Toolchain::Dist("stable".into());
398399
let reg = Crate::Registry(RegistryCrate {
399400
name: "lazy_static".into(),
400401
version: "1.0".into(),
@@ -409,19 +410,19 @@ mod tests {
409410
});
410411

411412
assert_eq!(
412-
crate_to_path_fragment(&tc, &reg, false),
413+
crate_to_path_fragment(&MAIN_TOOLCHAIN, &reg, false),
413414
PathBuf::from("stable/reg/lazy_static-1.0")
414415
);
415416
assert_eq!(
416-
crate_to_path_fragment(&tc, &gh, false),
417+
crate_to_path_fragment(&MAIN_TOOLCHAIN, &gh, false),
417418
PathBuf::from("stable/gh/brson.hello-rs")
418419
);
419420
assert_eq!(
420-
crate_to_path_fragment(&tc, &plus, false),
421+
crate_to_path_fragment(&MAIN_TOOLCHAIN, &plus, false),
421422
PathBuf::from("stable/reg/foo-1.0+bar")
422423
);
423424
assert_eq!(
424-
crate_to_path_fragment(&tc, &plus, true),
425+
crate_to_path_fragment(&MAIN_TOOLCHAIN, &plus, true),
425426
PathBuf::from("stable/reg/foo-1.0%2Bbar")
426427
);
427428
}
@@ -559,23 +560,40 @@ mod tests {
559560
};
560561
let gh = Crate::GitHub(repo.clone());
561562

562-
let stable = Toolchain::Dist("stable".to_string());
563-
let beta = Toolchain::Dist("beta".to_string());
564-
565563
let ex = Experiment {
566564
name: "foo".to_string(),
567565
crates: vec![gh.clone()],
568-
toolchains: vec![stable.clone(), beta.clone()],
566+
toolchains: [MAIN_TOOLCHAIN.clone(), TEST_TOOLCHAIN.clone()],
569567
mode: ExMode::BuildAndTest,
570568
cap_lints: ExCapLints::Forbid,
571569
};
572570

573571
let mut db = DummyDB::default();
574572
db.add_dummy_sha(&ex, repo.clone(), "f00".to_string());
575-
db.add_dummy_result(&ex, gh.clone(), stable.clone(), TestResult::TestPass);
576-
db.add_dummy_result(&ex, gh.clone(), beta.clone(), TestResult::BuildFail);
577-
db.add_dummy_log(&ex, gh.clone(), stable.clone(), b"stable log".to_vec());
578-
db.add_dummy_log(&ex, gh.clone(), beta.clone(), b"beta log".to_vec());
573+
db.add_dummy_result(
574+
&ex,
575+
gh.clone(),
576+
MAIN_TOOLCHAIN.clone(),
577+
TestResult::TestPass,
578+
);
579+
db.add_dummy_result(
580+
&ex,
581+
gh.clone(),
582+
TEST_TOOLCHAIN.clone(),
583+
TestResult::BuildFail,
584+
);
585+
db.add_dummy_log(
586+
&ex,
587+
gh.clone(),
588+
MAIN_TOOLCHAIN.clone(),
589+
b"stable log".to_vec(),
590+
);
591+
db.add_dummy_log(
592+
&ex,
593+
gh.clone(),
594+
TEST_TOOLCHAIN.clone(),
595+
b"beta log".to_vec(),
596+
);
579597

580598
let writer = DummyWriter::default();
581599
gen(&db, &ex, &writer, &config).unwrap();

src/results/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl FileDB {
3131

3232
ex_dir(&ex.name)
3333
.join("res")
34-
.join(toolchain.rustup_name())
34+
.join(toolchain.to_string())
3535
.join(crate_path)
3636
}
3737

src/server/agents.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ mod tests {
151151
use server::db::Database;
152152
use server::experiments::Experiments;
153153
use server::tokens::Tokens;
154-
use toolchain::Toolchain;
154+
use toolchain::{MAIN_TOOLCHAIN, TEST_TOOLCHAIN};
155155

156156
#[test]
157157
fn test_agents_synchronize() {
@@ -231,8 +231,8 @@ mod tests {
231231
experiments
232232
.create(
233233
"test".into(),
234-
&Toolchain::Dist("stable".into()),
235-
&Toolchain::Dist("beta".into()),
234+
&MAIN_TOOLCHAIN,
235+
&TEST_TOOLCHAIN,
236236
ExMode::BuildAndTest,
237237
ExCrateSelect::Demo,
238238
ExCapLints::Forbid,

0 commit comments

Comments
 (0)