blob: c5675fd46cbe07f4cedfeb0bed4047ab439eb424 [file] [log] [blame]
Alex Crichtondefd1b32016-03-08 07:15:551// 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 Crichton0e272de2016-11-16 20:31:1911//! Implementation of the test-related targets of the build system.
Alex Crichtonf72bfe62016-05-02 22:16:1512//!
13//! This file implements the various regression test suites that we execute on
14//! our CI.
15
Alex Crichtona270b802016-10-21 20:18:0916use std::collections::HashSet;
Alex Crichtonbb9062a2016-04-29 21:23:1517use std::env;
Ulrik Sverdrupb1566ba2016-11-25 21:13:5918use std::fmt;
Alex Crichton147e2da2016-10-07 06:30:3819use std::fs;
Alex Crichtonede89442016-04-15 01:00:3520use std::path::{PathBuf, Path};
21use std::process::Command;
Alex Crichton73c2d2a2016-04-14 21:27:5122
Alex Crichton126e09e2016-04-14 22:51:0323use build_helper::output;
24
Alex Crichton48a07bf2016-07-06 04:58:2025use {Build, Compiler, Mode};
26use util::{self, dylib_path, dylib_path_var};
Alex Crichton39a5d3f2016-06-28 20:31:3027
28const ADB_TEST_DIR: &'static str = "/data/tmp";
Alex Crichtondefd1b32016-03-08 07:15:5529
Ulrik Sverdrupb1566ba2016-11-25 21:13:5930/// The two modes of the test runner; tests or benchmarks.
31#[derive(Copy, Clone)]
32pub enum TestKind {
33 /// Run `cargo test`
34 Test,
35 /// Run `cargo bench`
36 Bench,
37}
38
39impl TestKind {
40 // Return the cargo subcommand for this test kind
41 fn subcommand(self) -> &'static str {
42 match self {
43 TestKind::Test => "test",
44 TestKind::Bench => "bench",
45 }
46 }
47}
48
49impl fmt::Display for TestKind {
50 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51 f.write_str(match *self {
52 TestKind::Test => "Testing",
53 TestKind::Bench => "Benchmarking",
54 })
55 }
56}
57
Alex Crichtonf72bfe62016-05-02 22:16:1558/// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
59///
60/// This tool in `src/tools` will verify the validity of all our links in the
61/// documentation to ensure we don't have a bunch of dead ones.
Alex Crichtondefd1b32016-03-08 07:15:5562pub fn linkcheck(build: &Build, stage: u32, host: &str) {
63 println!("Linkcheck stage{} ({})", stage, host);
64 let compiler = Compiler::new(stage, host);
Alex Crichton0e272de2016-11-16 20:31:1965
66 let _time = util::timeit();
Alex Crichton4a917e02016-03-12 00:21:0567 build.run(build.tool_cmd(&compiler, "linkchecker")
68 .arg(build.out.join(host).join("doc")));
Alex Crichtondefd1b32016-03-08 07:15:5569}
Brian Anderson3a790ac2016-03-18 20:54:3170
Alex Crichtonf72bfe62016-05-02 22:16:1571/// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
72///
73/// This tool in `src/tools` will check out a few Rust projects and run `cargo
74/// test` to ensure that we don't regress the test suites there.
Brian Anderson3a790ac2016-03-18 20:54:3175pub fn cargotest(build: &Build, stage: u32, host: &str) {
76 let ref compiler = Compiler::new(stage, host);
Brian Anderson80199222016-04-06 18:03:4277
78 // Configure PATH to find the right rustc. NB. we have to use PATH
79 // and not RUSTC because the Cargo test suite has tests that will
80 // fail if rustc is not spelled `rustc`.
81 let path = build.sysroot(compiler).join("bin");
82 let old_path = ::std::env::var("PATH").expect("");
83 let sep = if cfg!(windows) { ";" } else {":" };
84 let ref newpath = format!("{}{}{}", path.display(), sep, old_path);
85
Alex Crichton73c2d2a2016-04-14 21:27:5186 // Note that this is a short, cryptic, and not scoped directory name. This
87 // is currently to minimize the length of path on Windows where we otherwise
88 // quickly run into path name limit constraints.
89 let out_dir = build.out.join("ct");
90 t!(fs::create_dir_all(&out_dir));
91
Alex Crichton0e272de2016-11-16 20:31:1992 let _time = util::timeit();
Brian Anderson3a790ac2016-03-18 20:54:3193 build.run(build.tool_cmd(compiler, "cargotest")
Alex Crichton73c2d2a2016-04-14 21:27:5194 .env("PATH", newpath)
95 .arg(&build.cargo)
96 .arg(&out_dir));
Brian Anderson3a790ac2016-03-18 20:54:3197}
Alex Crichton9dd3c542016-03-29 20:14:5298
Alex Crichtonf72bfe62016-05-02 22:16:1599/// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
100///
101/// This tool in `src/tools` checks up on various bits and pieces of style and
102/// otherwise just implements a few lint-like checks that are specific to the
103/// compiler itself.
Alex Crichton9dd3c542016-03-29 20:14:52104pub fn tidy(build: &Build, stage: u32, host: &str) {
105 println!("tidy check stage{} ({})", stage, host);
106 let compiler = Compiler::new(stage, host);
107 build.run(build.tool_cmd(&compiler, "tidy")
108 .arg(build.src.join("src")));
109}
Alex Crichtonb325baf2016-04-05 18:34:23110
111fn testdir(build: &Build, host: &str) -> PathBuf {
112 build.out.join(host).join("test")
113}
114
Alex Crichtonf72bfe62016-05-02 22:16:15115/// Executes the `compiletest` tool to run a suite of tests.
116///
117/// Compiles all tests with `compiler` for `target` with the specified
118/// compiletest `mode` and `suite` arguments. For example `mode` can be
119/// "run-pass" or `suite` can be something like `debuginfo`.
Alex Crichtonb325baf2016-04-05 18:34:23120pub fn compiletest(build: &Build,
121 compiler: &Compiler,
122 target: &str,
123 mode: &str,
124 suite: &str) {
Alex Crichton0e272de2016-11-16 20:31:19125 println!("Check compiletest suite={} mode={} ({} -> {})",
126 suite, mode, compiler.host, target);
Alex Crichtonb325baf2016-04-05 18:34:23127 let mut cmd = build.tool_cmd(compiler, "compiletest");
128
Alex Crichtonf72bfe62016-05-02 22:16:15129 // compiletest currently has... a lot of arguments, so let's just pass all
130 // of them!
131
Alex Crichtonb325baf2016-04-05 18:34:23132 cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler));
133 cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target));
134 cmd.arg("--rustc-path").arg(build.compiler_path(compiler));
135 cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler));
136 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
Alex Crichtonb325baf2016-04-05 18:34:23137 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
138 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
139 cmd.arg("--mode").arg(mode);
140 cmd.arg("--target").arg(target);
141 cmd.arg("--host").arg(compiler.host);
142 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.config.build));
143
Brian Anderson8401e372016-09-15 19:42:26144 if let Some(nodejs) = build.config.nodejs.as_ref() {
145 cmd.arg("--nodejs").arg(nodejs);
146 }
147
Alex Crichton39a5d3f2016-06-28 20:31:30148 let mut flags = vec!["-Crpath".to_string()];
Alex Crichtonf4e4ec72016-05-13 22:26:41149 if build.config.rust_optimize_tests {
Alex Crichton39a5d3f2016-06-28 20:31:30150 flags.push("-O".to_string());
Alex Crichtonf4e4ec72016-05-13 22:26:41151 }
152 if build.config.rust_debuginfo_tests {
Alex Crichton39a5d3f2016-06-28 20:31:30153 flags.push("-g".to_string());
Alex Crichtonf4e4ec72016-05-13 22:26:41154 }
155
Alex Crichton39a5d3f2016-06-28 20:31:30156 let mut hostflags = build.rustc_flags(&compiler.host);
157 hostflags.extend(flags.clone());
158 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtonf4e4ec72016-05-13 22:26:41159
Alex Crichton39a5d3f2016-06-28 20:31:30160 let mut targetflags = build.rustc_flags(&target);
161 targetflags.extend(flags);
162 targetflags.push(format!("-Lnative={}",
163 build.test_helpers_out(target).display()));
164 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19165
Alex Crichton5f6261382016-11-14 16:04:39166 cmd.arg("--docck-python").arg(build.python());
Alex Crichtoncbe62922016-04-19 16:44:19167
168 if build.config.build.ends_with("apple-darwin") {
169 // Force /usr/bin/python on OSX for LLDB tests because we're loading the
170 // LLDB plugin's compiled module which only works with the system python
171 // (namely not Homebrew-installed python)
172 cmd.arg("--lldb-python").arg("/usr/bin/python");
173 } else {
Alex Crichton5f6261382016-11-14 16:04:39174 cmd.arg("--lldb-python").arg(build.python());
Alex Crichtoncbe62922016-04-19 16:44:19175 }
Alex Crichtonb325baf2016-04-05 18:34:23176
Tim Neumanndce46002016-10-29 18:11:53177 if let Some(ref gdb) = build.config.gdb {
178 cmd.arg("--gdb").arg(gdb);
Alex Crichtonb325baf2016-04-05 18:34:23179 }
180 if let Some(ref vers) = build.lldb_version {
181 cmd.arg("--lldb-version").arg(vers);
182 }
183 if let Some(ref dir) = build.lldb_python_dir {
184 cmd.arg("--lldb-python-dir").arg(dir);
185 }
Alex Crichton96283fc2016-09-01 17:52:44186 let llvm_config = build.llvm_config(target);
187 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
188 cmd.arg("--llvm-version").arg(llvm_version);
Alex Crichtonb325baf2016-04-05 18:34:23189
Alex Crichtona270b802016-10-21 20:18:09190 cmd.args(&build.flags.cmd.test_args());
Alex Crichtonb325baf2016-04-05 18:34:23191
192 if build.config.verbose || build.flags.verbose {
193 cmd.arg("--verbose");
194 }
195
Corey Farwellc8c6d2c2016-10-30 01:58:52196 if build.config.quiet_tests {
197 cmd.arg("--quiet");
198 }
199
Alex Crichtonf72bfe62016-05-02 22:16:15200 // Only pass correct values for these flags for the `run-make` suite as it
201 // requires that a C++ compiler was configured which isn't always the case.
Alex Crichton126e09e2016-04-14 22:51:03202 if suite == "run-make" {
Alex Crichton126e09e2016-04-14 22:51:03203 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
204 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
205 cmd.arg("--cc").arg(build.cc(target))
206 .arg("--cxx").arg(build.cxx(target))
207 .arg("--cflags").arg(build.cflags(target).join(" "))
208 .arg("--llvm-components").arg(llvm_components.trim())
209 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
210 } else {
211 cmd.arg("--cc").arg("")
212 .arg("--cxx").arg("")
213 .arg("--cflags").arg("")
214 .arg("--llvm-components").arg("")
215 .arg("--llvm-cxxflags").arg("");
216 }
217
218 // Running a C compiler on MSVC requires a few env vars to be set, to be
219 // sure to set them here.
Alex Crichton0e272de2016-11-16 20:31:19220 //
221 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
222 // rather than stomp over it.
Alex Crichton126e09e2016-04-14 22:51:03223 if target.contains("msvc") {
224 for &(ref k, ref v) in build.cc[target].0.env() {
225 if k != "PATH" {
226 cmd.env(k, v);
227 }
228 }
229 }
Alex Crichton21866602016-11-16 17:19:02230 cmd.env("RUSTC_BOOTSTRAP", "1");
Alex Crichton0e272de2016-11-16 20:31:19231 build.add_rust_test_threads(&mut cmd);
Alex Crichton126e09e2016-04-14 22:51:03232
Alex Crichton39a5d3f2016-06-28 20:31:30233 cmd.arg("--adb-path").arg("adb");
234 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
235 if target.contains("android") {
236 // Assume that cc for this target comes from the android sysroot
237 cmd.arg("--android-cross-path")
238 .arg(build.cc(target).parent().unwrap().parent().unwrap());
239 } else {
240 cmd.arg("--android-cross-path").arg("");
241 }
242
Alex Crichton0e272de2016-11-16 20:31:19243 let _time = util::timeit();
Alex Crichtonb325baf2016-04-05 18:34:23244 build.run(&mut cmd);
245}
Alex Crichtonede89442016-04-15 01:00:35246
Alex Crichtonf72bfe62016-05-02 22:16:15247/// Run `rustdoc --test` for all documentation in `src/doc`.
248///
249/// This will run all tests in our markdown documentation (e.g. the book)
250/// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
251/// `compiler`.
Alex Crichtonede89442016-04-15 01:00:35252pub fn docs(build: &Build, compiler: &Compiler) {
Alex Crichtonf72bfe62016-05-02 22:16:15253 // Do a breadth-first traversal of the `src/doc` directory and just run
254 // tests for all files that end in `*.md`
Alex Crichtonede89442016-04-15 01:00:35255 let mut stack = vec![build.src.join("src/doc")];
Alex Crichton0e272de2016-11-16 20:31:19256 let _time = util::timeit();
Alex Crichtonede89442016-04-15 01:00:35257
258 while let Some(p) = stack.pop() {
259 if p.is_dir() {
260 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
261 continue
262 }
263
264 if p.extension().and_then(|s| s.to_str()) != Some("md") {
265 continue
266 }
267
268 println!("doc tests for: {}", p.display());
269 markdown_test(build, compiler, &p);
270 }
271}
272
Alex Crichtonf72bfe62016-05-02 22:16:15273/// Run the error index generator tool to execute the tests located in the error
274/// index.
275///
276/// The `error_index_generator` tool lives in `src/tools` and is used to
277/// generate a markdown file from the error indexes of the code base which is
278/// then passed to `rustdoc --test`.
Alex Crichtonede89442016-04-15 01:00:35279pub fn error_index(build: &Build, compiler: &Compiler) {
280 println!("Testing error-index stage{}", compiler.stage);
281
Alex Crichton860c6ab2016-11-08 17:59:46282 let dir = testdir(build, compiler.host);
283 t!(fs::create_dir_all(&dir));
284 let output = dir.join("error-index.md");
Alex Crichton0e272de2016-11-16 20:31:19285
286 let _time = util::timeit();
Alex Crichtonede89442016-04-15 01:00:35287 build.run(build.tool_cmd(compiler, "error_index_generator")
288 .arg("markdown")
289 .arg(&output)
290 .env("CFG_BUILD", &build.config.build));
291
292 markdown_test(build, compiler, &output);
293}
294
295fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
296 let mut cmd = Command::new(build.rustdoc(compiler));
297 build.add_rustc_lib_path(compiler, &mut cmd);
Alex Crichton0e272de2016-11-16 20:31:19298 build.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:35299 cmd.arg("--test");
300 cmd.arg(markdown);
Corey Farwellc8c6d2c2016-10-30 01:58:52301
Alex Crichtona270b802016-10-21 20:18:09302 let mut test_args = build.flags.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:52303 if build.config.quiet_tests {
304 test_args.push_str(" --quiet");
305 }
306 cmd.arg("--test-args").arg(test_args);
307
Alex Crichtonede89442016-04-15 01:00:35308 build.run(&mut cmd);
309}
Alex Crichtonbb9062a2016-04-29 21:23:15310
311/// Run all unit tests plus documentation tests for an entire crate DAG defined
312/// by a `Cargo.toml`
313///
314/// This is what runs tests for crates like the standard library, compiler, etc.
315/// It essentially is the driver for running `cargo test`.
316///
317/// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
Alex Crichton147e2da2016-10-07 06:30:38318/// arguments, and those arguments are discovered from `cargo metadata`.
Alex Crichtonbb9062a2016-04-29 21:23:15319pub fn krate(build: &Build,
320 compiler: &Compiler,
321 target: &str,
Alex Crichtona270b802016-10-21 20:18:09322 mode: Mode,
Ulrik Sverdrupb1566ba2016-11-25 21:13:59323 test_kind: TestKind,
Alex Crichtona270b802016-10-21 20:18:09324 krate: Option<&str>) {
Alex Crichton147e2da2016-10-07 06:30:38325 let (name, path, features, root) = match mode {
Ahmed Charles9ca382f2016-09-02 08:55:29326 Mode::Libstd => {
Alex Crichton147e2da2016-10-07 06:30:38327 ("libstd", "src/rustc/std_shim", build.std_features(), "std_shim")
Ahmed Charles9ca382f2016-09-02 08:55:29328 }
329 Mode::Libtest => {
Alex Crichton147e2da2016-10-07 06:30:38330 ("libtest", "src/rustc/test_shim", String::new(), "test_shim")
Ahmed Charles9ca382f2016-09-02 08:55:29331 }
332 Mode::Librustc => {
Alex Crichton147e2da2016-10-07 06:30:38333 ("librustc", "src/rustc", build.rustc_features(), "rustc-main")
Ahmed Charles9ca382f2016-09-02 08:55:29334 }
Alex Crichtonbb9062a2016-04-29 21:23:15335 _ => panic!("can only test libraries"),
336 };
Ulrik Sverdrupb1566ba2016-11-25 21:13:59337 println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
Alex Crichtonbb9062a2016-04-29 21:23:15338 compiler.host, target);
339
340 // Build up the base `cargo test` command.
Alex Crichton147e2da2016-10-07 06:30:38341 //
342 // Pass in some standard flags then iterate over the graph we've discovered
343 // in `cargo metadata` with the maps above and figure out what `-p`
344 // arguments need to get passed.
Ulrik Sverdrupb1566ba2016-11-25 21:13:59345 let mut cargo = build.cargo(compiler, mode, target, test_kind.subcommand());
Alex Crichtonbb9062a2016-04-29 21:23:15346 cargo.arg("--manifest-path")
347 .arg(build.src.join(path).join("Cargo.toml"))
348 .arg("--features").arg(features);
349
Alex Crichtona270b802016-10-21 20:18:09350 match krate {
351 Some(krate) => {
352 cargo.arg("-p").arg(krate);
Alex Crichtonbb9062a2016-04-29 21:23:15353 }
Alex Crichtona270b802016-10-21 20:18:09354 None => {
355 let mut visited = HashSet::new();
356 let mut next = vec![root];
357 while let Some(name) = next.pop() {
358 // Right now jemalloc is our only target-specific crate in the sense
359 // that it's not present on all platforms. Custom skip it here for now,
360 // but if we add more this probably wants to get more generalized.
361 if !name.contains("jemalloc") {
362 cargo.arg("-p").arg(name);
363 }
364 for dep in build.crates[name].deps.iter() {
365 if visited.insert(dep) {
366 next.push(dep);
367 }
368 }
Alex Crichtonbb9062a2016-04-29 21:23:15369 }
370 }
Alex Crichtonbb9062a2016-04-29 21:23:15371 }
372
373 // The tests are going to run with the *target* libraries, so we need to
374 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
375 //
376 // Note that to run the compiler we need to run with the *host* libraries,
377 // but our wrapper scripts arrange for that to be the case anyway.
378 let mut dylib_path = dylib_path();
379 dylib_path.insert(0, build.sysroot_libdir(compiler, target));
380 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:15381
Alex Crichton0e272de2016-11-16 20:31:19382 if target.contains("android") {
383 cargo.arg("--no-run");
384 } else if target.contains("emscripten") {
385 cargo.arg("--no-run");
386 }
387
388 cargo.arg("--");
389
Corey Farwellc8c6d2c2016-10-30 01:58:52390 if build.config.quiet_tests {
Corey Farwellc8c6d2c2016-10-30 01:58:52391 cargo.arg("--quiet");
392 }
393
Alex Crichton0e272de2016-11-16 20:31:19394 let _time = util::timeit();
395
Alex Crichton39a5d3f2016-06-28 20:31:30396 if target.contains("android") {
Alex Crichton0e272de2016-11-16 20:31:19397 build.run(&mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:30398 krate_android(build, compiler, target, mode);
Brian Andersonb8b50f02016-09-06 00:41:50399 } else if target.contains("emscripten") {
Alex Crichton0e272de2016-11-16 20:31:19400 build.run(&mut cargo);
Brian Andersonb8b50f02016-09-06 00:41:50401 krate_emscripten(build, compiler, target, mode);
Alex Crichton39a5d3f2016-06-28 20:31:30402 } else {
Alex Crichtona270b802016-10-21 20:18:09403 cargo.args(&build.flags.cmd.test_args());
Alex Crichton39a5d3f2016-06-28 20:31:30404 build.run(&mut cargo);
405 }
406}
407
408fn krate_android(build: &Build,
409 compiler: &Compiler,
410 target: &str,
411 mode: Mode) {
412 let mut tests = Vec::new();
413 let out_dir = build.cargo_out(compiler, mode, target);
414 find_tests(&out_dir, target, &mut tests);
415 find_tests(&out_dir.join("deps"), target, &mut tests);
416
417 for test in tests {
418 build.run(Command::new("adb").arg("push").arg(&test).arg(ADB_TEST_DIR));
419
420 let test_file_name = test.file_name().unwrap().to_string_lossy();
421 let log = format!("{}/check-stage{}-T-{}-H-{}-{}.log",
422 ADB_TEST_DIR,
423 compiler.stage,
424 target,
425 compiler.host,
426 test_file_name);
Alex Crichton0e272de2016-11-16 20:31:19427 let quiet = if build.config.quiet_tests { "--quiet" } else { "" };
Alex Crichton39a5d3f2016-06-28 20:31:30428 let program = format!("(cd {dir}; \
429 LD_LIBRARY_PATH=./{target} ./{test} \
430 --logfile {log} \
Alex Crichton0e272de2016-11-16 20:31:19431 {quiet} \
Alex Crichton39a5d3f2016-06-28 20:31:30432 {args})",
433 dir = ADB_TEST_DIR,
434 target = target,
435 test = test_file_name,
436 log = log,
Alex Crichton0e272de2016-11-16 20:31:19437 quiet = quiet,
Alex Crichtona270b802016-10-21 20:18:09438 args = build.flags.cmd.test_args().join(" "));
Alex Crichton39a5d3f2016-06-28 20:31:30439
440 let output = output(Command::new("adb").arg("shell").arg(&program));
441 println!("{}", output);
442 build.run(Command::new("adb")
443 .arg("pull")
444 .arg(&log)
445 .arg(build.out.join("tmp")));
446 build.run(Command::new("adb").arg("shell").arg("rm").arg(&log));
447 if !output.contains("result: ok") {
448 panic!("some tests failed");
449 }
450 }
451}
452
Brian Andersonb8b50f02016-09-06 00:41:50453fn krate_emscripten(build: &Build,
454 compiler: &Compiler,
455 target: &str,
456 mode: Mode) {
Ross Schulmanad9184c2016-09-05 23:56:48457 let mut tests = Vec::new();
458 let out_dir = build.cargo_out(compiler, mode, target);
459 find_tests(&out_dir, target, &mut tests);
460 find_tests(&out_dir.join("deps"), target, &mut tests);
461
462 for test in tests {
463 let test_file_name = test.to_string_lossy().into_owned();
Brian Andersonfcd32792016-09-06 20:36:14464 println!("running {}", test_file_name);
Brian Anderson8401e372016-09-15 19:42:26465 let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
Alex Crichton0e272de2016-11-16 20:31:19466 let mut cmd = Command::new(nodejs);
467 cmd.arg(&test_file_name)
468 .stderr(::std::process::Stdio::inherit());
469 if build.config.quiet_tests {
470 cmd.arg("--quiet");
471 }
472 build.run(&mut cmd);
Ross Schulmanad9184c2016-09-05 23:56:48473 }
474 }
475
476
Alex Crichton39a5d3f2016-06-28 20:31:30477fn find_tests(dir: &Path,
478 target: &str,
479 dst: &mut Vec<PathBuf>) {
480 for e in t!(dir.read_dir()).map(|e| t!(e)) {
481 let file_type = t!(e.file_type());
482 if !file_type.is_file() {
483 continue
484 }
485 let filename = e.file_name().into_string().unwrap();
486 if (target.contains("windows") && filename.ends_with(".exe")) ||
Ross Schulmanad9184c2016-09-05 23:56:48487 (!target.contains("windows") && !filename.contains(".")) ||
Brian Andersonfcd32792016-09-06 20:36:14488 (target.contains("emscripten") && filename.contains(".js")){
Alex Crichton39a5d3f2016-06-28 20:31:30489 dst.push(e.path());
490 }
491 }
492}
493
494pub fn android_copy_libs(build: &Build,
495 compiler: &Compiler,
496 target: &str) {
497 println!("Android copy libs to emulator ({})", target);
498 build.run(Command::new("adb").arg("remount"));
499 build.run(Command::new("adb").args(&["shell", "rm", "-r", ADB_TEST_DIR]));
500 build.run(Command::new("adb").args(&["shell", "mkdir", ADB_TEST_DIR]));
501 build.run(Command::new("adb")
502 .arg("push")
503 .arg(build.src.join("src/etc/adb_run_wrapper.sh"))
504 .arg(ADB_TEST_DIR));
505
506 let target_dir = format!("{}/{}", ADB_TEST_DIR, target);
507 build.run(Command::new("adb").args(&["shell", "mkdir", &target_dir[..]]));
508
509 for f in t!(build.sysroot_libdir(compiler, target).read_dir()) {
510 let f = t!(f);
511 let name = f.file_name().into_string().unwrap();
512 if util::is_dylib(&name) {
513 build.run(Command::new("adb")
514 .arg("push")
515 .arg(f.path())
516 .arg(&target_dir));
517 }
518 }
Alex Crichtonbb9062a2016-04-29 21:23:15519}