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 | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 11 | //! Implementation of the various `check-*` targets of the build system. |
| 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; |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 18 | use std::fs; |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 19 | use std::path::{PathBuf, Path}; |
| 20 | use std::process::Command; |
Alex Crichton | 73c2d2a | 2016-04-14 21:27:51 | [diff] [blame] | 21 | |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 22 | use build_helper::output; |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 23 | |
Alex Crichton | 48a07bf | 2016-07-06 04:58:20 | [diff] [blame] | 24 | use {Build, Compiler, Mode}; |
| 25 | use util::{self, dylib_path, dylib_path_var}; |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 26 | |
| 27 | const ADB_TEST_DIR: &'static str = "/data/tmp"; |
Alex Crichton | defd1b3 | 2016-03-08 07:15:55 | [diff] [blame] | 28 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 29 | /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler. |
| 30 | /// |
| 31 | /// This tool in `src/tools` will verify the validity of all our links in the |
| 32 | /// documentation to ensure we don't have a bunch of dead ones. |
Alex Crichton | defd1b3 | 2016-03-08 07:15:55 | [diff] [blame] | 33 | pub fn linkcheck(build: &Build, stage: u32, host: &str) { |
| 34 | println!("Linkcheck stage{} ({})", stage, host); |
| 35 | let compiler = Compiler::new(stage, host); |
Alex Crichton | 4a917e0 | 2016-03-12 00:21:05 | [diff] [blame] | 36 | build.run(build.tool_cmd(&compiler, "linkchecker") |
| 37 | .arg(build.out.join(host).join("doc"))); |
Alex Crichton | defd1b3 | 2016-03-08 07:15:55 | [diff] [blame] | 38 | } |
Brian Anderson | 3a790ac | 2016-03-18 20:54:31 | [diff] [blame] | 39 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 40 | /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler. |
| 41 | /// |
| 42 | /// This tool in `src/tools` will check out a few Rust projects and run `cargo |
| 43 | /// test` to ensure that we don't regress the test suites there. |
Brian Anderson | 3a790ac | 2016-03-18 20:54:31 | [diff] [blame] | 44 | pub fn cargotest(build: &Build, stage: u32, host: &str) { |
| 45 | let ref compiler = Compiler::new(stage, host); |
Brian Anderson | 8019922 | 2016-04-06 18:03:42 | [diff] [blame] | 46 | |
| 47 | // Configure PATH to find the right rustc. NB. we have to use PATH |
| 48 | // and not RUSTC because the Cargo test suite has tests that will |
| 49 | // fail if rustc is not spelled `rustc`. |
| 50 | let path = build.sysroot(compiler).join("bin"); |
| 51 | let old_path = ::std::env::var("PATH").expect(""); |
| 52 | let sep = if cfg!(windows) { ";" } else {":" }; |
| 53 | let ref newpath = format!("{}{}{}", path.display(), sep, old_path); |
| 54 | |
Alex Crichton | 73c2d2a | 2016-04-14 21:27:51 | [diff] [blame] | 55 | // Note that this is a short, cryptic, and not scoped directory name. This |
| 56 | // is currently to minimize the length of path on Windows where we otherwise |
| 57 | // quickly run into path name limit constraints. |
| 58 | let out_dir = build.out.join("ct"); |
| 59 | t!(fs::create_dir_all(&out_dir)); |
| 60 | |
Brian Anderson | 3a790ac | 2016-03-18 20:54:31 | [diff] [blame] | 61 | build.run(build.tool_cmd(compiler, "cargotest") |
Alex Crichton | 73c2d2a | 2016-04-14 21:27:51 | [diff] [blame] | 62 | .env("PATH", newpath) |
| 63 | .arg(&build.cargo) |
| 64 | .arg(&out_dir)); |
Brian Anderson | 3a790ac | 2016-03-18 20:54:31 | [diff] [blame] | 65 | } |
Alex Crichton | 9dd3c54 | 2016-03-29 20:14:52 | [diff] [blame] | 66 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 67 | /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler. |
| 68 | /// |
| 69 | /// This tool in `src/tools` checks up on various bits and pieces of style and |
| 70 | /// otherwise just implements a few lint-like checks that are specific to the |
| 71 | /// compiler itself. |
Alex Crichton | 9dd3c54 | 2016-03-29 20:14:52 | [diff] [blame] | 72 | pub fn tidy(build: &Build, stage: u32, host: &str) { |
| 73 | println!("tidy check stage{} ({})", stage, host); |
| 74 | let compiler = Compiler::new(stage, host); |
| 75 | build.run(build.tool_cmd(&compiler, "tidy") |
| 76 | .arg(build.src.join("src"))); |
| 77 | } |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 78 | |
| 79 | fn testdir(build: &Build, host: &str) -> PathBuf { |
| 80 | build.out.join(host).join("test") |
| 81 | } |
| 82 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 83 | /// Executes the `compiletest` tool to run a suite of tests. |
| 84 | /// |
| 85 | /// Compiles all tests with `compiler` for `target` with the specified |
| 86 | /// compiletest `mode` and `suite` arguments. For example `mode` can be |
| 87 | /// "run-pass" or `suite` can be something like `debuginfo`. |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 88 | pub fn compiletest(build: &Build, |
| 89 | compiler: &Compiler, |
| 90 | target: &str, |
| 91 | mode: &str, |
| 92 | suite: &str) { |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 93 | println!("Check compiletest {} ({} -> {})", suite, compiler.host, target); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 94 | let mut cmd = build.tool_cmd(compiler, "compiletest"); |
| 95 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 96 | // compiletest currently has... a lot of arguments, so let's just pass all |
| 97 | // of them! |
| 98 | |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 99 | cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler)); |
| 100 | cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target)); |
| 101 | cmd.arg("--rustc-path").arg(build.compiler_path(compiler)); |
| 102 | cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler)); |
| 103 | cmd.arg("--src-base").arg(build.src.join("src/test").join(suite)); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 104 | cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite)); |
| 105 | cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target)); |
| 106 | cmd.arg("--mode").arg(mode); |
| 107 | cmd.arg("--target").arg(target); |
| 108 | cmd.arg("--host").arg(compiler.host); |
| 109 | cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.config.build)); |
| 110 | |
Brian Anderson | 8401e37 | 2016-09-15 19:42:26 | [diff] [blame] | 111 | if let Some(nodejs) = build.config.nodejs.as_ref() { |
| 112 | cmd.arg("--nodejs").arg(nodejs); |
| 113 | } |
| 114 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 115 | let mut flags = vec!["-Crpath".to_string()]; |
Alex Crichton | f4e4ec7 | 2016-05-13 22:26:41 | [diff] [blame] | 116 | if build.config.rust_optimize_tests { |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 117 | flags.push("-O".to_string()); |
Alex Crichton | f4e4ec7 | 2016-05-13 22:26:41 | [diff] [blame] | 118 | } |
| 119 | if build.config.rust_debuginfo_tests { |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 120 | flags.push("-g".to_string()); |
Alex Crichton | f4e4ec7 | 2016-05-13 22:26:41 | [diff] [blame] | 121 | } |
| 122 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 123 | let mut hostflags = build.rustc_flags(&compiler.host); |
| 124 | hostflags.extend(flags.clone()); |
| 125 | cmd.arg("--host-rustcflags").arg(hostflags.join(" ")); |
Alex Crichton | f4e4ec7 | 2016-05-13 22:26:41 | [diff] [blame] | 126 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 127 | let mut targetflags = build.rustc_flags(&target); |
| 128 | targetflags.extend(flags); |
| 129 | targetflags.push(format!("-Lnative={}", |
| 130 | build.test_helpers_out(target).display())); |
| 131 | cmd.arg("--target-rustcflags").arg(targetflags.join(" ")); |
Alex Crichton | cbe6292 | 2016-04-19 16:44:19 | [diff] [blame] | 132 | |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 133 | // FIXME: CFG_PYTHON should probably be detected more robustly elsewhere |
Alex Crichton | cbe6292 | 2016-04-19 16:44:19 | [diff] [blame] | 134 | let python_default = "python"; |
| 135 | cmd.arg("--docck-python").arg(python_default); |
| 136 | |
| 137 | if build.config.build.ends_with("apple-darwin") { |
| 138 | // Force /usr/bin/python on OSX for LLDB tests because we're loading the |
| 139 | // LLDB plugin's compiled module which only works with the system python |
| 140 | // (namely not Homebrew-installed python) |
| 141 | cmd.arg("--lldb-python").arg("/usr/bin/python"); |
| 142 | } else { |
| 143 | cmd.arg("--lldb-python").arg(python_default); |
| 144 | } |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 145 | |
| 146 | if let Some(ref vers) = build.gdb_version { |
| 147 | cmd.arg("--gdb-version").arg(vers); |
| 148 | } |
| 149 | if let Some(ref vers) = build.lldb_version { |
| 150 | cmd.arg("--lldb-version").arg(vers); |
| 151 | } |
| 152 | if let Some(ref dir) = build.lldb_python_dir { |
| 153 | cmd.arg("--lldb-python-dir").arg(dir); |
| 154 | } |
Alex Crichton | 96283fc | 2016-09-01 17:52:44 | [diff] [blame] | 155 | let llvm_config = build.llvm_config(target); |
| 156 | let llvm_version = output(Command::new(&llvm_config).arg("--version")); |
| 157 | cmd.arg("--llvm-version").arg(llvm_version); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 158 | |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame^] | 159 | cmd.args(&build.flags.cmd.test_args()); |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 160 | |
| 161 | if build.config.verbose || build.flags.verbose { |
| 162 | cmd.arg("--verbose"); |
| 163 | } |
| 164 | |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 165 | if build.config.quiet_tests { |
| 166 | cmd.arg("--quiet"); |
| 167 | } |
| 168 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 169 | // Only pass correct values for these flags for the `run-make` suite as it |
| 170 | // requires that a C++ compiler was configured which isn't always the case. |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 171 | if suite == "run-make" { |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 172 | let llvm_components = output(Command::new(&llvm_config).arg("--components")); |
| 173 | let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags")); |
| 174 | cmd.arg("--cc").arg(build.cc(target)) |
| 175 | .arg("--cxx").arg(build.cxx(target)) |
| 176 | .arg("--cflags").arg(build.cflags(target).join(" ")) |
| 177 | .arg("--llvm-components").arg(llvm_components.trim()) |
| 178 | .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim()); |
| 179 | } else { |
| 180 | cmd.arg("--cc").arg("") |
| 181 | .arg("--cxx").arg("") |
| 182 | .arg("--cflags").arg("") |
| 183 | .arg("--llvm-components").arg("") |
| 184 | .arg("--llvm-cxxflags").arg(""); |
| 185 | } |
| 186 | |
| 187 | // Running a C compiler on MSVC requires a few env vars to be set, to be |
| 188 | // sure to set them here. |
| 189 | if target.contains("msvc") { |
| 190 | for &(ref k, ref v) in build.cc[target].0.env() { |
| 191 | if k != "PATH" { |
| 192 | cmd.env(k, v); |
| 193 | } |
| 194 | } |
| 195 | } |
Brian Anderson | d3c5905 | 2016-10-18 22:42:01 | [diff] [blame] | 196 | build.add_bootstrap_key(&mut cmd); |
Alex Crichton | 126e09e | 2016-04-14 22:51:03 | [diff] [blame] | 197 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 198 | cmd.arg("--adb-path").arg("adb"); |
| 199 | cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR); |
| 200 | if target.contains("android") { |
| 201 | // Assume that cc for this target comes from the android sysroot |
| 202 | cmd.arg("--android-cross-path") |
| 203 | .arg(build.cc(target).parent().unwrap().parent().unwrap()); |
| 204 | } else { |
| 205 | cmd.arg("--android-cross-path").arg(""); |
| 206 | } |
| 207 | |
Alex Crichton | b325baf | 2016-04-05 18:34:23 | [diff] [blame] | 208 | build.run(&mut cmd); |
| 209 | } |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 210 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 211 | /// Run `rustdoc --test` for all documentation in `src/doc`. |
| 212 | /// |
| 213 | /// This will run all tests in our markdown documentation (e.g. the book) |
| 214 | /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to |
| 215 | /// `compiler`. |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 216 | pub fn docs(build: &Build, compiler: &Compiler) { |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 217 | // Do a breadth-first traversal of the `src/doc` directory and just run |
| 218 | // tests for all files that end in `*.md` |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 219 | let mut stack = vec![build.src.join("src/doc")]; |
| 220 | |
| 221 | while let Some(p) = stack.pop() { |
| 222 | if p.is_dir() { |
| 223 | stack.extend(t!(p.read_dir()).map(|p| t!(p).path())); |
| 224 | continue |
| 225 | } |
| 226 | |
| 227 | if p.extension().and_then(|s| s.to_str()) != Some("md") { |
| 228 | continue |
| 229 | } |
| 230 | |
| 231 | println!("doc tests for: {}", p.display()); |
| 232 | markdown_test(build, compiler, &p); |
| 233 | } |
| 234 | } |
| 235 | |
Alex Crichton | f72bfe6 | 2016-05-02 22:16:15 | [diff] [blame] | 236 | /// Run the error index generator tool to execute the tests located in the error |
| 237 | /// index. |
| 238 | /// |
| 239 | /// The `error_index_generator` tool lives in `src/tools` and is used to |
| 240 | /// generate a markdown file from the error indexes of the code base which is |
| 241 | /// then passed to `rustdoc --test`. |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 242 | pub fn error_index(build: &Build, compiler: &Compiler) { |
| 243 | println!("Testing error-index stage{}", compiler.stage); |
| 244 | |
| 245 | let output = testdir(build, compiler.host).join("error-index.md"); |
| 246 | build.run(build.tool_cmd(compiler, "error_index_generator") |
| 247 | .arg("markdown") |
| 248 | .arg(&output) |
| 249 | .env("CFG_BUILD", &build.config.build)); |
| 250 | |
| 251 | markdown_test(build, compiler, &output); |
| 252 | } |
| 253 | |
| 254 | fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) { |
| 255 | let mut cmd = Command::new(build.rustdoc(compiler)); |
| 256 | build.add_rustc_lib_path(compiler, &mut cmd); |
| 257 | cmd.arg("--test"); |
| 258 | cmd.arg(markdown); |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 259 | |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame^] | 260 | let mut test_args = build.flags.cmd.test_args().join(" "); |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 261 | if build.config.quiet_tests { |
| 262 | test_args.push_str(" --quiet"); |
| 263 | } |
| 264 | cmd.arg("--test-args").arg(test_args); |
| 265 | |
Alex Crichton | ede8944 | 2016-04-15 01:00:35 | [diff] [blame] | 266 | build.run(&mut cmd); |
| 267 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 268 | |
| 269 | /// Run all unit tests plus documentation tests for an entire crate DAG defined |
| 270 | /// by a `Cargo.toml` |
| 271 | /// |
| 272 | /// This is what runs tests for crates like the standard library, compiler, etc. |
| 273 | /// It essentially is the driver for running `cargo test`. |
| 274 | /// |
| 275 | /// 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] | 276 | /// arguments, and those arguments are discovered from `cargo metadata`. |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 277 | pub fn krate(build: &Build, |
| 278 | compiler: &Compiler, |
| 279 | target: &str, |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame^] | 280 | mode: Mode, |
| 281 | krate: Option<&str>) { |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 282 | let (name, path, features, root) = match mode { |
Ahmed Charles | 9ca382f | 2016-09-02 08:55:29 | [diff] [blame] | 283 | Mode::Libstd => { |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 284 | ("libstd", "src/rustc/std_shim", build.std_features(), "std_shim") |
Ahmed Charles | 9ca382f | 2016-09-02 08:55:29 | [diff] [blame] | 285 | } |
| 286 | Mode::Libtest => { |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 287 | ("libtest", "src/rustc/test_shim", String::new(), "test_shim") |
Ahmed Charles | 9ca382f | 2016-09-02 08:55:29 | [diff] [blame] | 288 | } |
| 289 | Mode::Librustc => { |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 290 | ("librustc", "src/rustc", build.rustc_features(), "rustc-main") |
Ahmed Charles | 9ca382f | 2016-09-02 08:55:29 | [diff] [blame] | 291 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 292 | _ => panic!("can only test libraries"), |
| 293 | }; |
| 294 | println!("Testing {} stage{} ({} -> {})", name, compiler.stage, |
| 295 | compiler.host, target); |
| 296 | |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 297 | // Build up the base `cargo test` command. |
Alex Crichton | 147e2da | 2016-10-07 06:30:38 | [diff] [blame] | 298 | // |
| 299 | // Pass in some standard flags then iterate over the graph we've discovered |
| 300 | // in `cargo metadata` with the maps above and figure out what `-p` |
| 301 | // arguments need to get passed. |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 302 | let mut cargo = build.cargo(compiler, mode, target, "test"); |
| 303 | cargo.arg("--manifest-path") |
| 304 | .arg(build.src.join(path).join("Cargo.toml")) |
| 305 | .arg("--features").arg(features); |
| 306 | |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame^] | 307 | match krate { |
| 308 | Some(krate) => { |
| 309 | cargo.arg("-p").arg(krate); |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 310 | } |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame^] | 311 | None => { |
| 312 | let mut visited = HashSet::new(); |
| 313 | let mut next = vec![root]; |
| 314 | while let Some(name) = next.pop() { |
| 315 | // Right now jemalloc is our only target-specific crate in the sense |
| 316 | // that it's not present on all platforms. Custom skip it here for now, |
| 317 | // but if we add more this probably wants to get more generalized. |
| 318 | if !name.contains("jemalloc") { |
| 319 | cargo.arg("-p").arg(name); |
| 320 | } |
| 321 | for dep in build.crates[name].deps.iter() { |
| 322 | if visited.insert(dep) { |
| 323 | next.push(dep); |
| 324 | } |
| 325 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 326 | } |
| 327 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | // The tests are going to run with the *target* libraries, so we need to |
| 331 | // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent. |
| 332 | // |
| 333 | // Note that to run the compiler we need to run with the *host* libraries, |
| 334 | // but our wrapper scripts arrange for that to be the case anyway. |
| 335 | let mut dylib_path = dylib_path(); |
| 336 | dylib_path.insert(0, build.sysroot_libdir(compiler, target)); |
| 337 | cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap()); |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 338 | |
Corey Farwell | c8c6d2c | 2016-10-30 01:58:52 | [diff] [blame] | 339 | if build.config.quiet_tests { |
| 340 | cargo.arg("--"); |
| 341 | cargo.arg("--quiet"); |
| 342 | } |
| 343 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 344 | if target.contains("android") { |
| 345 | build.run(cargo.arg("--no-run")); |
| 346 | krate_android(build, compiler, target, mode); |
Brian Anderson | b8b50f0 | 2016-09-06 00:41:50 | [diff] [blame] | 347 | } else if target.contains("emscripten") { |
Ross Schulman | ad9184c | 2016-09-05 23:56:48 | [diff] [blame] | 348 | build.run(cargo.arg("--no-run")); |
Brian Anderson | b8b50f0 | 2016-09-06 00:41:50 | [diff] [blame] | 349 | krate_emscripten(build, compiler, target, mode); |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 350 | } else { |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame^] | 351 | cargo.args(&build.flags.cmd.test_args()); |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 352 | build.run(&mut cargo); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | fn krate_android(build: &Build, |
| 357 | compiler: &Compiler, |
| 358 | target: &str, |
| 359 | mode: Mode) { |
| 360 | let mut tests = Vec::new(); |
| 361 | let out_dir = build.cargo_out(compiler, mode, target); |
| 362 | find_tests(&out_dir, target, &mut tests); |
| 363 | find_tests(&out_dir.join("deps"), target, &mut tests); |
| 364 | |
| 365 | for test in tests { |
| 366 | build.run(Command::new("adb").arg("push").arg(&test).arg(ADB_TEST_DIR)); |
| 367 | |
| 368 | let test_file_name = test.file_name().unwrap().to_string_lossy(); |
| 369 | let log = format!("{}/check-stage{}-T-{}-H-{}-{}.log", |
| 370 | ADB_TEST_DIR, |
| 371 | compiler.stage, |
| 372 | target, |
| 373 | compiler.host, |
| 374 | test_file_name); |
| 375 | let program = format!("(cd {dir}; \ |
| 376 | LD_LIBRARY_PATH=./{target} ./{test} \ |
| 377 | --logfile {log} \ |
| 378 | {args})", |
| 379 | dir = ADB_TEST_DIR, |
| 380 | target = target, |
| 381 | test = test_file_name, |
| 382 | log = log, |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame^] | 383 | args = build.flags.cmd.test_args().join(" ")); |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 384 | |
| 385 | let output = output(Command::new("adb").arg("shell").arg(&program)); |
| 386 | println!("{}", output); |
| 387 | build.run(Command::new("adb") |
| 388 | .arg("pull") |
| 389 | .arg(&log) |
| 390 | .arg(build.out.join("tmp"))); |
| 391 | build.run(Command::new("adb").arg("shell").arg("rm").arg(&log)); |
| 392 | if !output.contains("result: ok") { |
| 393 | panic!("some tests failed"); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
Brian Anderson | b8b50f0 | 2016-09-06 00:41:50 | [diff] [blame] | 398 | fn krate_emscripten(build: &Build, |
| 399 | compiler: &Compiler, |
| 400 | target: &str, |
| 401 | mode: Mode) { |
Ross Schulman | ad9184c | 2016-09-05 23:56:48 | [diff] [blame] | 402 | let mut tests = Vec::new(); |
| 403 | let out_dir = build.cargo_out(compiler, mode, target); |
| 404 | find_tests(&out_dir, target, &mut tests); |
| 405 | find_tests(&out_dir.join("deps"), target, &mut tests); |
| 406 | |
| 407 | for test in tests { |
| 408 | let test_file_name = test.to_string_lossy().into_owned(); |
Brian Anderson | fcd3279 | 2016-09-06 20:36:14 | [diff] [blame] | 409 | println!("running {}", test_file_name); |
Brian Anderson | 8401e37 | 2016-09-15 19:42:26 | [diff] [blame] | 410 | let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured"); |
Brian Anderson | badfd62 | 2016-09-27 19:56:50 | [diff] [blame] | 411 | let status = Command::new(nodejs) |
Brian Anderson | fcd3279 | 2016-09-06 20:36:14 | [diff] [blame] | 412 | .arg(&test_file_name) |
| 413 | .stderr(::std::process::Stdio::inherit()) |
Brian Anderson | badfd62 | 2016-09-27 19:56:50 | [diff] [blame] | 414 | .status(); |
| 415 | match status { |
| 416 | Ok(status) => { |
| 417 | if !status.success() { |
| 418 | panic!("some tests failed"); |
| 419 | } |
| 420 | } |
Brian Anderson | fcd3279 | 2016-09-06 20:36:14 | [diff] [blame] | 421 | Err(e) => panic!(format!("failed to execute command: {}", e)), |
| 422 | }; |
Ross Schulman | ad9184c | 2016-09-05 23:56:48 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 427 | fn find_tests(dir: &Path, |
| 428 | target: &str, |
| 429 | dst: &mut Vec<PathBuf>) { |
| 430 | for e in t!(dir.read_dir()).map(|e| t!(e)) { |
| 431 | let file_type = t!(e.file_type()); |
| 432 | if !file_type.is_file() { |
| 433 | continue |
| 434 | } |
| 435 | let filename = e.file_name().into_string().unwrap(); |
| 436 | if (target.contains("windows") && filename.ends_with(".exe")) || |
Ross Schulman | ad9184c | 2016-09-05 23:56:48 | [diff] [blame] | 437 | (!target.contains("windows") && !filename.contains(".")) || |
Brian Anderson | fcd3279 | 2016-09-06 20:36:14 | [diff] [blame] | 438 | (target.contains("emscripten") && filename.contains(".js")){ |
Alex Crichton | 39a5d3f | 2016-06-28 20:31:30 | [diff] [blame] | 439 | dst.push(e.path()); |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | pub fn android_copy_libs(build: &Build, |
| 445 | compiler: &Compiler, |
| 446 | target: &str) { |
| 447 | println!("Android copy libs to emulator ({})", target); |
| 448 | build.run(Command::new("adb").arg("remount")); |
| 449 | build.run(Command::new("adb").args(&["shell", "rm", "-r", ADB_TEST_DIR])); |
| 450 | build.run(Command::new("adb").args(&["shell", "mkdir", ADB_TEST_DIR])); |
| 451 | build.run(Command::new("adb") |
| 452 | .arg("push") |
| 453 | .arg(build.src.join("src/etc/adb_run_wrapper.sh")) |
| 454 | .arg(ADB_TEST_DIR)); |
| 455 | |
| 456 | let target_dir = format!("{}/{}", ADB_TEST_DIR, target); |
| 457 | build.run(Command::new("adb").args(&["shell", "mkdir", &target_dir[..]])); |
| 458 | |
| 459 | for f in t!(build.sysroot_libdir(compiler, target).read_dir()) { |
| 460 | let f = t!(f); |
| 461 | let name = f.file_name().into_string().unwrap(); |
| 462 | if util::is_dylib(&name) { |
| 463 | build.run(Command::new("adb") |
| 464 | .arg("push") |
| 465 | .arg(f.path()) |
| 466 | .arg(&target_dir)); |
| 467 | } |
| 468 | } |
Alex Crichton | bb9062a | 2016-04-29 21:23:15 | [diff] [blame] | 469 | } |