]>
Commit | Line | Data |
---|---|---|
54a0048b SL |
1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
476ff2be | 11 | //! Implementation of the test-related targets of the build system. |
a7813a04 XL |
12 | //! |
13 | //! This file implements the various regression test suites that we execute on | |
14 | //! our CI. | |
54a0048b | 15 | |
476ff2be SL |
16 | extern crate build_helper; |
17 | ||
c30ab7b3 | 18 | use std::collections::HashSet; |
a7813a04 | 19 | use std::env; |
476ff2be | 20 | use std::fmt; |
c30ab7b3 | 21 | use std::fs; |
a7813a04 XL |
22 | use std::path::{PathBuf, Path}; |
23 | use std::process::Command; | |
24 | ||
25 | use build_helper::output; | |
a7813a04 | 26 | |
5bcae85e | 27 | use {Build, Compiler, Mode}; |
476ff2be | 28 | use dist; |
8bb4bdeb | 29 | use util::{self, dylib_path, dylib_path_var, exe}; |
3157f602 | 30 | |
7cac9316 | 31 | const ADB_TEST_DIR: &'static str = "/data/tmp/work"; |
a7813a04 | 32 | |
476ff2be SL |
33 | /// The two modes of the test runner; tests or benchmarks. |
34 | #[derive(Copy, Clone)] | |
35 | pub enum TestKind { | |
36 | /// Run `cargo test` | |
37 | Test, | |
38 | /// Run `cargo bench` | |
39 | Bench, | |
40 | } | |
41 | ||
42 | impl TestKind { | |
43 | // Return the cargo subcommand for this test kind | |
44 | fn subcommand(self) -> &'static str { | |
45 | match self { | |
46 | TestKind::Test => "test", | |
47 | TestKind::Bench => "bench", | |
48 | } | |
49 | } | |
50 | } | |
51 | ||
52 | impl fmt::Display for TestKind { | |
53 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
54 | f.write_str(match *self { | |
55 | TestKind::Test => "Testing", | |
56 | TestKind::Bench => "Benchmarking", | |
57 | }) | |
58 | } | |
59 | } | |
60 | ||
7cac9316 XL |
61 | fn try_run(build: &Build, cmd: &mut Command) { |
62 | if build.flags.cmd.no_fail_fast() { | |
63 | if !build.try_run(cmd) { | |
64 | let failures = build.delayed_failures.get(); | |
65 | build.delayed_failures.set(failures + 1); | |
66 | } | |
67 | } else { | |
68 | build.run(cmd); | |
69 | } | |
70 | } | |
71 | ||
72 | fn try_run_quiet(build: &Build, cmd: &mut Command) { | |
73 | if build.flags.cmd.no_fail_fast() { | |
74 | if !build.try_run_quiet(cmd) { | |
75 | let failures = build.delayed_failures.get(); | |
76 | build.delayed_failures.set(failures + 1); | |
77 | } | |
78 | } else { | |
79 | build.run_quiet(cmd); | |
80 | } | |
81 | } | |
82 | ||
a7813a04 XL |
83 | /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler. |
84 | /// | |
85 | /// This tool in `src/tools` will verify the validity of all our links in the | |
86 | /// documentation to ensure we don't have a bunch of dead ones. | |
32a655c1 SL |
87 | pub fn linkcheck(build: &Build, host: &str) { |
88 | println!("Linkcheck ({})", host); | |
89 | let compiler = Compiler::new(0, host); | |
476ff2be SL |
90 | |
91 | let _time = util::timeit(); | |
7cac9316 XL |
92 | try_run(build, build.tool_cmd(&compiler, "linkchecker") |
93 | .arg(build.out.join(host).join("doc"))); | |
54a0048b SL |
94 | } |
95 | ||
a7813a04 XL |
96 | /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler. |
97 | /// | |
98 | /// This tool in `src/tools` will check out a few Rust projects and run `cargo | |
99 | /// test` to ensure that we don't regress the test suites there. | |
54a0048b | 100 | pub fn cargotest(build: &Build, stage: u32, host: &str) { |
54a0048b SL |
101 | let ref compiler = Compiler::new(stage, host); |
102 | ||
a7813a04 XL |
103 | // Note that this is a short, cryptic, and not scoped directory name. This |
104 | // is currently to minimize the length of path on Windows where we otherwise | |
105 | // quickly run into path name limit constraints. | |
106 | let out_dir = build.out.join("ct"); | |
107 | t!(fs::create_dir_all(&out_dir)); | |
108 | ||
476ff2be | 109 | let _time = util::timeit(); |
32a655c1 SL |
110 | let mut cmd = Command::new(build.tool(&Compiler::new(0, host), "cargotest")); |
111 | build.prepare_tool_cmd(compiler, &mut cmd); | |
7cac9316 XL |
112 | try_run(build, cmd.arg(&build.cargo) |
113 | .arg(&out_dir) | |
114 | .env("RUSTC", build.compiler_path(compiler)) | |
115 | .env("RUSTDOC", build.rustdoc(compiler))); | |
116 | } | |
117 | ||
118 | /// Runs `cargo test` for `cargo` packaged with Rust. | |
119 | pub fn cargo(build: &Build, stage: u32, host: &str) { | |
120 | let ref compiler = Compiler::new(stage, host); | |
121 | ||
122 | // Configure PATH to find the right rustc. NB. we have to use PATH | |
123 | // and not RUSTC because the Cargo test suite has tests that will | |
124 | // fail if rustc is not spelled `rustc`. | |
125 | let path = build.sysroot(compiler).join("bin"); | |
126 | let old_path = ::std::env::var("PATH").expect(""); | |
127 | let sep = if cfg!(windows) { ";" } else {":" }; | |
128 | let ref newpath = format!("{}{}{}", path.display(), sep, old_path); | |
129 | ||
130 | let mut cargo = build.cargo(compiler, Mode::Tool, host, "test"); | |
131 | cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml")); | |
132 | if build.flags.cmd.no_fail_fast() { | |
133 | cargo.arg("--no-fail-fast"); | |
134 | } | |
135 | ||
136 | // Don't build tests dynamically, just a pain to work with | |
137 | cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); | |
138 | ||
139 | // Don't run cross-compile tests, we may not have cross-compiled libstd libs | |
140 | // available. | |
141 | cargo.env("CFG_DISABLE_CROSS_TESTS", "1"); | |
142 | ||
143 | try_run(build, cargo.env("PATH", newpath)); | |
a7813a04 XL |
144 | } |
145 | ||
146 | /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler. | |
147 | /// | |
148 | /// This tool in `src/tools` checks up on various bits and pieces of style and | |
149 | /// otherwise just implements a few lint-like checks that are specific to the | |
150 | /// compiler itself. | |
32a655c1 | 151 | pub fn tidy(build: &Build, host: &str) { |
7cac9316 | 152 | let _folder = build.fold_output(|| "tidy"); |
32a655c1 SL |
153 | println!("tidy check ({})", host); |
154 | let compiler = Compiler::new(0, host); | |
8bb4bdeb XL |
155 | let mut cmd = build.tool_cmd(&compiler, "tidy"); |
156 | cmd.arg(build.src.join("src")); | |
157 | if !build.config.vendor { | |
158 | cmd.arg("--no-vendor"); | |
159 | } | |
7cac9316 XL |
160 | if build.config.quiet_tests { |
161 | cmd.arg("--quiet"); | |
162 | } | |
163 | try_run(build, &mut cmd); | |
a7813a04 XL |
164 | } |
165 | ||
166 | fn testdir(build: &Build, host: &str) -> PathBuf { | |
167 | build.out.join(host).join("test") | |
168 | } | |
169 | ||
170 | /// Executes the `compiletest` tool to run a suite of tests. | |
171 | /// | |
172 | /// Compiles all tests with `compiler` for `target` with the specified | |
173 | /// compiletest `mode` and `suite` arguments. For example `mode` can be | |
174 | /// "run-pass" or `suite` can be something like `debuginfo`. | |
175 | pub fn compiletest(build: &Build, | |
176 | compiler: &Compiler, | |
177 | target: &str, | |
178 | mode: &str, | |
179 | suite: &str) { | |
7cac9316 | 180 | let _folder = build.fold_output(|| format!("test_{}", suite)); |
476ff2be SL |
181 | println!("Check compiletest suite={} mode={} ({} -> {})", |
182 | suite, mode, compiler.host, target); | |
32a655c1 SL |
183 | let mut cmd = Command::new(build.tool(&Compiler::new(0, compiler.host), |
184 | "compiletest")); | |
185 | build.prepare_tool_cmd(compiler, &mut cmd); | |
a7813a04 XL |
186 | |
187 | // compiletest currently has... a lot of arguments, so let's just pass all | |
188 | // of them! | |
189 | ||
190 | cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler)); | |
191 | cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target)); | |
192 | cmd.arg("--rustc-path").arg(build.compiler_path(compiler)); | |
193 | cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler)); | |
194 | cmd.arg("--src-base").arg(build.src.join("src/test").join(suite)); | |
195 | cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite)); | |
196 | cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target)); | |
197 | cmd.arg("--mode").arg(mode); | |
198 | cmd.arg("--target").arg(target); | |
199 | cmd.arg("--host").arg(compiler.host); | |
200 | cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.config.build)); | |
201 | ||
c30ab7b3 SL |
202 | if let Some(nodejs) = build.config.nodejs.as_ref() { |
203 | cmd.arg("--nodejs").arg(nodejs); | |
204 | } | |
205 | ||
3157f602 | 206 | let mut flags = vec!["-Crpath".to_string()]; |
a7813a04 | 207 | if build.config.rust_optimize_tests { |
3157f602 | 208 | flags.push("-O".to_string()); |
a7813a04 XL |
209 | } |
210 | if build.config.rust_debuginfo_tests { | |
3157f602 | 211 | flags.push("-g".to_string()); |
a7813a04 XL |
212 | } |
213 | ||
3157f602 XL |
214 | let mut hostflags = build.rustc_flags(&compiler.host); |
215 | hostflags.extend(flags.clone()); | |
216 | cmd.arg("--host-rustcflags").arg(hostflags.join(" ")); | |
a7813a04 | 217 | |
3157f602 XL |
218 | let mut targetflags = build.rustc_flags(&target); |
219 | targetflags.extend(flags); | |
220 | targetflags.push(format!("-Lnative={}", | |
221 | build.test_helpers_out(target).display())); | |
222 | cmd.arg("--target-rustcflags").arg(targetflags.join(" ")); | |
a7813a04 | 223 | |
476ff2be | 224 | cmd.arg("--docck-python").arg(build.python()); |
a7813a04 XL |
225 | |
226 | if build.config.build.ends_with("apple-darwin") { | |
cc61c64b | 227 | // Force /usr/bin/python on macOS for LLDB tests because we're loading the |
a7813a04 XL |
228 | // LLDB plugin's compiled module which only works with the system python |
229 | // (namely not Homebrew-installed python) | |
230 | cmd.arg("--lldb-python").arg("/usr/bin/python"); | |
231 | } else { | |
476ff2be | 232 | cmd.arg("--lldb-python").arg(build.python()); |
a7813a04 XL |
233 | } |
234 | ||
c30ab7b3 SL |
235 | if let Some(ref gdb) = build.config.gdb { |
236 | cmd.arg("--gdb").arg(gdb); | |
a7813a04 XL |
237 | } |
238 | if let Some(ref vers) = build.lldb_version { | |
239 | cmd.arg("--lldb-version").arg(vers); | |
240 | } | |
241 | if let Some(ref dir) = build.lldb_python_dir { | |
242 | cmd.arg("--lldb-python-dir").arg(dir); | |
243 | } | |
9e0c209e SL |
244 | let llvm_config = build.llvm_config(target); |
245 | let llvm_version = output(Command::new(&llvm_config).arg("--version")); | |
246 | cmd.arg("--llvm-version").arg(llvm_version); | |
a7813a04 | 247 | |
c30ab7b3 | 248 | cmd.args(&build.flags.cmd.test_args()); |
a7813a04 | 249 | |
32a655c1 | 250 | if build.config.verbose() || build.flags.verbose() { |
a7813a04 XL |
251 | cmd.arg("--verbose"); |
252 | } | |
253 | ||
c30ab7b3 SL |
254 | if build.config.quiet_tests { |
255 | cmd.arg("--quiet"); | |
256 | } | |
257 | ||
a7813a04 XL |
258 | // Only pass correct values for these flags for the `run-make` suite as it |
259 | // requires that a C++ compiler was configured which isn't always the case. | |
260 | if suite == "run-make" { | |
a7813a04 XL |
261 | let llvm_components = output(Command::new(&llvm_config).arg("--components")); |
262 | let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags")); | |
263 | cmd.arg("--cc").arg(build.cc(target)) | |
264 | .arg("--cxx").arg(build.cxx(target)) | |
265 | .arg("--cflags").arg(build.cflags(target).join(" ")) | |
266 | .arg("--llvm-components").arg(llvm_components.trim()) | |
267 | .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim()); | |
268 | } else { | |
269 | cmd.arg("--cc").arg("") | |
270 | .arg("--cxx").arg("") | |
271 | .arg("--cflags").arg("") | |
272 | .arg("--llvm-components").arg("") | |
273 | .arg("--llvm-cxxflags").arg(""); | |
274 | } | |
275 | ||
7cac9316 XL |
276 | if build.remote_tested(target) { |
277 | cmd.arg("--remote-test-client") | |
8bb4bdeb | 278 | .arg(build.tool(&Compiler::new(0, &build.config.build), |
7cac9316 | 279 | "remote-test-client")); |
8bb4bdeb XL |
280 | } |
281 | ||
a7813a04 XL |
282 | // Running a C compiler on MSVC requires a few env vars to be set, to be |
283 | // sure to set them here. | |
476ff2be SL |
284 | // |
285 | // Note that if we encounter `PATH` we make sure to append to our own `PATH` | |
286 | // rather than stomp over it. | |
a7813a04 XL |
287 | if target.contains("msvc") { |
288 | for &(ref k, ref v) in build.cc[target].0.env() { | |
289 | if k != "PATH" { | |
290 | cmd.env(k, v); | |
291 | } | |
292 | } | |
293 | } | |
476ff2be SL |
294 | cmd.env("RUSTC_BOOTSTRAP", "1"); |
295 | build.add_rust_test_threads(&mut cmd); | |
a7813a04 | 296 | |
8bb4bdeb XL |
297 | if build.config.sanitizers { |
298 | cmd.env("SANITIZER_SUPPORT", "1"); | |
299 | } | |
300 | ||
3157f602 XL |
301 | cmd.arg("--adb-path").arg("adb"); |
302 | cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR); | |
303 | if target.contains("android") { | |
304 | // Assume that cc for this target comes from the android sysroot | |
305 | cmd.arg("--android-cross-path") | |
306 | .arg(build.cc(target).parent().unwrap().parent().unwrap()); | |
307 | } else { | |
308 | cmd.arg("--android-cross-path").arg(""); | |
309 | } | |
310 | ||
7cac9316 XL |
311 | build.ci_env.force_coloring_in_ci(&mut cmd); |
312 | ||
476ff2be | 313 | let _time = util::timeit(); |
7cac9316 | 314 | try_run(build, &mut cmd); |
a7813a04 XL |
315 | } |
316 | ||
317 | /// Run `rustdoc --test` for all documentation in `src/doc`. | |
318 | /// | |
319 | /// This will run all tests in our markdown documentation (e.g. the book) | |
320 | /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to | |
321 | /// `compiler`. | |
322 | pub fn docs(build: &Build, compiler: &Compiler) { | |
323 | // Do a breadth-first traversal of the `src/doc` directory and just run | |
324 | // tests for all files that end in `*.md` | |
325 | let mut stack = vec![build.src.join("src/doc")]; | |
476ff2be | 326 | let _time = util::timeit(); |
7cac9316 | 327 | let _folder = build.fold_output(|| "test_docs"); |
a7813a04 XL |
328 | |
329 | while let Some(p) = stack.pop() { | |
330 | if p.is_dir() { | |
331 | stack.extend(t!(p.read_dir()).map(|p| t!(p).path())); | |
332 | continue | |
333 | } | |
334 | ||
335 | if p.extension().and_then(|s| s.to_str()) != Some("md") { | |
336 | continue | |
337 | } | |
338 | ||
cc61c64b XL |
339 | // The nostarch directory in the book is for no starch, and so isn't guaranteed to build. |
340 | // we don't care if it doesn't build, so skip it. | |
341 | use std::ffi::OsStr; | |
342 | let path: &OsStr = p.as_ref(); | |
343 | if let Some(path) = path.to_str() { | |
344 | if path.contains("nostarch") { | |
345 | continue; | |
346 | } | |
347 | } | |
348 | ||
a7813a04 XL |
349 | println!("doc tests for: {}", p.display()); |
350 | markdown_test(build, compiler, &p); | |
351 | } | |
352 | } | |
353 | ||
354 | /// Run the error index generator tool to execute the tests located in the error | |
355 | /// index. | |
356 | /// | |
357 | /// The `error_index_generator` tool lives in `src/tools` and is used to | |
358 | /// generate a markdown file from the error indexes of the code base which is | |
359 | /// then passed to `rustdoc --test`. | |
360 | pub fn error_index(build: &Build, compiler: &Compiler) { | |
7cac9316 | 361 | let _folder = build.fold_output(|| "test_error_index"); |
a7813a04 XL |
362 | println!("Testing error-index stage{}", compiler.stage); |
363 | ||
476ff2be SL |
364 | let dir = testdir(build, compiler.host); |
365 | t!(fs::create_dir_all(&dir)); | |
366 | let output = dir.join("error-index.md"); | |
367 | ||
368 | let _time = util::timeit(); | |
32a655c1 SL |
369 | build.run(build.tool_cmd(&Compiler::new(0, compiler.host), |
370 | "error_index_generator") | |
a7813a04 XL |
371 | .arg("markdown") |
372 | .arg(&output) | |
373 | .env("CFG_BUILD", &build.config.build)); | |
374 | ||
375 | markdown_test(build, compiler, &output); | |
376 | } | |
377 | ||
378 | fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) { | |
379 | let mut cmd = Command::new(build.rustdoc(compiler)); | |
380 | build.add_rustc_lib_path(compiler, &mut cmd); | |
476ff2be | 381 | build.add_rust_test_threads(&mut cmd); |
a7813a04 XL |
382 | cmd.arg("--test"); |
383 | cmd.arg(markdown); | |
476ff2be | 384 | cmd.env("RUSTC_BOOTSTRAP", "1"); |
c30ab7b3 | 385 | |
7cac9316 | 386 | let test_args = build.flags.cmd.test_args().join(" "); |
c30ab7b3 SL |
387 | cmd.arg("--test-args").arg(test_args); |
388 | ||
7cac9316 XL |
389 | if build.config.quiet_tests { |
390 | try_run_quiet(build, &mut cmd); | |
391 | } else { | |
392 | try_run(build, &mut cmd); | |
393 | } | |
a7813a04 XL |
394 | } |
395 | ||
396 | /// Run all unit tests plus documentation tests for an entire crate DAG defined | |
397 | /// by a `Cargo.toml` | |
398 | /// | |
399 | /// This is what runs tests for crates like the standard library, compiler, etc. | |
400 | /// It essentially is the driver for running `cargo test`. | |
401 | /// | |
402 | /// Currently this runs all tests for a DAG by passing a bunch of `-p foo` | |
c30ab7b3 | 403 | /// arguments, and those arguments are discovered from `cargo metadata`. |
a7813a04 XL |
404 | pub fn krate(build: &Build, |
405 | compiler: &Compiler, | |
406 | target: &str, | |
c30ab7b3 | 407 | mode: Mode, |
476ff2be | 408 | test_kind: TestKind, |
c30ab7b3 SL |
409 | krate: Option<&str>) { |
410 | let (name, path, features, root) = match mode { | |
411 | Mode::Libstd => { | |
8bb4bdeb | 412 | ("libstd", "src/libstd", build.std_features(), "std") |
c30ab7b3 SL |
413 | } |
414 | Mode::Libtest => { | |
8bb4bdeb | 415 | ("libtest", "src/libtest", String::new(), "test") |
c30ab7b3 SL |
416 | } |
417 | Mode::Librustc => { | |
418 | ("librustc", "src/rustc", build.rustc_features(), "rustc-main") | |
419 | } | |
a7813a04 XL |
420 | _ => panic!("can only test libraries"), |
421 | }; | |
7cac9316 XL |
422 | let _folder = build.fold_output(|| { |
423 | format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name) | |
424 | }); | |
476ff2be | 425 | println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage, |
a7813a04 XL |
426 | compiler.host, target); |
427 | ||
32a655c1 SL |
428 | // If we're not doing a full bootstrap but we're testing a stage2 version of |
429 | // libstd, then what we're actually testing is the libstd produced in | |
430 | // stage1. Reflect that here by updating the compiler that we're working | |
431 | // with automatically. | |
432 | let compiler = if build.force_use_stage1(compiler, target) { | |
433 | Compiler::new(1, compiler.host) | |
434 | } else { | |
435 | compiler.clone() | |
436 | }; | |
437 | ||
a7813a04 | 438 | // Build up the base `cargo test` command. |
c30ab7b3 SL |
439 | // |
440 | // Pass in some standard flags then iterate over the graph we've discovered | |
441 | // in `cargo metadata` with the maps above and figure out what `-p` | |
442 | // arguments need to get passed. | |
32a655c1 | 443 | let mut cargo = build.cargo(&compiler, mode, target, test_kind.subcommand()); |
a7813a04 XL |
444 | cargo.arg("--manifest-path") |
445 | .arg(build.src.join(path).join("Cargo.toml")) | |
446 | .arg("--features").arg(features); | |
7cac9316 XL |
447 | if test_kind.subcommand() == "test" && build.flags.cmd.no_fail_fast() { |
448 | cargo.arg("--no-fail-fast"); | |
449 | } | |
a7813a04 | 450 | |
c30ab7b3 SL |
451 | match krate { |
452 | Some(krate) => { | |
453 | cargo.arg("-p").arg(krate); | |
a7813a04 | 454 | } |
c30ab7b3 SL |
455 | None => { |
456 | let mut visited = HashSet::new(); | |
457 | let mut next = vec![root]; | |
458 | while let Some(name) = next.pop() { | |
32a655c1 SL |
459 | // Right now jemalloc is our only target-specific crate in the |
460 | // sense that it's not present on all platforms. Custom skip it | |
461 | // here for now, but if we add more this probably wants to get | |
462 | // more generalized. | |
463 | // | |
464 | // Also skip `build_helper` as it's not compiled normally for | |
465 | // target during the bootstrap and it's just meant to be a | |
466 | // helper crate, not tested. If it leaks through then it ends up | |
467 | // messing with various mtime calculations and such. | |
468 | if !name.contains("jemalloc") && name != "build_helper" { | |
8bb4bdeb | 469 | cargo.arg("-p").arg(&format!("{}:0.0.0", name)); |
c30ab7b3 SL |
470 | } |
471 | for dep in build.crates[name].deps.iter() { | |
472 | if visited.insert(dep) { | |
473 | next.push(dep); | |
474 | } | |
475 | } | |
a7813a04 XL |
476 | } |
477 | } | |
a7813a04 XL |
478 | } |
479 | ||
480 | // The tests are going to run with the *target* libraries, so we need to | |
481 | // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent. | |
482 | // | |
483 | // Note that to run the compiler we need to run with the *host* libraries, | |
484 | // but our wrapper scripts arrange for that to be the case anyway. | |
485 | let mut dylib_path = dylib_path(); | |
32a655c1 | 486 | dylib_path.insert(0, build.sysroot_libdir(&compiler, target)); |
a7813a04 | 487 | cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap()); |
a7813a04 | 488 | |
7cac9316 | 489 | if target.contains("emscripten") || build.remote_tested(target) { |
476ff2be SL |
490 | cargo.arg("--no-run"); |
491 | } | |
492 | ||
493 | cargo.arg("--"); | |
494 | ||
c30ab7b3 | 495 | if build.config.quiet_tests { |
c30ab7b3 SL |
496 | cargo.arg("--quiet"); |
497 | } | |
498 | ||
476ff2be SL |
499 | let _time = util::timeit(); |
500 | ||
7cac9316 | 501 | if target.contains("emscripten") { |
476ff2be | 502 | build.run(&mut cargo); |
32a655c1 | 503 | krate_emscripten(build, &compiler, target, mode); |
7cac9316 | 504 | } else if build.remote_tested(target) { |
8bb4bdeb | 505 | build.run(&mut cargo); |
7cac9316 | 506 | krate_remote(build, &compiler, target, mode); |
3157f602 | 507 | } else { |
c30ab7b3 | 508 | cargo.args(&build.flags.cmd.test_args()); |
7cac9316 | 509 | try_run(build, &mut cargo); |
3157f602 XL |
510 | } |
511 | } | |
512 | ||
c30ab7b3 SL |
513 | fn krate_emscripten(build: &Build, |
514 | compiler: &Compiler, | |
515 | target: &str, | |
516 | mode: Mode) { | |
8bb4bdeb XL |
517 | let mut tests = Vec::new(); |
518 | let out_dir = build.cargo_out(compiler, mode, target); | |
8bb4bdeb XL |
519 | find_tests(&out_dir.join("deps"), target, &mut tests); |
520 | ||
521 | for test in tests { | |
522 | let test_file_name = test.to_string_lossy().into_owned(); | |
523 | println!("running {}", test_file_name); | |
524 | let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured"); | |
525 | let mut cmd = Command::new(nodejs); | |
526 | cmd.arg(&test_file_name); | |
527 | if build.config.quiet_tests { | |
528 | cmd.arg("--quiet"); | |
529 | } | |
7cac9316 | 530 | try_run(build, &mut cmd); |
8bb4bdeb XL |
531 | } |
532 | } | |
533 | ||
7cac9316 XL |
534 | fn krate_remote(build: &Build, |
535 | compiler: &Compiler, | |
536 | target: &str, | |
537 | mode: Mode) { | |
8bb4bdeb XL |
538 | let mut tests = Vec::new(); |
539 | let out_dir = build.cargo_out(compiler, mode, target); | |
8bb4bdeb XL |
540 | find_tests(&out_dir.join("deps"), target, &mut tests); |
541 | ||
542 | let tool = build.tool(&Compiler::new(0, &build.config.build), | |
7cac9316 | 543 | "remote-test-client"); |
8bb4bdeb XL |
544 | for test in tests { |
545 | let mut cmd = Command::new(&tool); | |
546 | cmd.arg("run") | |
547 | .arg(&test); | |
548 | if build.config.quiet_tests { | |
549 | cmd.arg("--quiet"); | |
550 | } | |
551 | cmd.args(&build.flags.cmd.test_args()); | |
7cac9316 | 552 | try_run(build, &mut cmd); |
8bb4bdeb XL |
553 | } |
554 | } | |
c30ab7b3 | 555 | |
3157f602 XL |
556 | fn find_tests(dir: &Path, |
557 | target: &str, | |
558 | dst: &mut Vec<PathBuf>) { | |
559 | for e in t!(dir.read_dir()).map(|e| t!(e)) { | |
560 | let file_type = t!(e.file_type()); | |
561 | if !file_type.is_file() { | |
562 | continue | |
563 | } | |
564 | let filename = e.file_name().into_string().unwrap(); | |
565 | if (target.contains("windows") && filename.ends_with(".exe")) || | |
c30ab7b3 | 566 | (!target.contains("windows") && !filename.contains(".")) || |
8bb4bdeb | 567 | (target.contains("emscripten") && filename.ends_with(".js")) { |
3157f602 XL |
568 | dst.push(e.path()); |
569 | } | |
570 | } | |
571 | } | |
572 | ||
7cac9316 XL |
573 | pub fn remote_copy_libs(build: &Build, compiler: &Compiler, target: &str) { |
574 | if !build.remote_tested(target) { | |
575 | return | |
3157f602 | 576 | } |
476ff2be | 577 | |
7cac9316 | 578 | println!("REMOTE copy libs to emulator ({})", target); |
8bb4bdeb XL |
579 | t!(fs::create_dir_all(build.out.join("tmp"))); |
580 | ||
8bb4bdeb | 581 | let server = build.cargo_out(compiler, Mode::Tool, target) |
7cac9316 | 582 | .join(exe("remote-test-server", target)); |
8bb4bdeb XL |
583 | |
584 | // Spawn the emulator and wait for it to come online | |
585 | let tool = build.tool(&Compiler::new(0, &build.config.build), | |
7cac9316 XL |
586 | "remote-test-client"); |
587 | let mut cmd = Command::new(&tool); | |
588 | cmd.arg("spawn-emulator") | |
589 | .arg(target) | |
590 | .arg(&server) | |
591 | .arg(build.out.join("tmp")); | |
592 | if let Some(rootfs) = build.qemu_rootfs(target) { | |
593 | cmd.arg(rootfs); | |
594 | } | |
595 | build.run(&mut cmd); | |
8bb4bdeb XL |
596 | |
597 | // Push all our dylibs to the emulator | |
598 | for f in t!(build.sysroot_libdir(compiler, target).read_dir()) { | |
599 | let f = t!(f); | |
600 | let name = f.file_name().into_string().unwrap(); | |
601 | if util::is_dylib(&name) { | |
602 | build.run(Command::new(&tool) | |
603 | .arg("push") | |
604 | .arg(f.path())); | |
605 | } | |
606 | } | |
607 | } | |
608 | ||
476ff2be SL |
609 | /// Run "distcheck", a 'make check' from a tarball |
610 | pub fn distcheck(build: &Build) { | |
611 | if build.config.build != "x86_64-unknown-linux-gnu" { | |
612 | return | |
613 | } | |
614 | if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") { | |
615 | return | |
616 | } | |
617 | if !build.config.target.iter().any(|s| s == "x86_64-unknown-linux-gnu") { | |
618 | return | |
619 | } | |
620 | ||
7cac9316 | 621 | println!("Distcheck"); |
476ff2be SL |
622 | let dir = build.out.join("tmp").join("distcheck"); |
623 | let _ = fs::remove_dir_all(&dir); | |
624 | t!(fs::create_dir_all(&dir)); | |
625 | ||
626 | let mut cmd = Command::new("tar"); | |
627 | cmd.arg("-xzf") | |
628 | .arg(dist::rust_src_location(build)) | |
629 | .arg("--strip-components=1") | |
630 | .current_dir(&dir); | |
631 | build.run(&mut cmd); | |
632 | build.run(Command::new("./configure") | |
32a655c1 | 633 | .args(&build.config.configure_args) |
8bb4bdeb | 634 | .arg("--enable-vendor") |
476ff2be SL |
635 | .current_dir(&dir)); |
636 | build.run(Command::new(build_helper::make(&build.config.build)) | |
637 | .arg("check") | |
638 | .current_dir(&dir)); | |
7cac9316 XL |
639 | |
640 | // Now make sure that rust-src has all of libstd's dependencies | |
641 | println!("Distcheck rust-src"); | |
642 | let dir = build.out.join("tmp").join("distcheck-src"); | |
643 | let _ = fs::remove_dir_all(&dir); | |
644 | t!(fs::create_dir_all(&dir)); | |
645 | ||
646 | let mut cmd = Command::new("tar"); | |
647 | cmd.arg("-xzf") | |
648 | .arg(dist::rust_src_installer(build)) | |
649 | .arg("--strip-components=1") | |
650 | .current_dir(&dir); | |
651 | build.run(&mut cmd); | |
652 | ||
653 | let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml"); | |
654 | build.run(Command::new(&build.cargo) | |
655 | .arg("generate-lockfile") | |
656 | .arg("--manifest-path") | |
657 | .arg(&toml) | |
658 | .current_dir(&dir)); | |
476ff2be | 659 | } |
32a655c1 SL |
660 | |
661 | /// Test the build system itself | |
662 | pub fn bootstrap(build: &Build) { | |
663 | let mut cmd = Command::new(&build.cargo); | |
664 | cmd.arg("test") | |
665 | .current_dir(build.src.join("src/bootstrap")) | |
666 | .env("CARGO_TARGET_DIR", build.out.join("bootstrap")) | |
667 | .env("RUSTC", &build.rustc); | |
7cac9316 XL |
668 | if build.flags.cmd.no_fail_fast() { |
669 | cmd.arg("--no-fail-fast"); | |
670 | } | |
32a655c1 | 671 | cmd.arg("--").args(&build.flags.cmd.test_args()); |
7cac9316 | 672 | try_run(build, &mut cmd); |
32a655c1 | 673 | } |