Alex Crichton | defd1b3 | 2016-03-08 07:15:55 | [diff] [blame] | 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 | |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 11 | //! Implementation of the test-related targets of the build system. |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 12 | //! |
| 13 | //! This file implements the various regression test suites that we execute on |
| 14 | //! our CI. |
| 15 | |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 16 | use std::collections::HashSet; |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 17 | use std::env; |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 18 | use std::iter; |
Ulrik Sverdrup | b1566ba | 2016-11-25 21:13:59 | [diff] [blame] | 19 | use std::fmt; |
Mark Simulacrum | dd1d75e | 2017-06-04 23:55:50 | [diff] [blame] | 20 | use std::fs::{self, File}; |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 21 | use std::path::{PathBuf, Path}; |
| 22 | use std::process::Command; |
Mark Simulacrum | dd1d75e | 2017-06-04 23:55:50 | [diff] [blame] | 23 | use std::io::Read; |
Alex Crichton | 73c2d2a | 2016-04-14 21:27:51 | [diff] [blame] | 24 | |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 25 | use build_helper::{self, output}; |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 26 | |
Alex Crichton | 48a07bf | 2016-07-06 04:58:20 | [diff] [blame] | 27 | use {Build, Compiler, Mode}; |
Alex Crichton | d38db82 | 2016-12-09 01:13:55 | [diff] [blame] | 28 | use dist; |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 29 | use util::{self, dylib_path, dylib_path_var, exe}; |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 30 | |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 31 | const ADB_TEST_DIR: &str = "/data/tmp/work"; |
Alex Crichton | defd1b3 | 2016-03-08 07:15:55 | [diff] [blame] | 32 | |
Ulrik Sverdrup | b1566ba | 2016-11-25 21:13:59 | [diff] [blame] | 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 | |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 61 | fn try_run(build: &Build, cmd: &mut Command) { |
Mark Simulacrum | 4dc8fe9 | 2017-06-27 19:37:24 | [diff] [blame^] | 62 | if !build.fail_fast { |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 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) { |
Mark Simulacrum | 4dc8fe9 | 2017-06-27 19:37:24 | [diff] [blame^] | 73 | if !build.fail_fast { |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 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 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 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. |
Alex Crichton | 254876e | 2016-12-28 23:01:21 | [diff] [blame] | 87 | pub fn linkcheck(build: &Build, host: &str) { |
| 88 | println!("Linkcheck ({})", host); |
| 89 | let compiler = Compiler::new(0, host); |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 90 | |
| 91 | let _time = util::timeit(); |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 92 | try_run(build, build.tool_cmd(&compiler, "linkchecker") |
| 93 | .arg(build.out.join(host).join("doc"))); |
Alex Crichton | defd1b3 | 2016-03-08 07:15:55 | [diff] [blame] | 94 | } |
Brian Anderson | 3a790ac | 2016-03-18 20:54:31 | [diff] [blame] | 95 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 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. |
Brian Anderson | 3a790ac | 2016-03-18 20:54:31 | [diff] [blame] | 100 | pub fn cargotest(build: &Build, stage: u32, host: &str) { |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 101 | let compiler = Compiler::new(stage, host); |
Brian Anderson | 8019922 | 2016-04-06 18:03:42 | [diff] [blame] | 102 | |
Alex Crichton | 73c2d2a | 2016-04-14 21:27:51 | [diff] [blame] | 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 | |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 109 | let _time = util::timeit(); |
Alex Crichton | 254876e | 2016-12-28 23:01:21 | [diff] [blame] | 110 | let mut cmd = Command::new(build.tool(&Compiler::new(0, host), "cargotest")); |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 111 | build.prepare_tool_cmd(&compiler, &mut cmd); |
Mark Simulacrum | 2cc5b08 | 2017-06-27 19:32:04 | [diff] [blame] | 112 | try_run(build, cmd.arg(&build.initial_cargo) |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 113 | .arg(&out_dir) |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 114 | .env("RUSTC", build.compiler_path(&compiler)) |
| 115 | .env("RUSTDOC", build.rustdoc(&compiler))); |
Alex Crichton | 009f45f | 2017-04-18 00:24:05 | [diff] [blame] | 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"); |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 126 | let old_path = env::var_os("PATH").unwrap_or_default(); |
| 127 | let newpath = env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect(""); |
Alex Crichton | 009f45f | 2017-04-18 00:24:05 | [diff] [blame] | 128 | |
| 129 | let mut cargo = build.cargo(compiler, Mode::Tool, host, "test"); |
Alex Crichton | 5daf557 | 2017-04-20 21:32:54 | [diff] [blame] | 130 | cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml")); |
Mark Simulacrum | 4dc8fe9 | 2017-06-27 19:37:24 | [diff] [blame^] | 131 | if !build.fail_fast { |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 132 | cargo.arg("--no-fail-fast"); |
| 133 | } |
Alex Crichton | 009f45f | 2017-04-18 00:24:05 | [diff] [blame] | 134 | |
| 135 | // Don't build tests dynamically, just a pain to work with |
| 136 | cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); |
| 137 | |
| 138 | // Don't run cross-compile tests, we may not have cross-compiled libstd libs |
| 139 | // available. |
| 140 | cargo.env("CFG_DISABLE_CROSS_TESTS", "1"); |
| 141 | |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 142 | try_run(build, cargo.env("PATH", newpath)); |
Brian Anderson | 3a790ac | 2016-03-18 20:54:31 | [diff] [blame] | 143 | } |
Alex Crichton | 9dd3c54 | 2016-03-29 20:14:52 | [diff] [blame] | 144 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 145 | /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler. |
| 146 | /// |
| 147 | /// This tool in `src/tools` checks up on various bits and pieces of style and |
| 148 | /// otherwise just implements a few lint-like checks that are specific to the |
| 149 | /// compiler itself. |
Alex Crichton | 254876e | 2016-12-28 23:01:21 | [diff] [blame] | 150 | pub fn tidy(build: &Build, host: &str) { |
kennytm | e6e5dc0 | 2017-05-17 16:33:20 | [diff] [blame] | 151 | let _folder = build.fold_output(|| "tidy"); |
Alex Crichton | 254876e | 2016-12-28 23:01:21 | [diff] [blame] | 152 | println!("tidy check ({})", host); |
| 153 | let compiler = Compiler::new(0, host); |
Eduard-Mihai Burtescu | d29f0bc | 2017-02-10 20:59:40 | [diff] [blame] | 154 | let mut cmd = build.tool_cmd(&compiler, "tidy"); |
| 155 | cmd.arg(build.src.join("src")); |
| 156 | if !build.config.vendor { |
| 157 | cmd.arg("--no-vendor"); |
| 158 | } |
kennytm | 6ac0787 | 2017-05-21 20:27:47 | [diff] [blame] | 159 | if build.config.quiet_tests { |
| 160 | cmd.arg("--quiet"); |
| 161 | } |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 162 | try_run(build, &mut cmd); |
Alex Crichton | 9dd3c54 | 2016-03-29 20:14:52 | [diff] [blame] | 163 | } |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 164 | |
| 165 | fn testdir(build: &Build, host: &str) -> PathBuf { |
| 166 | build.out.join(host).join("test") |
| 167 | } |
| 168 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 169 | /// Executes the `compiletest` tool to run a suite of tests. |
| 170 | /// |
| 171 | /// Compiles all tests with `compiler` for `target` with the specified |
| 172 | /// compiletest `mode` and `suite` arguments. For example `mode` can be |
| 173 | /// "run-pass" or `suite` can be something like `debuginfo`. |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 174 | pub fn compiletest(build: &Build, |
| 175 | compiler: &Compiler, |
| 176 | target: &str, |
| 177 | mode: &str, |
| 178 | suite: &str) { |
kennytm | e6e5dc0 | 2017-05-17 16:33:20 | [diff] [blame] | 179 | let _folder = build.fold_output(|| format!("test_{}", suite)); |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 180 | println!("Check compiletest suite={} mode={} ({} -> {})", |
| 181 | suite, mode, compiler.host, target); |
Alex Crichton | 254876e | 2016-12-28 23:01:21 | [diff] [blame] | 182 | let mut cmd = Command::new(build.tool(&Compiler::new(0, compiler.host), |
| 183 | "compiletest")); |
| 184 | build.prepare_tool_cmd(compiler, &mut cmd); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 185 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 186 | // compiletest currently has... a lot of arguments, so let's just pass all |
| 187 | // of them! |
| 188 | |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 189 | cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler)); |
| 190 | cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target)); |
| 191 | cmd.arg("--rustc-path").arg(build.compiler_path(compiler)); |
| 192 | cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler)); |
| 193 | cmd.arg("--src-base").arg(build.src.join("src/test").join(suite)); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 194 | cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite)); |
| 195 | cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target)); |
| 196 | cmd.arg("--mode").arg(mode); |
| 197 | cmd.arg("--target").arg(target); |
| 198 | cmd.arg("--host").arg(compiler.host); |
| 199 | cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.config.build)); |
| 200 | |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 201 | if let Some(ref nodejs) = build.config.nodejs { |
Brian Anderson | 8401e37 | 2016-09-15 19:42:26 | [diff] [blame] | 202 | cmd.arg("--nodejs").arg(nodejs); |
| 203 | } |
| 204 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 205 | let mut flags = vec!["-Crpath".to_string()]; |
Alex Crichton | f4e4ec7 | 2016-05-13 22:26:41 | [diff] [blame] | 206 | if build.config.rust_optimize_tests { |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 207 | flags.push("-O".to_string()); |
Alex Crichton | f4e4ec7 | 2016-05-13 22:26:41 | [diff] [blame] | 208 | } |
| 209 | if build.config.rust_debuginfo_tests { |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 210 | flags.push("-g".to_string()); |
Alex Crichton | f4e4ec7 | 2016-05-13 22:26:41 | [diff] [blame] | 211 | } |
| 212 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 213 | let mut hostflags = build.rustc_flags(&compiler.host); |
| 214 | hostflags.extend(flags.clone()); |
| 215 | cmd.arg("--host-rustcflags").arg(hostflags.join(" ")); |
Alex Crichton | f4e4ec7 | 2016-05-13 22:26:41 | [diff] [blame] | 216 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 217 | let mut targetflags = build.rustc_flags(&target); |
| 218 | targetflags.extend(flags); |
| 219 | targetflags.push(format!("-Lnative={}", |
| 220 | build.test_helpers_out(target).display())); |
| 221 | cmd.arg("--target-rustcflags").arg(targetflags.join(" ")); |
Alex Crichton | cbe6292 | 2016-04-19 16:44:19 | [diff] [blame] | 222 | |
Alex Crichton | 5f626138 | 2016-11-14 16:04:39 | [diff] [blame] | 223 | cmd.arg("--docck-python").arg(build.python()); |
Alex Crichton | cbe6292 | 2016-04-19 16:44:19 | [diff] [blame] | 224 | |
| 225 | if build.config.build.ends_with("apple-darwin") { |
Corey Farwell | 97a1b6a | 2017-03-12 18:13:35 | [diff] [blame] | 226 | // Force /usr/bin/python on macOS for LLDB tests because we're loading the |
Alex Crichton | cbe6292 | 2016-04-19 16:44:19 | [diff] [blame] | 227 | // LLDB plugin's compiled module which only works with the system python |
| 228 | // (namely not Homebrew-installed python) |
| 229 | cmd.arg("--lldb-python").arg("/usr/bin/python"); |
| 230 | } else { |
Alex Crichton | 5f626138 | 2016-11-14 16:04:39 | [diff] [blame] | 231 | cmd.arg("--lldb-python").arg(build.python()); |
Alex Crichton | cbe6292 | 2016-04-19 16:44:19 | [diff] [blame] | 232 | } |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 233 | |
Tim Neumann | dce4600 | 2016-10-29 18:11:53 | [diff] [blame] | 234 | if let Some(ref gdb) = build.config.gdb { |
| 235 | cmd.arg("--gdb").arg(gdb); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 236 | } |
| 237 | if let Some(ref vers) = build.lldb_version { |
| 238 | cmd.arg("--lldb-version").arg(vers); |
| 239 | } |
| 240 | if let Some(ref dir) = build.lldb_python_dir { |
| 241 | cmd.arg("--lldb-python-dir").arg(dir); |
| 242 | } |
Alex Crichton | 96283fc | 2016-09-01 17:52:44 | [diff] [blame] | 243 | let llvm_config = build.llvm_config(target); |
| 244 | let llvm_version = output(Command::new(&llvm_config).arg("--version")); |
| 245 | cmd.arg("--llvm-version").arg(llvm_version); |
Simonas Kazlauskas | 406eddf | 2017-06-08 14:18:05 | [diff] [blame] | 246 | if !build.is_rust_llvm(target) { |
| 247 | cmd.arg("--system-llvm"); |
| 248 | } |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 249 | |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 250 | cmd.args(&build.flags.cmd.test_args()); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 251 | |
Niko Matsakis | 83453bc | 2016-11-16 23:02:56 | [diff] [blame] | 252 | if build.config.verbose() || build.flags.verbose() { |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 253 | cmd.arg("--verbose"); |
| 254 | } |
| 255 | |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 256 | if build.config.quiet_tests { |
| 257 | cmd.arg("--quiet"); |
| 258 | } |
| 259 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 260 | // Only pass correct values for these flags for the `run-make` suite as it |
| 261 | // requires that a C++ compiler was configured which isn't always the case. |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 262 | if suite == "run-make" { |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 263 | let llvm_components = output(Command::new(&llvm_config).arg("--components")); |
| 264 | let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags")); |
| 265 | cmd.arg("--cc").arg(build.cc(target)) |
Ian Douglas Scott | f98ffb5 | 2017-06-22 18:51:32 | [diff] [blame] | 266 | .arg("--cxx").arg(build.cxx(target).unwrap()) |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 267 | .arg("--cflags").arg(build.cflags(target).join(" ")) |
| 268 | .arg("--llvm-components").arg(llvm_components.trim()) |
| 269 | .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim()); |
| 270 | } else { |
| 271 | cmd.arg("--cc").arg("") |
| 272 | .arg("--cxx").arg("") |
| 273 | .arg("--cflags").arg("") |
| 274 | .arg("--llvm-components").arg("") |
| 275 | .arg("--llvm-cxxflags").arg(""); |
| 276 | } |
| 277 | |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 278 | if build.remote_tested(target) { |
| 279 | cmd.arg("--remote-test-client") |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 280 | .arg(build.tool(&Compiler::new(0, &build.config.build), |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 281 | "remote-test-client")); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 282 | } |
| 283 | |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 284 | // Running a C compiler on MSVC requires a few env vars to be set, to be |
| 285 | // sure to set them here. |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 286 | // |
| 287 | // Note that if we encounter `PATH` we make sure to append to our own `PATH` |
| 288 | // rather than stomp over it. |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 289 | if target.contains("msvc") { |
| 290 | for &(ref k, ref v) in build.cc[target].0.env() { |
| 291 | if k != "PATH" { |
| 292 | cmd.env(k, v); |
| 293 | } |
| 294 | } |
| 295 | } |
Alex Crichton | 2186660 | 2016-11-16 17:19:02 | [diff] [blame] | 296 | cmd.env("RUSTC_BOOTSTRAP", "1"); |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 297 | build.add_rust_test_threads(&mut cmd); |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 298 | |
Jorge Aparicio | 775a936 | 2017-02-03 23:58:47 | [diff] [blame] | 299 | if build.config.sanitizers { |
| 300 | cmd.env("SANITIZER_SUPPORT", "1"); |
| 301 | } |
| 302 | |
whitequark | 42754ce | 2017-02-13 09:57:50 | [diff] [blame] | 303 | if build.config.profiler { |
| 304 | cmd.env("PROFILER_SUPPORT", "1"); |
| 305 | } |
| 306 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 307 | cmd.arg("--adb-path").arg("adb"); |
| 308 | cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR); |
| 309 | if target.contains("android") { |
| 310 | // Assume that cc for this target comes from the android sysroot |
| 311 | cmd.arg("--android-cross-path") |
| 312 | .arg(build.cc(target).parent().unwrap().parent().unwrap()); |
| 313 | } else { |
| 314 | cmd.arg("--android-cross-path").arg(""); |
| 315 | } |
| 316 | |
kennytm | e6e5dc0 | 2017-05-17 16:33:20 | [diff] [blame] | 317 | build.ci_env.force_coloring_in_ci(&mut cmd); |
| 318 | |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 319 | let _time = util::timeit(); |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 320 | try_run(build, &mut cmd); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 321 | } |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 322 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 323 | /// Run `rustdoc --test` for all documentation in `src/doc`. |
| 324 | /// |
| 325 | /// This will run all tests in our markdown documentation (e.g. the book) |
| 326 | /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to |
| 327 | /// `compiler`. |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 328 | pub fn docs(build: &Build, compiler: &Compiler) { |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 329 | // Do a breadth-first traversal of the `src/doc` directory and just run |
| 330 | // tests for all files that end in `*.md` |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 331 | let mut stack = vec![build.src.join("src/doc")]; |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 332 | let _time = util::timeit(); |
kennytm | e6e5dc0 | 2017-05-17 16:33:20 | [diff] [blame] | 333 | let _folder = build.fold_output(|| "test_docs"); |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 334 | |
| 335 | while let Some(p) = stack.pop() { |
| 336 | if p.is_dir() { |
Mark Simulacrum | dd1d75e | 2017-06-04 23:55:50 | [diff] [blame] | 337 | stack.extend(t!(p.read_dir()).map(|p| t!(p).path()).filter(|p| { |
| 338 | p.extension().and_then(|s| s.to_str()) == Some("md") && |
| 339 | // The nostarch directory in the book is for no starch, and so isn't guaranteed to |
| 340 | // build. We don't care if it doesn't build, so skip it. |
| 341 | p.to_str().map_or(true, |p| !p.contains("nostarch")) |
| 342 | })); |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 343 | continue |
| 344 | } |
| 345 | |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 346 | markdown_test(build, compiler, &p); |
| 347 | } |
| 348 | } |
| 349 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 350 | /// Run the error index generator tool to execute the tests located in the error |
| 351 | /// index. |
| 352 | /// |
| 353 | /// The `error_index_generator` tool lives in `src/tools` and is used to |
| 354 | /// generate a markdown file from the error indexes of the code base which is |
| 355 | /// then passed to `rustdoc --test`. |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 356 | pub fn error_index(build: &Build, compiler: &Compiler) { |
kennytm | e6e5dc0 | 2017-05-17 16:33:20 | [diff] [blame] | 357 | let _folder = build.fold_output(|| "test_error_index"); |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 358 | println!("Testing error-index stage{}", compiler.stage); |
| 359 | |
Alex Crichton | 860c6ab | 2016-11-08 17:59:46 | [diff] [blame] | 360 | let dir = testdir(build, compiler.host); |
| 361 | t!(fs::create_dir_all(&dir)); |
| 362 | let output = dir.join("error-index.md"); |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 363 | |
| 364 | let _time = util::timeit(); |
Alex Crichton | 254876e | 2016-12-28 23:01:21 | [diff] [blame] | 365 | build.run(build.tool_cmd(&Compiler::new(0, compiler.host), |
| 366 | "error_index_generator") |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 367 | .arg("markdown") |
| 368 | .arg(&output) |
| 369 | .env("CFG_BUILD", &build.config.build)); |
| 370 | |
| 371 | markdown_test(build, compiler, &output); |
| 372 | } |
| 373 | |
| 374 | fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) { |
Mark Simulacrum | dd1d75e | 2017-06-04 23:55:50 | [diff] [blame] | 375 | let mut file = t!(File::open(markdown)); |
| 376 | let mut contents = String::new(); |
| 377 | t!(file.read_to_string(&mut contents)); |
| 378 | if !contents.contains("```") { |
| 379 | return; |
| 380 | } |
| 381 | |
Mark Simulacrum | bc8fabb | 2017-06-06 18:00:22 | [diff] [blame] | 382 | println!("doc tests for: {}", markdown.display()); |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 383 | let mut cmd = Command::new(build.rustdoc(compiler)); |
| 384 | build.add_rustc_lib_path(compiler, &mut cmd); |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 385 | build.add_rust_test_threads(&mut cmd); |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 386 | cmd.arg("--test"); |
| 387 | cmd.arg(markdown); |
Alex Crichton | 6f62fae | 2016-12-12 17:03:35 | [diff] [blame] | 388 | cmd.env("RUSTC_BOOTSTRAP", "1"); |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 389 | |
kennytm | 6ac0787 | 2017-05-21 20:27:47 | [diff] [blame] | 390 | let test_args = build.flags.cmd.test_args().join(" "); |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 391 | cmd.arg("--test-args").arg(test_args); |
| 392 | |
kennytm | 6ac0787 | 2017-05-21 20:27:47 | [diff] [blame] | 393 | if build.config.quiet_tests { |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 394 | try_run_quiet(build, &mut cmd); |
kennytm | 6ac0787 | 2017-05-21 20:27:47 | [diff] [blame] | 395 | } else { |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 396 | try_run(build, &mut cmd); |
kennytm | 6ac0787 | 2017-05-21 20:27:47 | [diff] [blame] | 397 | } |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 398 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 399 | |
| 400 | /// Run all unit tests plus documentation tests for an entire crate DAG defined |
| 401 | /// by a `Cargo.toml` |
| 402 | /// |
| 403 | /// This is what runs tests for crates like the standard library, compiler, etc. |
| 404 | /// It essentially is the driver for running `cargo test`. |
| 405 | /// |
| 406 | /// Currently this runs all tests for a DAG by passing a bunch of `-p foo` |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 407 | /// arguments, and those arguments are discovered from `cargo metadata`. |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 408 | pub fn krate(build: &Build, |
| 409 | compiler: &Compiler, |
| 410 | target: &str, |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 411 | mode: Mode, |
Ulrik Sverdrup | b1566ba | 2016-11-25 21:13:59 | [diff] [blame] | 412 | test_kind: TestKind, |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 413 | krate: Option<&str>) { |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 414 | let (name, path, features, root) = match mode { |
Ahmed Charles | 9ca382f | 2016-09-02 08:55:29 | [diff] [blame] | 415 | Mode::Libstd => { |
Alex Crichton | 40aaa65 | 2017-02-15 16:53:18 | [diff] [blame] | 416 | ("libstd", "src/libstd", build.std_features(), "std") |
Ahmed Charles | 9ca382f | 2016-09-02 08:55:29 | [diff] [blame] | 417 | } |
| 418 | Mode::Libtest => { |
Alex Crichton | 40aaa65 | 2017-02-15 16:53:18 | [diff] [blame] | 419 | ("libtest", "src/libtest", String::new(), "test") |
Ahmed Charles | 9ca382f | 2016-09-02 08:55:29 | [diff] [blame] | 420 | } |
| 421 | Mode::Librustc => { |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 422 | ("librustc", "src/rustc", build.rustc_features(), "rustc-main") |
Ahmed Charles | 9ca382f | 2016-09-02 08:55:29 | [diff] [blame] | 423 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 424 | _ => panic!("can only test libraries"), |
| 425 | }; |
kennytm | e6e5dc0 | 2017-05-17 16:33:20 | [diff] [blame] | 426 | let _folder = build.fold_output(|| { |
| 427 | format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name) |
| 428 | }); |
Ulrik Sverdrup | b1566ba | 2016-11-25 21:13:59 | [diff] [blame] | 429 | println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage, |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 430 | compiler.host, target); |
| 431 | |
Alex Crichton | 7046fea | 2016-12-25 23:20:33 | [diff] [blame] | 432 | // If we're not doing a full bootstrap but we're testing a stage2 version of |
| 433 | // libstd, then what we're actually testing is the libstd produced in |
| 434 | // stage1. Reflect that here by updating the compiler that we're working |
| 435 | // with automatically. |
| 436 | let compiler = if build.force_use_stage1(compiler, target) { |
| 437 | Compiler::new(1, compiler.host) |
| 438 | } else { |
| 439 | compiler.clone() |
| 440 | }; |
| 441 | |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 442 | // Build up the base `cargo test` command. |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 443 | // |
| 444 | // Pass in some standard flags then iterate over the graph we've discovered |
| 445 | // in `cargo metadata` with the maps above and figure out what `-p` |
| 446 | // arguments need to get passed. |
Alex Crichton | 7046fea | 2016-12-25 23:20:33 | [diff] [blame] | 447 | let mut cargo = build.cargo(&compiler, mode, target, test_kind.subcommand()); |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 448 | cargo.arg("--manifest-path") |
| 449 | .arg(build.src.join(path).join("Cargo.toml")) |
| 450 | .arg("--features").arg(features); |
Mark Simulacrum | 4dc8fe9 | 2017-06-27 19:37:24 | [diff] [blame^] | 451 | if test_kind.subcommand() == "test" && !build.fail_fast { |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 452 | cargo.arg("--no-fail-fast"); |
| 453 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 454 | |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 455 | match krate { |
| 456 | Some(krate) => { |
| 457 | cargo.arg("-p").arg(krate); |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 458 | } |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 459 | None => { |
| 460 | let mut visited = HashSet::new(); |
| 461 | let mut next = vec![root]; |
| 462 | while let Some(name) = next.pop() { |
Alex Crichton | 36a926a | 2017-01-13 23:11:34 | [diff] [blame] | 463 | // Right now jemalloc is our only target-specific crate in the |
| 464 | // sense that it's not present on all platforms. Custom skip it |
| 465 | // here for now, but if we add more this probably wants to get |
| 466 | // more generalized. |
| 467 | // |
| 468 | // Also skip `build_helper` as it's not compiled normally for |
| 469 | // target during the bootstrap and it's just meant to be a |
| 470 | // helper crate, not tested. If it leaks through then it ends up |
| 471 | // messing with various mtime calculations and such. |
| 472 | if !name.contains("jemalloc") && name != "build_helper" { |
Vadim Petrochenkov | b4abb72 | 2017-02-02 20:55:42 | [diff] [blame] | 473 | cargo.arg("-p").arg(&format!("{}:0.0.0", name)); |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 474 | } |
| 475 | for dep in build.crates[name].deps.iter() { |
| 476 | if visited.insert(dep) { |
| 477 | next.push(dep); |
| 478 | } |
| 479 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 480 | } |
| 481 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | // The tests are going to run with the *target* libraries, so we need to |
| 485 | // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent. |
| 486 | // |
| 487 | // Note that to run the compiler we need to run with the *host* libraries, |
| 488 | // but our wrapper scripts arrange for that to be the case anyway. |
| 489 | let mut dylib_path = dylib_path(); |
Alex Crichton | 7046fea | 2016-12-25 23:20:33 | [diff] [blame] | 490 | dylib_path.insert(0, build.sysroot_libdir(&compiler, target)); |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 491 | cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap()); |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 492 | |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 493 | if target.contains("emscripten") || build.remote_tested(target) { |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 494 | cargo.arg("--no-run"); |
| 495 | } |
| 496 | |
| 497 | cargo.arg("--"); |
| 498 | |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 499 | if build.config.quiet_tests { |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 500 | cargo.arg("--quiet"); |
| 501 | } |
| 502 | |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 503 | let _time = util::timeit(); |
| 504 | |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 505 | if target.contains("emscripten") { |
Alex Crichton | 0e272de | 2016-11-16 20:31:19 | [diff] [blame] | 506 | build.run(&mut cargo); |
Alex Crichton | 7046fea | 2016-12-25 23:20:33 | [diff] [blame] | 507 | krate_emscripten(build, &compiler, target, mode); |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 508 | } else if build.remote_tested(target) { |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 509 | build.run(&mut cargo); |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 510 | krate_remote(build, &compiler, target, mode); |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 511 | } else { |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 512 | cargo.args(&build.flags.cmd.test_args()); |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 513 | try_run(build, &mut cargo); |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Brian Anderson | b8b50f0 | 2016-09-06 00:41:50 | [diff] [blame] | 517 | fn krate_emscripten(build: &Build, |
| 518 | compiler: &Compiler, |
| 519 | target: &str, |
| 520 | mode: Mode) { |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 521 | let out_dir = build.cargo_out(compiler, mode, target); |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 522 | let tests = find_tests(&out_dir.join("deps"), target); |
Ross Schulman | ad9184c | 2016-09-05 23:56:48 | [diff] [blame] | 523 | |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 524 | let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured"); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 525 | for test in tests { |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 526 | println!("running {}", test.display()); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 527 | let mut cmd = Command::new(nodejs); |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 528 | cmd.arg(&test); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 529 | if build.config.quiet_tests { |
| 530 | cmd.arg("--quiet"); |
| 531 | } |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 532 | try_run(build, &mut cmd); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 536 | fn krate_remote(build: &Build, |
| 537 | compiler: &Compiler, |
| 538 | target: &str, |
| 539 | mode: Mode) { |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 540 | let out_dir = build.cargo_out(compiler, mode, target); |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 541 | let tests = find_tests(&out_dir.join("deps"), target); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 542 | |
| 543 | let tool = build.tool(&Compiler::new(0, &build.config.build), |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 544 | "remote-test-client"); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 545 | for test in tests { |
| 546 | let mut cmd = Command::new(&tool); |
| 547 | cmd.arg("run") |
| 548 | .arg(&test); |
| 549 | if build.config.quiet_tests { |
| 550 | cmd.arg("--quiet"); |
| 551 | } |
| 552 | cmd.args(&build.flags.cmd.test_args()); |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 553 | try_run(build, &mut cmd); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 554 | } |
| 555 | } |
Ross Schulman | ad9184c | 2016-09-05 23:56:48 | [diff] [blame] | 556 | |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 557 | fn find_tests(dir: &Path, target: &str) -> Vec<PathBuf> { |
| 558 | let mut dst = Vec::new(); |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 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")) || |
Ross Schulman | ad9184c | 2016-09-05 23:56:48 | [diff] [blame] | 566 | (!target.contains("windows") && !filename.contains(".")) || |
Marco A L Barbosa | 554f21b | 2017-06-13 12:32:49 | [diff] [blame] | 567 | (target.contains("emscripten") && |
| 568 | filename.ends_with(".js") && |
| 569 | !filename.ends_with(".asm.js")) { |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 570 | dst.push(e.path()); |
| 571 | } |
| 572 | } |
Mark Simulacrum | 5b44cbc | 2017-06-26 16:23:50 | [diff] [blame] | 573 | dst |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 574 | } |
| 575 | |
Mátyás Mustoha | b194def | 2017-04-11 10:10:05 | [diff] [blame] | 576 | pub fn remote_copy_libs(build: &Build, compiler: &Compiler, target: &str) { |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 577 | if !build.remote_tested(target) { |
| 578 | return |
Alex Crichton | cf8fde1 | 2016-12-31 02:54:05 | [diff] [blame] | 579 | } |
| 580 | |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 581 | println!("REMOTE copy libs to emulator ({})", target); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 582 | t!(fs::create_dir_all(build.out.join("tmp"))); |
| 583 | |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 584 | let server = build.cargo_out(compiler, Mode::Tool, target) |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 585 | .join(exe("remote-test-server", target)); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 586 | |
| 587 | // Spawn the emulator and wait for it to come online |
| 588 | let tool = build.tool(&Compiler::new(0, &build.config.build), |
Alex Crichton | 7bc2cbf | 2017-04-26 15:52:19 | [diff] [blame] | 589 | "remote-test-client"); |
| 590 | let mut cmd = Command::new(&tool); |
| 591 | cmd.arg("spawn-emulator") |
| 592 | .arg(target) |
| 593 | .arg(&server) |
| 594 | .arg(build.out.join("tmp")); |
| 595 | if let Some(rootfs) = build.qemu_rootfs(target) { |
| 596 | cmd.arg(rootfs); |
| 597 | } |
| 598 | build.run(&mut cmd); |
Alex Crichton | 1747ce2 | 2017-01-28 21:38:06 | [diff] [blame] | 599 | |
| 600 | // Push all our dylibs to the emulator |
| 601 | for f in t!(build.sysroot_libdir(compiler, target).read_dir()) { |
| 602 | let f = t!(f); |
| 603 | let name = f.file_name().into_string().unwrap(); |
| 604 | if util::is_dylib(&name) { |
| 605 | build.run(Command::new(&tool) |
| 606 | .arg("push") |
| 607 | .arg(f.path())); |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
Alex Crichton | d38db82 | 2016-12-09 01:13:55 | [diff] [blame] | 612 | /// Run "distcheck", a 'make check' from a tarball |
| 613 | pub fn distcheck(build: &Build) { |
| 614 | if build.config.build != "x86_64-unknown-linux-gnu" { |
| 615 | return |
| 616 | } |
| 617 | if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") { |
| 618 | return |
| 619 | } |
| 620 | if !build.config.target.iter().any(|s| s == "x86_64-unknown-linux-gnu") { |
| 621 | return |
| 622 | } |
| 623 | |
Josh Stone | c5cd4cb | 2017-04-26 19:37:12 | [diff] [blame] | 624 | println!("Distcheck"); |
Alex Crichton | d38db82 | 2016-12-09 01:13:55 | [diff] [blame] | 625 | let dir = build.out.join("tmp").join("distcheck"); |
| 626 | let _ = fs::remove_dir_all(&dir); |
| 627 | t!(fs::create_dir_all(&dir)); |
| 628 | |
| 629 | let mut cmd = Command::new("tar"); |
| 630 | cmd.arg("-xzf") |
| 631 | .arg(dist::rust_src_location(build)) |
| 632 | .arg("--strip-components=1") |
| 633 | .current_dir(&dir); |
| 634 | build.run(&mut cmd); |
| 635 | build.run(Command::new("./configure") |
Alex Crichton | 4781eb3 | 2016-12-30 17:26:25 | [diff] [blame] | 636 | .args(&build.config.configure_args) |
Eduard-Mihai Burtescu | d29f0bc | 2017-02-10 20:59:40 | [diff] [blame] | 637 | .arg("--enable-vendor") |
Alex Crichton | d38db82 | 2016-12-09 01:13:55 | [diff] [blame] | 638 | .current_dir(&dir)); |
Sébastien Marie | a7d9025 | 2016-12-17 19:09:23 | [diff] [blame] | 639 | build.run(Command::new(build_helper::make(&build.config.build)) |
Alex Crichton | d38db82 | 2016-12-09 01:13:55 | [diff] [blame] | 640 | .arg("check") |
| 641 | .current_dir(&dir)); |
Josh Stone | c5cd4cb | 2017-04-26 19:37:12 | [diff] [blame] | 642 | |
| 643 | // Now make sure that rust-src has all of libstd's dependencies |
| 644 | println!("Distcheck rust-src"); |
| 645 | let dir = build.out.join("tmp").join("distcheck-src"); |
| 646 | let _ = fs::remove_dir_all(&dir); |
| 647 | t!(fs::create_dir_all(&dir)); |
| 648 | |
| 649 | let mut cmd = Command::new("tar"); |
| 650 | cmd.arg("-xzf") |
| 651 | .arg(dist::rust_src_installer(build)) |
| 652 | .arg("--strip-components=1") |
| 653 | .current_dir(&dir); |
| 654 | build.run(&mut cmd); |
| 655 | |
| 656 | let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml"); |
Mark Simulacrum | 2cc5b08 | 2017-06-27 19:32:04 | [diff] [blame] | 657 | build.run(Command::new(&build.initial_cargo) |
Josh Stone | c5cd4cb | 2017-04-26 19:37:12 | [diff] [blame] | 658 | .arg("generate-lockfile") |
| 659 | .arg("--manifest-path") |
| 660 | .arg(&toml) |
| 661 | .current_dir(&dir)); |
Alex Crichton | d38db82 | 2016-12-09 01:13:55 | [diff] [blame] | 662 | } |
Alex Crichton | 1a040b3 | 2016-12-31 03:50:57 | [diff] [blame] | 663 | |
| 664 | /// Test the build system itself |
| 665 | pub fn bootstrap(build: &Build) { |
Mark Simulacrum | 2cc5b08 | 2017-06-27 19:32:04 | [diff] [blame] | 666 | let mut cmd = Command::new(&build.initial_cargo); |
Alex Crichton | 1a040b3 | 2016-12-31 03:50:57 | [diff] [blame] | 667 | cmd.arg("test") |
| 668 | .current_dir(build.src.join("src/bootstrap")) |
| 669 | .env("CARGO_TARGET_DIR", build.out.join("bootstrap")) |
Alex Crichton | be7ebdd | 2017-06-07 02:32:43 | [diff] [blame] | 670 | .env("RUSTC_BOOTSTRAP", "1") |
Mark Simulacrum | 2cc5b08 | 2017-06-27 19:32:04 | [diff] [blame] | 671 | .env("RUSTC", &build.initial_rustc); |
Mark Simulacrum | 4dc8fe9 | 2017-06-27 19:37:24 | [diff] [blame^] | 672 | if !build.fail_fast { |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 673 | cmd.arg("--no-fail-fast"); |
| 674 | } |
Alex Crichton | 1a040b3 | 2016-12-31 03:50:57 | [diff] [blame] | 675 | cmd.arg("--").args(&build.flags.cmd.test_args()); |
Josh Stone | 617aea4 | 2017-06-02 16:27:44 | [diff] [blame] | 676 | try_run(build, &mut cmd); |
Alex Crichton | 1a040b3 | 2016-12-31 03:50:57 | [diff] [blame] | 677 | } |