]> git.lizzy.rs Git - rust.git/blob - src/tools/cargotest/main.rs
Rollup merge of #67527 - GuillaumeGomez:results-show-too-much, r=kinnison
[rust.git] / src / tools / cargotest / main.rs
1 #![deny(warnings)]
2
3 use std::env;
4 use std::fs;
5 use std::path::{Path, PathBuf};
6 use std::process::Command;
7
8 struct Test {
9     repo: &'static str,
10     name: &'static str,
11     sha: &'static str,
12     lock: Option<&'static str>,
13     packages: &'static [&'static str],
14 }
15
16 const TEST_REPOS: &'static [Test] = &[
17     Test {
18         name: "iron",
19         repo: "https://github.com/iron/iron",
20         sha: "cf056ea5e8052c1feea6141e40ab0306715a2c33",
21         lock: None,
22         packages: &[],
23     },
24     Test {
25         name: "ripgrep",
26         repo: "https://github.com/BurntSushi/ripgrep",
27         sha: "ad9befbc1d3b5c695e7f6b6734ee1b8e683edd41",
28         lock: None,
29         packages: &[],
30     },
31     Test {
32         name: "tokei",
33         repo: "https://github.com/XAMPPRocky/tokei",
34         sha: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928",
35         lock: None,
36         packages: &[],
37     },
38     Test {
39         name: "treeify",
40         repo: "https://github.com/dzamlo/treeify",
41         sha: "999001b223152441198f117a68fb81f57bc086dd",
42         lock: None,
43         packages: &[],
44     },
45     Test {
46         name: "xsv",
47         repo: "https://github.com/BurntSushi/xsv",
48         sha: "66956b6bfd62d6ac767a6b6499c982eae20a2c9f",
49         lock: None,
50         packages: &[],
51     },
52     Test {
53         name: "servo",
54         repo: "https://github.com/servo/servo",
55         sha: "caac107ae8145ef2fd20365e2b8fadaf09c2eb3b",
56         lock: None,
57         // Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
58         // This takes much less time to build than all of Servo and supports stable Rust.
59         packages: &["selectors"],
60     },
61     Test {
62         name: "webrender",
63         repo: "https://github.com/servo/webrender",
64         sha: "a3d6e6894c5a601fa547c6273eb963ca1321c2bb",
65         lock: None,
66         packages: &[],
67     },
68 ];
69
70 fn main() {
71     let args = env::args().collect::<Vec<_>>();
72     let ref cargo = args[1];
73     let out_dir = Path::new(&args[2]);
74     let ref cargo = Path::new(cargo);
75
76     for test in TEST_REPOS.iter().rev() {
77         test_repo(cargo, out_dir, test);
78     }
79 }
80
81 fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
82     println!("testing {}", test.repo);
83     let dir = clone_repo(test, out_dir);
84     if let Some(lockfile) = test.lock {
85         fs::write(&dir.join("Cargo.lock"), lockfile).unwrap();
86     }
87     if !run_cargo_test(cargo, &dir, test.packages) {
88         panic!("tests failed for {}", test.repo);
89     }
90 }
91
92 fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
93     let out_dir = out_dir.join(test.name);
94
95     if !out_dir.join(".git").is_dir() {
96         let status = Command::new("git").arg("init").arg(&out_dir).status().expect("");
97         assert!(status.success());
98     }
99
100     // Try progressively deeper fetch depths to find the commit
101     let mut found = false;
102     for depth in &[0, 1, 10, 100, 1000, 100000] {
103         if *depth > 0 {
104             let status = Command::new("git")
105                 .arg("fetch")
106                 .arg(test.repo)
107                 .arg("master")
108                 .arg(&format!("--depth={}", depth))
109                 .current_dir(&out_dir)
110                 .status()
111                 .expect("");
112             assert!(status.success());
113         }
114
115         let status = Command::new("git")
116             .arg("reset")
117             .arg(test.sha)
118             .arg("--hard")
119             .current_dir(&out_dir)
120             .status()
121             .expect("");
122
123         if status.success() {
124             found = true;
125             break;
126         }
127     }
128
129     if !found {
130         panic!("unable to find commit {}", test.sha)
131     }
132     let status =
133         Command::new("git").arg("clean").arg("-fdx").current_dir(&out_dir).status().unwrap();
134     assert!(status.success());
135
136     out_dir
137 }
138
139 fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool {
140     let mut command = Command::new(cargo_path);
141     command.arg("test");
142     for name in packages {
143         command.arg("-p").arg(name);
144     }
145     let status = command
146         // Disable rust-lang/cargo's cross-compile tests
147         .env("CFG_DISABLE_CROSS_TESTS", "1")
148         // Relax #![deny(warnings)] in some crates
149         .env("RUSTFLAGS", "--cap-lints warn")
150         .current_dir(crate_path)
151         .status()
152         .expect("");
153
154     status.success()
155 }