]> git.lizzy.rs Git - rust.git/blob - src/tools/cargotest/main.rs
Rollup merge of #64801 - nnethercote:improve-find_constraint_paths_between_regions...
[rust.git] / src / tools / cargotest / main.rs
1 #![deny(warnings)]
2
3 use std::env;
4 use std::process::Command;
5 use std::path::{Path, PathBuf};
6 use std::fs;
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")
97                          .arg("init")
98                          .arg(&out_dir)
99                          .status()
100                          .expect("");
101         assert!(status.success());
102     }
103
104     // Try progressively deeper fetch depths to find the commit
105     let mut found = false;
106     for depth in &[0, 1, 10, 100, 1000, 100000] {
107         if *depth > 0 {
108             let status = Command::new("git")
109                              .arg("fetch")
110                              .arg(test.repo)
111                              .arg("master")
112                              .arg(&format!("--depth={}", depth))
113                              .current_dir(&out_dir)
114                              .status()
115                              .expect("");
116             assert!(status.success());
117         }
118
119         let status = Command::new("git")
120                          .arg("reset")
121                          .arg(test.sha)
122                          .arg("--hard")
123                          .current_dir(&out_dir)
124                          .status()
125                          .expect("");
126
127         if status.success() {
128             found = true;
129             break;
130         }
131     }
132
133     if !found {
134         panic!("unable to find commit {}", test.sha)
135     }
136     let status = Command::new("git")
137                      .arg("clean")
138                      .arg("-fdx")
139                      .current_dir(&out_dir)
140                      .status()
141                      .unwrap();
142     assert!(status.success());
143
144     out_dir
145 }
146
147 fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool {
148     let mut command = Command::new(cargo_path);
149     command.arg("test");
150     for name in packages {
151         command.arg("-p").arg(name);
152     }
153     let status = command
154         // Disable rust-lang/cargo's cross-compile tests
155         .env("CFG_DISABLE_CROSS_TESTS", "1")
156         // Relax #![deny(warnings)] in some crates
157         .env("RUSTFLAGS", "--cap-lints warn")
158         .current_dir(crate_path)
159         .status()
160         .expect("");
161
162     status.success()
163 }