blob: 712c4c52baa5f55ab9b7ada5dfdaf850eda72aa4 [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};
Alex Crichtond38db822016-12-09 01:13:5526use dist;
Alex Crichton48a07bf2016-07-06 04:58:2027use util::{self, dylib_path, dylib_path_var};
Alex Crichton39a5d3f2016-06-28 20:31:3028
29const ADB_TEST_DIR: &'static str = "/data/tmp";
Alex Crichtondefd1b32016-03-08 07:15:5530
Ulrik Sverdrupb1566ba2016-11-25 21:13:5931/// The two modes of the test runner; tests or benchmarks.
32#[derive(Copy, Clone)]
33pub enum TestKind {
34 /// Run `cargo test`
35 Test,
36 /// Run `cargo bench`
37 Bench,
38}
39
40impl TestKind {
41 // Return the cargo subcommand for this test kind
42 fn subcommand(self) -> &'static str {
43 match self {
44 TestKind::Test => "test",
45 TestKind::Bench => "bench",
46 }
47 }
48}
49
50impl fmt::Display for TestKind {
51 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52 f.write_str(match *self {
53 TestKind::Test => "Testing",
54 TestKind::Bench => "Benchmarking",
55 })
56 }
57}
58
Alex Crichtonf72bfe62016-05-02 22:16:1559/// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
60///
61/// This tool in `src/tools` will verify the validity of all our links in the
62/// documentation to ensure we don't have a bunch of dead ones.
Alex Crichtondefd1b32016-03-08 07:15:5563pub fn linkcheck(build: &Build, stage: u32, host: &str) {
64 println!("Linkcheck stage{} ({})", stage, host);
65 let compiler = Compiler::new(stage, host);
Alex Crichton0e272de2016-11-16 20:31:1966
67 let _time = util::timeit();
Alex Crichton4a917e02016-03-12 00:21:0568 build.run(build.tool_cmd(&compiler, "linkchecker")
69 .arg(build.out.join(host).join("doc")));
Alex Crichtondefd1b32016-03-08 07:15:5570}
Brian Anderson3a790ac2016-03-18 20:54:3171
Alex Crichtonf72bfe62016-05-02 22:16:1572/// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
73///
74/// This tool in `src/tools` will check out a few Rust projects and run `cargo
75/// test` to ensure that we don't regress the test suites there.
Brian Anderson3a790ac2016-03-18 20:54:3176pub fn cargotest(build: &Build, stage: u32, host: &str) {
77 let ref compiler = Compiler::new(stage, host);
Brian Anderson80199222016-04-06 18:03:4278
79 // Configure PATH to find the right rustc. NB. we have to use PATH
80 // and not RUSTC because the Cargo test suite has tests that will
81 // fail if rustc is not spelled `rustc`.
82 let path = build.sysroot(compiler).join("bin");
83 let old_path = ::std::env::var("PATH").expect("");
84 let sep = if cfg!(windows) { ";" } else {":" };
85 let ref newpath = format!("{}{}{}", path.display(), sep, old_path);
86
Alex Crichton73c2d2a2016-04-14 21:27:5187 // Note that this is a short, cryptic, and not scoped directory name. This
88 // is currently to minimize the length of path on Windows where we otherwise
89 // quickly run into path name limit constraints.
90 let out_dir = build.out.join("ct");
91 t!(fs::create_dir_all(&out_dir));
92
Alex Crichton0e272de2016-11-16 20:31:1993 let _time = util::timeit();
Brian Anderson3a790ac2016-03-18 20:54:3194 build.run(build.tool_cmd(compiler, "cargotest")
Alex Crichton73c2d2a2016-04-14 21:27:5195 .env("PATH", newpath)
96 .arg(&build.cargo)
97 .arg(&out_dir));
Brian Anderson3a790ac2016-03-18 20:54:3198}
Alex Crichton9dd3c542016-03-29 20:14:5299
Alex Crichtonf72bfe62016-05-02 22:16:15100/// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
101///
102/// This tool in `src/tools` checks up on various bits and pieces of style and
103/// otherwise just implements a few lint-like checks that are specific to the
104/// compiler itself.
Alex Crichton9dd3c542016-03-29 20:14:52105pub fn tidy(build: &Build, stage: u32, host: &str) {
106 println!("tidy check stage{} ({})", stage, host);
107 let compiler = Compiler::new(stage, host);
108 build.run(build.tool_cmd(&compiler, "tidy")
109 .arg(build.src.join("src")));
110}
Alex Crichtonb325baf2016-04-05 18:34:23111
112fn testdir(build: &Build, host: &str) -> PathBuf {
113 build.out.join(host).join("test")
114}
115
Alex Crichtonf72bfe62016-05-02 22:16:15116/// Executes the `compiletest` tool to run a suite of tests.
117///
118/// Compiles all tests with `compiler` for `target` with the specified
119/// compiletest `mode` and `suite` arguments. For example `mode` can be
120/// "run-pass" or `suite` can be something like `debuginfo`.
Alex Crichtonb325baf2016-04-05 18:34:23121pub fn compiletest(build: &Build,
122 compiler: &Compiler,
123 target: &str,
124 mode: &str,
125 suite: &str) {
Alex Crichton0e272de2016-11-16 20:31:19126 println!("Check compiletest suite={} mode={} ({} -> {})",
127 suite, mode, compiler.host, target);
Alex Crichtonb325baf2016-04-05 18:34:23128 let mut cmd = build.tool_cmd(compiler, "compiletest");
129
Alex Crichtonf72bfe62016-05-02 22:16:15130 // compiletest currently has... a lot of arguments, so let's just pass all
131 // of them!
132
Alex Crichtonb325baf2016-04-05 18:34:23133 cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler));
134 cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target));
135 cmd.arg("--rustc-path").arg(build.compiler_path(compiler));
136 cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler));
137 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
Alex Crichtonb325baf2016-04-05 18:34:23138 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
139 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
140 cmd.arg("--mode").arg(mode);
141 cmd.arg("--target").arg(target);
142 cmd.arg("--host").arg(compiler.host);
143 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.config.build));
144
Brian Anderson8401e372016-09-15 19:42:26145 if let Some(nodejs) = build.config.nodejs.as_ref() {
146 cmd.arg("--nodejs").arg(nodejs);
147 }
148
Alex Crichton39a5d3f2016-06-28 20:31:30149 let mut flags = vec!["-Crpath".to_string()];
Alex Crichtonf4e4ec72016-05-13 22:26:41150 if build.config.rust_optimize_tests {
Alex Crichton39a5d3f2016-06-28 20:31:30151 flags.push("-O".to_string());
Alex Crichtonf4e4ec72016-05-13 22:26:41152 }
153 if build.config.rust_debuginfo_tests {
Alex Crichton39a5d3f2016-06-28 20:31:30154 flags.push("-g".to_string());
Alex Crichtonf4e4ec72016-05-13 22:26:41155 }
156
Alex Crichton39a5d3f2016-06-28 20:31:30157 let mut hostflags = build.rustc_flags(&compiler.host);
158 hostflags.extend(flags.clone());
159 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
Alex Crichtonf4e4ec72016-05-13 22:26:41160
Alex Crichton39a5d3f2016-06-28 20:31:30161 let mut targetflags = build.rustc_flags(&target);
162 targetflags.extend(flags);
163 targetflags.push(format!("-Lnative={}",
164 build.test_helpers_out(target).display()));
165 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
Alex Crichtoncbe62922016-04-19 16:44:19166
Alex Crichton5f6261382016-11-14 16:04:39167 cmd.arg("--docck-python").arg(build.python());
Alex Crichtoncbe62922016-04-19 16:44:19168
169 if build.config.build.ends_with("apple-darwin") {
170 // Force /usr/bin/python on OSX for LLDB tests because we're loading the
171 // LLDB plugin's compiled module which only works with the system python
172 // (namely not Homebrew-installed python)
173 cmd.arg("--lldb-python").arg("/usr/bin/python");
174 } else {
Alex Crichton5f6261382016-11-14 16:04:39175 cmd.arg("--lldb-python").arg(build.python());
Alex Crichtoncbe62922016-04-19 16:44:19176 }
Alex Crichtonb325baf2016-04-05 18:34:23177
Tim Neumanndce46002016-10-29 18:11:53178 if let Some(ref gdb) = build.config.gdb {
179 cmd.arg("--gdb").arg(gdb);
Alex Crichtonb325baf2016-04-05 18:34:23180 }
181 if let Some(ref vers) = build.lldb_version {
182 cmd.arg("--lldb-version").arg(vers);
183 }
184 if let Some(ref dir) = build.lldb_python_dir {
185 cmd.arg("--lldb-python-dir").arg(dir);
186 }
Alex Crichton96283fc2016-09-01 17:52:44187 let llvm_config = build.llvm_config(target);
188 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
189 cmd.arg("--llvm-version").arg(llvm_version);
Alex Crichtonb325baf2016-04-05 18:34:23190
Alex Crichtona270b802016-10-21 20:18:09191 cmd.args(&build.flags.cmd.test_args());
Alex Crichtonb325baf2016-04-05 18:34:23192
193 if build.config.verbose || build.flags.verbose {
194 cmd.arg("--verbose");
195 }
196
Corey Farwellc8c6d2c2016-10-30 01:58:52197 if build.config.quiet_tests {
198 cmd.arg("--quiet");
199 }
200
Alex Crichtonf72bfe62016-05-02 22:16:15201 // Only pass correct values for these flags for the `run-make` suite as it
202 // requires that a C++ compiler was configured which isn't always the case.
Alex Crichton126e09e2016-04-14 22:51:03203 if suite == "run-make" {
Alex Crichton126e09e2016-04-14 22:51:03204 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
205 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
206 cmd.arg("--cc").arg(build.cc(target))
207 .arg("--cxx").arg(build.cxx(target))
208 .arg("--cflags").arg(build.cflags(target).join(" "))
209 .arg("--llvm-components").arg(llvm_components.trim())
210 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
211 } else {
212 cmd.arg("--cc").arg("")
213 .arg("--cxx").arg("")
214 .arg("--cflags").arg("")
215 .arg("--llvm-components").arg("")
216 .arg("--llvm-cxxflags").arg("");
217 }
218
219 // Running a C compiler on MSVC requires a few env vars to be set, to be
220 // sure to set them here.
Alex Crichton0e272de2016-11-16 20:31:19221 //
222 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
223 // rather than stomp over it.
Alex Crichton126e09e2016-04-14 22:51:03224 if target.contains("msvc") {
225 for &(ref k, ref v) in build.cc[target].0.env() {
226 if k != "PATH" {
227 cmd.env(k, v);
228 }
229 }
230 }
Alex Crichton21866602016-11-16 17:19:02231 cmd.env("RUSTC_BOOTSTRAP", "1");
Alex Crichton0e272de2016-11-16 20:31:19232 build.add_rust_test_threads(&mut cmd);
Alex Crichton126e09e2016-04-14 22:51:03233
Alex Crichton39a5d3f2016-06-28 20:31:30234 cmd.arg("--adb-path").arg("adb");
235 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
236 if target.contains("android") {
237 // Assume that cc for this target comes from the android sysroot
238 cmd.arg("--android-cross-path")
239 .arg(build.cc(target).parent().unwrap().parent().unwrap());
240 } else {
241 cmd.arg("--android-cross-path").arg("");
242 }
243
Alex Crichton0e272de2016-11-16 20:31:19244 let _time = util::timeit();
Alex Crichtonb325baf2016-04-05 18:34:23245 build.run(&mut cmd);
246}
Alex Crichtonede89442016-04-15 01:00:35247
Alex Crichtonf72bfe62016-05-02 22:16:15248/// Run `rustdoc --test` for all documentation in `src/doc`.
249///
250/// This will run all tests in our markdown documentation (e.g. the book)
251/// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
252/// `compiler`.
Alex Crichtonede89442016-04-15 01:00:35253pub fn docs(build: &Build, compiler: &Compiler) {
Alex Crichtonf72bfe62016-05-02 22:16:15254 // Do a breadth-first traversal of the `src/doc` directory and just run
255 // tests for all files that end in `*.md`
Alex Crichtonede89442016-04-15 01:00:35256 let mut stack = vec![build.src.join("src/doc")];
Alex Crichton0e272de2016-11-16 20:31:19257 let _time = util::timeit();
Alex Crichtonede89442016-04-15 01:00:35258
259 while let Some(p) = stack.pop() {
260 if p.is_dir() {
261 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
262 continue
263 }
264
265 if p.extension().and_then(|s| s.to_str()) != Some("md") {
266 continue
267 }
268
269 println!("doc tests for: {}", p.display());
270 markdown_test(build, compiler, &p);
271 }
272}
273
Alex Crichtonf72bfe62016-05-02 22:16:15274/// Run the error index generator tool to execute the tests located in the error
275/// index.
276///
277/// The `error_index_generator` tool lives in `src/tools` and is used to
278/// generate a markdown file from the error indexes of the code base which is
279/// then passed to `rustdoc --test`.
Alex Crichtonede89442016-04-15 01:00:35280pub fn error_index(build: &Build, compiler: &Compiler) {
281 println!("Testing error-index stage{}", compiler.stage);
282
Alex Crichton860c6ab2016-11-08 17:59:46283 let dir = testdir(build, compiler.host);
284 t!(fs::create_dir_all(&dir));
285 let output = dir.join("error-index.md");
Alex Crichton0e272de2016-11-16 20:31:19286
287 let _time = util::timeit();
Alex Crichtonede89442016-04-15 01:00:35288 build.run(build.tool_cmd(compiler, "error_index_generator")
289 .arg("markdown")
290 .arg(&output)
291 .env("CFG_BUILD", &build.config.build));
292
293 markdown_test(build, compiler, &output);
294}
295
296fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
297 let mut cmd = Command::new(build.rustdoc(compiler));
298 build.add_rustc_lib_path(compiler, &mut cmd);
Alex Crichton0e272de2016-11-16 20:31:19299 build.add_rust_test_threads(&mut cmd);
Alex Crichtonede89442016-04-15 01:00:35300 cmd.arg("--test");
301 cmd.arg(markdown);
Alex Crichton6f62fae2016-12-12 17:03:35302 cmd.env("RUSTC_BOOTSTRAP", "1");
Corey Farwellc8c6d2c2016-10-30 01:58:52303
Alex Crichtona270b802016-10-21 20:18:09304 let mut test_args = build.flags.cmd.test_args().join(" ");
Corey Farwellc8c6d2c2016-10-30 01:58:52305 if build.config.quiet_tests {
306 test_args.push_str(" --quiet");
307 }
308 cmd.arg("--test-args").arg(test_args);
309
Alex Crichtonede89442016-04-15 01:00:35310 build.run(&mut cmd);
311}
Alex Crichtonbb9062a2016-04-29 21:23:15312
313/// Run all unit tests plus documentation tests for an entire crate DAG defined
314/// by a `Cargo.toml`
315///
316/// This is what runs tests for crates like the standard library, compiler, etc.
317/// It essentially is the driver for running `cargo test`.
318///
319/// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
Alex Crichton147e2da2016-10-07 06:30:38320/// arguments, and those arguments are discovered from `cargo metadata`.
Alex Crichtonbb9062a2016-04-29 21:23:15321pub fn krate(build: &Build,
322 compiler: &Compiler,
323 target: &str,
Alex Crichtona270b802016-10-21 20:18:09324 mode: Mode,
Ulrik Sverdrupb1566ba2016-11-25 21:13:59325 test_kind: TestKind,
Alex Crichtona270b802016-10-21 20:18:09326 krate: Option<&str>) {
Alex Crichton147e2da2016-10-07 06:30:38327 let (name, path, features, root) = match mode {
Ahmed Charles9ca382f2016-09-02 08:55:29328 Mode::Libstd => {
Alex Crichton147e2da2016-10-07 06:30:38329 ("libstd", "src/rustc/std_shim", build.std_features(), "std_shim")
Ahmed Charles9ca382f2016-09-02 08:55:29330 }
331 Mode::Libtest => {
Alex Crichton147e2da2016-10-07 06:30:38332 ("libtest", "src/rustc/test_shim", String::new(), "test_shim")
Ahmed Charles9ca382f2016-09-02 08:55:29333 }
334 Mode::Librustc => {
Alex Crichton147e2da2016-10-07 06:30:38335 ("librustc", "src/rustc", build.rustc_features(), "rustc-main")
Ahmed Charles9ca382f2016-09-02 08:55:29336 }
Alex Crichtonbb9062a2016-04-29 21:23:15337 _ => panic!("can only test libraries"),
338 };
Ulrik Sverdrupb1566ba2016-11-25 21:13:59339 println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
Alex Crichtonbb9062a2016-04-29 21:23:15340 compiler.host, target);
341
342 // Build up the base `cargo test` command.
Alex Crichton147e2da2016-10-07 06:30:38343 //
344 // Pass in some standard flags then iterate over the graph we've discovered
345 // in `cargo metadata` with the maps above and figure out what `-p`
346 // arguments need to get passed.
Ulrik Sverdrupb1566ba2016-11-25 21:13:59347 let mut cargo = build.cargo(compiler, mode, target, test_kind.subcommand());
Alex Crichtonbb9062a2016-04-29 21:23:15348 cargo.arg("--manifest-path")
349 .arg(build.src.join(path).join("Cargo.toml"))
350 .arg("--features").arg(features);
351
Alex Crichtona270b802016-10-21 20:18:09352 match krate {
353 Some(krate) => {
354 cargo.arg("-p").arg(krate);
Alex Crichtonbb9062a2016-04-29 21:23:15355 }
Alex Crichtona270b802016-10-21 20:18:09356 None => {
357 let mut visited = HashSet::new();
358 let mut next = vec![root];
359 while let Some(name) = next.pop() {
360 // Right now jemalloc is our only target-specific crate in the sense
361 // that it's not present on all platforms. Custom skip it here for now,
362 // but if we add more this probably wants to get more generalized.
363 if !name.contains("jemalloc") {
364 cargo.arg("-p").arg(name);
365 }
366 for dep in build.crates[name].deps.iter() {
367 if visited.insert(dep) {
368 next.push(dep);
369 }
370 }
Alex Crichtonbb9062a2016-04-29 21:23:15371 }
372 }
Alex Crichtonbb9062a2016-04-29 21:23:15373 }
374
375 // The tests are going to run with the *target* libraries, so we need to
376 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
377 //
378 // Note that to run the compiler we need to run with the *host* libraries,
379 // but our wrapper scripts arrange for that to be the case anyway.
380 let mut dylib_path = dylib_path();
381 dylib_path.insert(0, build.sysroot_libdir(compiler, target));
382 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
Alex Crichtonbb9062a2016-04-29 21:23:15383
Alex Crichton0e272de2016-11-16 20:31:19384 if target.contains("android") {
385 cargo.arg("--no-run");
386 } else if target.contains("emscripten") {
387 cargo.arg("--no-run");
388 }
389
390 cargo.arg("--");
391
Corey Farwellc8c6d2c2016-10-30 01:58:52392 if build.config.quiet_tests {
Corey Farwellc8c6d2c2016-10-30 01:58:52393 cargo.arg("--quiet");
394 }
395
Alex Crichton0e272de2016-11-16 20:31:19396 let _time = util::timeit();
397
Alex Crichton39a5d3f2016-06-28 20:31:30398 if target.contains("android") {
Alex Crichton0e272de2016-11-16 20:31:19399 build.run(&mut cargo);
Alex Crichton39a5d3f2016-06-28 20:31:30400 krate_android(build, compiler, target, mode);
Brian Andersonb8b50f02016-09-06 00:41:50401 } else if target.contains("emscripten") {
Alex Crichton0e272de2016-11-16 20:31:19402 build.run(&mut cargo);
Brian Andersonb8b50f02016-09-06 00:41:50403 krate_emscripten(build, compiler, target, mode);
Alex Crichton39a5d3f2016-06-28 20:31:30404 } else {
Alex Crichtona270b802016-10-21 20:18:09405 cargo.args(&build.flags.cmd.test_args());
Alex Crichton39a5d3f2016-06-28 20:31:30406 build.run(&mut cargo);
407 }
408}
409
410fn krate_android(build: &Build,
411 compiler: &Compiler,
412 target: &str,
413 mode: Mode) {
414 let mut tests = Vec::new();
415 let out_dir = build.cargo_out(compiler, mode, target);
416 find_tests(&out_dir, target, &mut tests);
417 find_tests(&out_dir.join("deps"), target, &mut tests);
418
419 for test in tests {
420 build.run(Command::new("adb").arg("push").arg(&test).arg(ADB_TEST_DIR));
421
422 let test_file_name = test.file_name().unwrap().to_string_lossy();
423 let log = format!("{}/check-stage{}-T-{}-H-{}-{}.log",
424 ADB_TEST_DIR,
425 compiler.stage,
426 target,
427 compiler.host,
428 test_file_name);
Alex Crichton0e272de2016-11-16 20:31:19429 let quiet = if build.config.quiet_tests { "--quiet" } else { "" };
Alex Crichton39a5d3f2016-06-28 20:31:30430 let program = format!("(cd {dir}; \
431 LD_LIBRARY_PATH=./{target} ./{test} \
432 --logfile {log} \
Alex Crichton0e272de2016-11-16 20:31:19433 {quiet} \
Alex Crichton39a5d3f2016-06-28 20:31:30434 {args})",
435 dir = ADB_TEST_DIR,
436 target = target,
437 test = test_file_name,
438 log = log,
Alex Crichton0e272de2016-11-16 20:31:19439 quiet = quiet,
Alex Crichtona270b802016-10-21 20:18:09440 args = build.flags.cmd.test_args().join(" "));
Alex Crichton39a5d3f2016-06-28 20:31:30441
442 let output = output(Command::new("adb").arg("shell").arg(&program));
443 println!("{}", output);
444 build.run(Command::new("adb")
445 .arg("pull")
446 .arg(&log)
447 .arg(build.out.join("tmp")));
448 build.run(Command::new("adb").arg("shell").arg("rm").arg(&log));
449 if !output.contains("result: ok") {
450 panic!("some tests failed");
451 }
452 }
453}
454
Brian Andersonb8b50f02016-09-06 00:41:50455fn krate_emscripten(build: &Build,
456 compiler: &Compiler,
457 target: &str,
458 mode: Mode) {
Ross Schulmanad9184c2016-09-05 23:56:48459 let mut tests = Vec::new();
460 let out_dir = build.cargo_out(compiler, mode, target);
461 find_tests(&out_dir, target, &mut tests);
462 find_tests(&out_dir.join("deps"), target, &mut tests);
463
464 for test in tests {
465 let test_file_name = test.to_string_lossy().into_owned();
Brian Andersonfcd32792016-09-06 20:36:14466 println!("running {}", test_file_name);
Brian Anderson8401e372016-09-15 19:42:26467 let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
Alex Crichton0e272de2016-11-16 20:31:19468 let mut cmd = Command::new(nodejs);
Alex Crichton03fb5ad2016-12-08 01:26:48469 cmd.arg(&test_file_name);
Alex Crichton0e272de2016-11-16 20:31:19470 if build.config.quiet_tests {
471 cmd.arg("--quiet");
472 }
473 build.run(&mut cmd);
Ross Schulmanad9184c2016-09-05 23:56:48474 }
475 }
476
477
Alex Crichton39a5d3f2016-06-28 20:31:30478fn find_tests(dir: &Path,
479 target: &str,
480 dst: &mut Vec<PathBuf>) {
481 for e in t!(dir.read_dir()).map(|e| t!(e)) {
482 let file_type = t!(e.file_type());
483 if !file_type.is_file() {
484 continue
485 }
486 let filename = e.file_name().into_string().unwrap();
487 if (target.contains("windows") && filename.ends_with(".exe")) ||
Ross Schulmanad9184c2016-09-05 23:56:48488 (!target.contains("windows") && !filename.contains(".")) ||
Brian Andersonfcd32792016-09-06 20:36:14489 (target.contains("emscripten") && filename.contains(".js")){
Alex Crichton39a5d3f2016-06-28 20:31:30490 dst.push(e.path());
491 }
492 }
493}
494
495pub fn android_copy_libs(build: &Build,
496 compiler: &Compiler,
497 target: &str) {
498 println!("Android copy libs to emulator ({})", target);
499 build.run(Command::new("adb").arg("remount"));
500 build.run(Command::new("adb").args(&["shell", "rm", "-r", ADB_TEST_DIR]));
501 build.run(Command::new("adb").args(&["shell", "mkdir", ADB_TEST_DIR]));
502 build.run(Command::new("adb")
503 .arg("push")
504 .arg(build.src.join("src/etc/adb_run_wrapper.sh"))
505 .arg(ADB_TEST_DIR));
506
507 let target_dir = format!("{}/{}", ADB_TEST_DIR, target);
508 build.run(Command::new("adb").args(&["shell", "mkdir", &target_dir[..]]));
509
510 for f in t!(build.sysroot_libdir(compiler, target).read_dir()) {
511 let f = t!(f);
512 let name = f.file_name().into_string().unwrap();
513 if util::is_dylib(&name) {
514 build.run(Command::new("adb")
515 .arg("push")
516 .arg(f.path())
517 .arg(&target_dir));
518 }
519 }
Alex Crichtonbb9062a2016-04-29 21:23:15520}
Alex Crichtond38db822016-12-09 01:13:55521
522/// Run "distcheck", a 'make check' from a tarball
523pub fn distcheck(build: &Build) {
524 if build.config.build != "x86_64-unknown-linux-gnu" {
525 return
526 }
527 if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
528 return
529 }
530 if !build.config.target.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
531 return
532 }
533
534 let dir = build.out.join("tmp").join("distcheck");
535 let _ = fs::remove_dir_all(&dir);
536 t!(fs::create_dir_all(&dir));
537
538 let mut cmd = Command::new("tar");
539 cmd.arg("-xzf")
540 .arg(dist::rust_src_location(build))
541 .arg("--strip-components=1")
542 .current_dir(&dir);
543 build.run(&mut cmd);
544 build.run(Command::new("./configure")
545 .current_dir(&dir));
546 build.run(Command::new("make")
547 .arg("check")
548 .current_dir(&dir));
549}