From 023dcd3ec8d3510245ce345ffb17509514fe9615 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Apr 2016 11:34:23 -0700 Subject: [PATCH 1/3] rustbuild: Add support for compiletest test suites This commit adds support in rustbuild for running all of the compiletest test suites as part of `make check`. The `compiletest` program was moved to `src/tools` (like `rustbook` and others) and is now just compiled like any other old tool. Each test suite has a pretty standard set of dependencies and just tweaks various parameters to the final compiletest executable. Note that full support is lacking in terms of: * Once a test suite has passed, that's not remembered. When a test suite is requested to be run, it's always run. * The arguments to compiletest probably don't work for every possible combination of platforms and testing environments just yet. There will likely need to be future updates to tweak various pieces here and there. * Cross compiled test suites probably don't work just yet, support for that will come in a follow-up patch. --- mk/crates.mk | 2 +- mk/dist.mk | 1 - src/bootstrap/bootstrap.py | 2 +- src/bootstrap/build/check.rs | 48 +++++++++++ src/bootstrap/build/compile.rs | 9 +- src/bootstrap/build/flags.rs | 5 -- src/bootstrap/build/mod.rs | 86 ++++++++++++++++++- src/bootstrap/build/native.rs | 27 +++++- src/bootstrap/build/sanity.rs | 6 ++ src/bootstrap/build/step.rs | 57 +++++++++++- src/tools/compiletest/Cargo.lock | 70 +++++++++++++++ src/tools/compiletest/Cargo.toml | 9 ++ src/tools/compiletest/build.rs | 3 + .../compiletest/src}/common.rs | 0 .../compiletest/src}/errors.rs | 0 .../compiletest/src}/header.rs | 0 .../compiletest/src/main.rs} | 15 +++- .../compiletest/src}/procsrv.rs | 0 .../compiletest/src}/raise_fd_limit.rs | 0 .../compiletest/src}/runtest.rs | 0 .../compiletest/src}/util.rs | 0 21 files changed, 313 insertions(+), 27 deletions(-) create mode 100644 src/tools/compiletest/Cargo.lock create mode 100644 src/tools/compiletest/Cargo.toml create mode 100644 src/tools/compiletest/build.rs rename src/{compiletest => tools/compiletest/src}/common.rs (100%) rename src/{compiletest => tools/compiletest/src}/errors.rs (100%) rename src/{compiletest => tools/compiletest/src}/header.rs (100%) rename src/{compiletest/compiletest.rs => tools/compiletest/src/main.rs} (98%) rename src/{compiletest => tools/compiletest/src}/procsrv.rs (100%) rename src/{compiletest => tools/compiletest/src}/raise_fd_limit.rs (100%) rename src/{compiletest => tools/compiletest/src}/runtest.rs (100%) rename src/{compiletest => tools/compiletest/src}/util.rs (100%) diff --git a/mk/crates.mk b/mk/crates.mk index dafda75f5fe7d..4003e092034e5 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -133,7 +133,7 @@ TOOL_DEPS_rustdoc := rustdoc TOOL_DEPS_rustc := rustc_driver TOOL_DEPS_rustbook := std rustdoc TOOL_DEPS_error_index_generator := rustdoc syntax serialize -TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs +TOOL_SOURCE_compiletest := $(S)src/tools/compiletest/src/main.rs TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs TOOL_SOURCE_rustc := $(S)src/driver/driver.rs TOOL_SOURCE_rustbook := $(S)src/tools/rustbook/main.rs diff --git a/mk/dist.mk b/mk/dist.mk index 1273900608385..48e01a2533467 100644 --- a/mk/dist.mk +++ b/mk/dist.mk @@ -50,7 +50,6 @@ PKG_FILES := \ $(addprefix $(S)src/, \ bootstrap \ build_helper \ - compiletest \ doc \ driver \ etc \ diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 5de7e6957c6f1..cdde9ca2c9ada 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -308,11 +308,11 @@ def build_triple(self): # Run the bootstrap args = [os.path.join(rb.build_dir, "bootstrap/debug/bootstrap")] -args.extend(sys.argv[1:]) args.append('--src') args.append(rb.rust_root) args.append('--build') args.append(rb.build) +args.extend(sys.argv[1:]) env = os.environ.copy() env["BOOTSTRAP_PARENT_ID"] = str(os.getpid()) rb.run(args, env) diff --git a/src/bootstrap/build/check.rs b/src/bootstrap/build/check.rs index a2445ae498a77..6114b44a46c0f 100644 --- a/src/bootstrap/build/check.rs +++ b/src/bootstrap/build/check.rs @@ -8,6 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::path::PathBuf; +use std::process::Command; + use build::{Build, Compiler}; pub fn linkcheck(build: &Build, stage: u32, host: &str) { @@ -33,3 +36,48 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) { .env("PATH", newpath) .arg(&build.cargo)); } + +fn testdir(build: &Build, host: &str) -> PathBuf { + build.out.join(host).join("test") +} + +pub fn compiletest(build: &Build, + compiler: &Compiler, + target: &str, + mode: &str, + suite: &str) { + let compiletest = build.tool(compiler, "compiletest"); + let mut cmd = Command::new(&compiletest); + + cmd.arg("--compile-lib-path").arg(build.rustc_libdir(compiler)); + cmd.arg("--run-lib-path").arg(build.sysroot_libdir(compiler, target)); + cmd.arg("--rustc-path").arg(build.compiler_path(compiler)); + cmd.arg("--rustdoc-path").arg(build.rustdoc(compiler)); + cmd.arg("--src-base").arg(build.src.join("src/test").join(suite)); + cmd.arg("--aux-base").arg(build.src.join("src/test/auxiliary")); + cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite)); + cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target)); + cmd.arg("--mode").arg(mode); + cmd.arg("--target").arg(target); + cmd.arg("--host").arg(compiler.host); + + let filecheck = build.llvm_filecheck(&build.config.build); + cmd.arg("--llvm-bin-path").arg(filecheck.parent().unwrap()); + + let linkflag = format!("-Lnative={}", build.test_helpers_out(target).display()); + cmd.arg("--host-rustcflags").arg("-Crpath"); + cmd.arg("--target-rustcflags").arg(format!("-Crpath {}", linkflag)); + + // FIXME: needs android support + cmd.arg("--android-cross-path").arg(""); + // FIXME: CFG_PYTHON should probably be detected more robustly elsewhere + cmd.arg("--python").arg("python"); + + cmd.args(&build.flags.args); + + if build.config.verbose || build.flags.verbose { + cmd.arg("--verbose"); + } + + build.run(&mut cmd); +} diff --git a/src/bootstrap/build/compile.rs b/src/bootstrap/build/compile.rs index a67f1ba48b560..7a582d853d8c5 100644 --- a/src/bootstrap/build/compile.rs +++ b/src/bootstrap/build/compile.rs @@ -191,14 +191,7 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { if !build.unstable_features { cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1"); } - let target_config = build.config.target_config.get(target); - if let Some(ref s) = target_config.and_then(|c| c.llvm_config.as_ref()) { - cargo.env("LLVM_CONFIG", s); - } else { - let llvm_config = build.llvm_out(&build.config.build).join("bin") - .join(exe("llvm-config", target)); - cargo.env("LLVM_CONFIG", llvm_config); - } + cargo.env("LLVM_CONFIG", build.llvm_config(target)); if build.config.llvm_static_stdcpp { cargo.env("LLVM_STATIC_STDCPP", compiler_file(build.cxx(target), "libstdc++.a")); diff --git a/src/bootstrap/build/flags.rs b/src/bootstrap/build/flags.rs index d91dfe0903d11..67f33e29cae84 100644 --- a/src/bootstrap/build/flags.rs +++ b/src/bootstrap/build/flags.rs @@ -62,11 +62,6 @@ impl Flags { usage(0); } - if m.free.len() > 0 { - println!("free arguments are not currently accepted"); - usage(1); - } - let cfg_file = m.opt_str("config").map(PathBuf::from).or_else(|| { if fs::metadata("config.toml").is_ok() { Some(PathBuf::from("config.toml")) diff --git a/src/bootstrap/build/mod.rs b/src/bootstrap/build/mod.rs index 248bf6cb4ea15..7826139c598cd 100644 --- a/src/bootstrap/build/mod.rs +++ b/src/bootstrap/build/mod.rs @@ -160,6 +160,9 @@ impl Build { CompilerRt { _dummy } => { native::compiler_rt(self, target.target); } + TestHelpers { _dummy } => { + native::test_helpers(self, target.target); + } Libstd { compiler } => { compile::std(self, target.target, &compiler); } @@ -197,6 +200,9 @@ impl Build { ToolCargoTest { stage } => { compile::tool(self, stage, target.target, "cargotest"); } + ToolCompiletest { stage } => { + compile::tool(self, stage, target.target, "compiletest"); + } DocBook { stage } => { doc::rustbook(self, stage, target.target, "book", &doc_out); } @@ -230,6 +236,55 @@ impl Build { CheckCargoTest { stage } => { check::cargotest(self, stage, target.target); } + CheckRPass { compiler } => { + check::compiletest(self, &compiler, target.target, + "run-pass", "run-pass"); + } + CheckCFail { compiler } => { + check::compiletest(self, &compiler, target.target, + "compile-fail", "compile-fail"); + } + CheckPFail { compiler } => { + check::compiletest(self, &compiler, target.target, + "parse-fail", "parse-fail"); + } + CheckRFail { compiler } => { + check::compiletest(self, &compiler, target.target, + "run-fail", "run-fail"); + } + CheckPretty { compiler } => { + check::compiletest(self, &compiler, target.target, + "pretty", "pretty"); + } + CheckCodegen { compiler } => { + check::compiletest(self, &compiler, target.target, + "codegen", "codegen"); + } + CheckCodegenUnits { compiler } => { + check::compiletest(self, &compiler, target.target, + "codegen-units", "codegen-units"); + } + CheckDebuginfo { compiler } => { + // TODO: select between gdb/lldb + check::compiletest(self, &compiler, target.target, + "debuginfo-gdb", "debuginfo"); + } + CheckRustdoc { compiler } => { + check::compiletest(self, &compiler, target.target, + "rustdoc", "rustdoc"); + } + CheckRPassValgrind { compiler } => { + check::compiletest(self, &compiler, target.target, + "run-pass-valgrind", "run-pass-valgrind"); + } + CheckRPassFull { compiler } => { + check::compiletest(self, &compiler, target.target, + "run-pass", "run-pass-fulldeps"); + } + CheckCFailFull { compiler } => { + check::compiletest(self, &compiler, target.target, + "compile-fail", "compile-fail-fulldeps") + } DistDocs { stage } => dist::docs(self, stage, target.target), DistMingw { _dummy } => dist::mingw(self, target.target), @@ -436,7 +491,8 @@ impl Build { let suffix = match mode { Mode::Libstd => "-std", Mode::Libtest => "-test", - Mode::Tool | Mode::Librustc => "-rustc", + Mode::Tool => "-tools", + Mode::Librustc => "-rustc", }; self.out.join(compiler.host) .join(format!("stage{}{}", compiler.stage, suffix)) @@ -457,11 +513,39 @@ impl Build { self.out.join(target).join("llvm") } + /// Returns the path to `llvm-config` for the specified target + fn llvm_config(&self, target: &str) -> PathBuf { + let target_config = self.config.target_config.get(target); + if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { + s.clone() + } else { + self.llvm_out(&self.config.build).join("bin") + .join(exe("llvm-config", target)) + } + } + + /// Returns the path to `llvm-config` for the specified target + fn llvm_filecheck(&self, target: &str) -> PathBuf { + let target_config = self.config.target_config.get(target); + if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { + s.parent().unwrap().join(exe("FileCheck", target)) + } else { + self.llvm_out(&self.config.build).join("build/bin") + .join(exe("FileCheck", target)) + } + } + /// Root output directory for compiler-rt compiled for `target` fn compiler_rt_out(&self, target: &str) -> PathBuf { self.out.join(target).join("compiler-rt") } + /// Root output directory for rust_test_helpers library compiled for + /// `target` + fn test_helpers_out(&self, target: &str) -> PathBuf { + self.out.join(target).join("rust-test-helpers") + } + fn add_rustc_lib_path(&self, compiler: &Compiler, cmd: &mut Command) { // Windows doesn't need dylib path munging because the dlls for the // compiler live next to the compiler and the system will find them diff --git a/src/bootstrap/build/native.rs b/src/bootstrap/build/native.rs index bf0494bcd8c8c..6a8cdb60cec6d 100644 --- a/src/bootstrap/build/native.rs +++ b/src/bootstrap/build/native.rs @@ -14,9 +14,10 @@ use std::fs; use build_helper::output; use cmake; +use gcc; use build::Build; -use build::util::{exe, staticlib}; +use build::util::{exe, staticlib, up_to_date}; pub fn llvm(build: &Build, target: &str) { // If we're using a custom LLVM bail out here, but we can only use a @@ -149,9 +150,7 @@ pub fn compiler_rt(build: &Build, target: &str) { } let _ = fs::remove_dir_all(&dst); t!(fs::create_dir_all(&dst)); - let build_llvm_config = build.llvm_out(&build.config.build) - .join("bin") - .join(exe("llvm-config", &build.config.build)); + let build_llvm_config = build.llvm_config(&build.config.build); let mut cfg = cmake::Config::new(build.src.join("src/compiler-rt")); cfg.target(target) .host(&build.config.build) @@ -168,3 +167,23 @@ pub fn compiler_rt(build: &Build, target: &str) { .build_target(&build_target); cfg.build(); } + +pub fn test_helpers(build: &Build, target: &str) { + let dst = build.test_helpers_out(target); + let src = build.src.join("src/rt/rust_test_helpers.c"); + if up_to_date(&src, &dst.join("librust_test_helpers.a")) { + return + } + + println!("Building test helpers"); + t!(fs::create_dir_all(&dst)); + let mut cfg = gcc::Config::new(); + cfg.cargo_metadata(false) + .out_dir(&dst) + .target(target) + .host(&build.config.build) + .opt_level(0) + .debug(false) + .file(build.src.join("src/rt/rust_test_helpers.c")) + .compile("librust_test_helpers.a"); +} diff --git a/src/bootstrap/build/sanity.rs b/src/bootstrap/build/sanity.rs index 6ce2749638841..75ecfd82febe0 100644 --- a/src/bootstrap/build/sanity.rs +++ b/src/bootstrap/build/sanity.rs @@ -63,6 +63,12 @@ pub fn check(build: &mut Build) { need_cmd(build.cxx(host).as_ref()); } + // Externally configured LLVM requires FileCheck to exist + let filecheck = build.llvm_filecheck(&build.config.build); + if !filecheck.starts_with(&build.out) && !filecheck.exists() { + panic!("filecheck executable {:?} does not exist", filecheck); + } + for target in build.config.target.iter() { // Either can't build or don't want to run jemalloc on these targets if target.contains("rumprun") || diff --git a/src/bootstrap/build/step.rs b/src/bootstrap/build/step.rs index 80fcc32e5371d..cf95a107c829e 100644 --- a/src/bootstrap/build/step.rs +++ b/src/bootstrap/build/step.rs @@ -51,6 +51,7 @@ macro_rules! targets { (tool_rustbook, ToolRustbook { stage: u32 }), (tool_error_index, ToolErrorIndex { stage: u32 }), (tool_cargotest, ToolCargoTest { stage: u32 }), + (tool_compiletest, ToolCompiletest { stage: u32 }), // Steps for long-running native builds. Ideally these wouldn't // actually exist and would be part of build scripts, but for now @@ -60,6 +61,7 @@ macro_rules! targets { // with braces are unstable so we just pick something that works. (llvm, Llvm { _dummy: () }), (compiler_rt, CompilerRt { _dummy: () }), + (test_helpers, TestHelpers { _dummy: () }), // Steps for various pieces of documentation that we can generate, // the 'doc' step is just a pseudo target to depend on a bunch of @@ -79,6 +81,18 @@ macro_rules! targets { (check, Check { stage: u32, compiler: Compiler<'a> }), (check_linkcheck, CheckLinkcheck { stage: u32 }), (check_cargotest, CheckCargoTest { stage: u32 }), + (check_rpass, CheckRPass { compiler: Compiler<'a> }), + (check_rfail, CheckRFail { compiler: Compiler<'a> }), + (check_cfail, CheckCFail { compiler: Compiler<'a> }), + (check_pfail, CheckPFail { compiler: Compiler<'a> }), + (check_codegen, CheckCodegen { compiler: Compiler<'a> }), + (check_codegen_units, CheckCodegenUnits { compiler: Compiler<'a> }), + (check_debuginfo, CheckDebuginfo { compiler: Compiler<'a> }), + (check_rustdoc, CheckRustdoc { compiler: Compiler<'a> }), + (check_pretty, CheckPretty { compiler: Compiler<'a> }), + (check_rpass_valgrind, CheckRPassValgrind { compiler: Compiler<'a> }), + (check_rpass_full, CheckRPassFull { compiler: Compiler<'a> }), + (check_cfail_full, CheckCFailFull { compiler: Compiler<'a> }), // Distribution targets, creating tarballs (dist, Dist { stage: u32 }), @@ -274,6 +288,7 @@ impl<'a> Step<'a> { vec![self.llvm(()).target(&build.config.build)] } Source::Llvm { _dummy } => Vec::new(), + Source::TestHelpers { _dummy } => Vec::new(), // Note that all doc targets depend on artifacts from the build // architecture, not the target (which is where we're generating @@ -306,9 +321,23 @@ impl<'a> Step<'a> { self.doc_std(stage), self.doc_error_index(stage)] } - Source::Check { stage, compiler: _ } => { - vec![self.check_linkcheck(stage), - self.dist(stage)] + Source::Check { stage, compiler } => { + vec![ + self.check_rpass(compiler), + self.check_cfail(compiler), + self.check_rfail(compiler), + self.check_pfail(compiler), + self.check_codegen(compiler), + self.check_codegen_units(compiler), + self.check_debuginfo(compiler), + self.check_rustdoc(compiler), + self.check_pretty(compiler), + self.check_rpass_valgrind(compiler), + self.check_rpass_full(compiler), + self.check_cfail_full(compiler), + self.check_linkcheck(stage), + self.dist(stage), + ] } Source::CheckLinkcheck { stage } => { vec![self.tool_linkchecker(stage), self.doc(stage)] @@ -316,6 +345,25 @@ impl<'a> Step<'a> { Source::CheckCargoTest { stage } => { vec![self.tool_cargotest(stage)] } + Source::CheckRFail { compiler } | + Source::CheckPFail { compiler } | + Source::CheckCodegen { compiler } | + Source::CheckCodegenUnits { compiler } | + Source::CheckDebuginfo { compiler } | + Source::CheckRustdoc { compiler } | + Source::CheckPretty { compiler } | + Source::CheckCFail { compiler } | + Source::CheckRPassValgrind { compiler } | + Source::CheckRPass { compiler } => { + vec![self.libtest(compiler), + self.tool_compiletest(compiler.stage), + self.test_helpers(())] + } + Source::CheckRPassFull { compiler } | + Source::CheckCFailFull { compiler } => { + vec![self.librustc(compiler), + self.tool_compiletest(compiler.stage)] + } Source::ToolLinkchecker { stage } => { vec![self.libstd(self.compiler(stage))] @@ -327,6 +375,9 @@ impl<'a> Step<'a> { Source::ToolCargoTest { stage } => { vec![self.librustc(self.compiler(stage))] } + Source::ToolCompiletest { stage } => { + vec![self.libtest(self.compiler(stage))] + } Source::DistDocs { stage } => vec![self.doc(stage)], Source::DistMingw { _dummy: _ } => Vec::new(), diff --git a/src/tools/compiletest/Cargo.lock b/src/tools/compiletest/Cargo.lock new file mode 100644 index 0000000000000..3b79636a2db5b --- /dev/null +++ b/src/tools/compiletest/Cargo.lock @@ -0,0 +1,70 @@ +[root] +name = "compiletest" +version = "0.0.0" +dependencies = [ + "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "aho-corasick" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "env_logger" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.62 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "log" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "memchr" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "mempool" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "regex" +version = "0.1.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "mempool 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "utf8-ranges" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml new file mode 100644 index 0000000000000..656b0829734e5 --- /dev/null +++ b/src/tools/compiletest/Cargo.toml @@ -0,0 +1,9 @@ +[package] +authors = ["The Rust Project Developers"] +name = "compiletest" +version = "0.0.0" +build = "build.rs" + +[dependencies] +log = "0.3" +env_logger = "0.3" diff --git a/src/tools/compiletest/build.rs b/src/tools/compiletest/build.rs new file mode 100644 index 0000000000000..11e94f7168b2a --- /dev/null +++ b/src/tools/compiletest/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rustc-cfg=cargobuild"); +} diff --git a/src/compiletest/common.rs b/src/tools/compiletest/src/common.rs similarity index 100% rename from src/compiletest/common.rs rename to src/tools/compiletest/src/common.rs diff --git a/src/compiletest/errors.rs b/src/tools/compiletest/src/errors.rs similarity index 100% rename from src/compiletest/errors.rs rename to src/tools/compiletest/src/errors.rs diff --git a/src/compiletest/header.rs b/src/tools/compiletest/src/header.rs similarity index 100% rename from src/compiletest/header.rs rename to src/tools/compiletest/src/header.rs diff --git a/src/compiletest/compiletest.rs b/src/tools/compiletest/src/main.rs similarity index 98% rename from src/compiletest/compiletest.rs rename to src/tools/compiletest/src/main.rs index 8d2558e4344e6..ace6c0677bdbd 100644 --- a/src/compiletest/compiletest.rs +++ b/src/tools/compiletest/src/main.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![crate_type = "bin"] +#![crate_name = "compiletest"] #![feature(box_syntax)] -#![feature(libc)] #![feature(rustc_private)] #![feature(test)] #![feature(question_mark)] +#![feature(libc)] #![deny(warnings)] @@ -25,6 +25,9 @@ extern crate getopts; #[macro_use] extern crate log; +#[cfg(cargobuild)] +extern crate env_logger; + use std::env; use std::fs; use std::io; @@ -43,7 +46,13 @@ pub mod common; pub mod errors; mod raise_fd_limit; -pub fn main() { +fn main() { + #[cfg(cargobuild)] + fn log_init() { env_logger::init().unwrap(); } + #[cfg(not(cargobuild))] + fn log_init() {} + log_init(); + let config = parse_config(env::args().collect()); if config.valgrind_path.is_none() && config.force_valgrind { diff --git a/src/compiletest/procsrv.rs b/src/tools/compiletest/src/procsrv.rs similarity index 100% rename from src/compiletest/procsrv.rs rename to src/tools/compiletest/src/procsrv.rs diff --git a/src/compiletest/raise_fd_limit.rs b/src/tools/compiletest/src/raise_fd_limit.rs similarity index 100% rename from src/compiletest/raise_fd_limit.rs rename to src/tools/compiletest/src/raise_fd_limit.rs diff --git a/src/compiletest/runtest.rs b/src/tools/compiletest/src/runtest.rs similarity index 100% rename from src/compiletest/runtest.rs rename to src/tools/compiletest/src/runtest.rs diff --git a/src/compiletest/util.rs b/src/tools/compiletest/src/util.rs similarity index 100% rename from src/compiletest/util.rs rename to src/tools/compiletest/src/util.rs From 6a44cf03f5e3a3e5f657c41a226e753e7a6886fa Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 7 Apr 2016 13:37:24 -0700 Subject: [PATCH 2/3] rustbuild: Fix optimizing native code The default flags printed out by gcc-rs indicate the optimization level, but we want to defer that until later when the build script is actually running so don't pass them down from the top level. --- src/bootstrap/build/check.rs | 7 +++++ src/bootstrap/build/dist.rs | 53 ++++++++++++++++++++--------------- src/bootstrap/build/mod.rs | 16 +++++++++++ src/bootstrap/build/sanity.rs | 10 +++++++ src/bootstrap/build/step.rs | 11 ++++++-- 5 files changed, 71 insertions(+), 26 deletions(-) diff --git a/src/bootstrap/build/check.rs b/src/bootstrap/build/check.rs index 6114b44a46c0f..5f7f494e6b391 100644 --- a/src/bootstrap/build/check.rs +++ b/src/bootstrap/build/check.rs @@ -73,6 +73,13 @@ pub fn compiletest(build: &Build, // FIXME: CFG_PYTHON should probably be detected more robustly elsewhere cmd.arg("--python").arg("python"); + if let Some(ref vers) = build.gdb_version { + cmd.arg("--gdb-version").arg(vers); + } + if let Some(ref vers) = build.lldb_version { + cmd.arg("--lldb-version").arg(vers); + } + cmd.args(&build.flags.args); if build.config.verbose || build.flags.verbose { diff --git a/src/bootstrap/build/dist.rs b/src/bootstrap/build/dist.rs index 6ae652bd66da6..f2e3117fa9766 100644 --- a/src/bootstrap/build/dist.rs +++ b/src/bootstrap/build/dist.rs @@ -195,29 +195,7 @@ pub fn rustc(build: &Build, stage: u32, host: &str) { cp_r(&build.src.join("man"), &image.join("share/man/man1")); // Debugger scripts - let cp_debugger_script = |file: &str| { - let dst = image.join("lib/rustlib/etc"); - t!(fs::create_dir_all(&dst)); - install(&build.src.join("src/etc/").join(file), &dst, 0o644); - }; - if host.contains("windows") { - // no debugger scripts - } else if host.contains("darwin") { - // lldb debugger scripts - install(&build.src.join("src/etc/rust-lldb"), &image.join("bin"), - 0o755); - - cp_debugger_script("lldb_rust_formatters.py"); - cp_debugger_script("debugger_pretty_printers_common.py"); - } else { - // gdb debugger scripts - install(&build.src.join("src/etc/rust-gdb"), &image.join("bin"), - 0o755); - - cp_debugger_script("gdb_load_rust_pretty_printers.py"); - cp_debugger_script("gdb_rust_pretty_printing.py"); - cp_debugger_script("debugger_pretty_printers_common.py"); - } + debugger_scripts(build, &image, host); // Misc license info let cp = |file: &str| { @@ -231,6 +209,35 @@ pub fn rustc(build: &Build, stage: u32, host: &str) { } } +pub fn debugger_scripts(build: &Build, + sysroot: &Path, + host: &str) { + let cp_debugger_script = |file: &str| { + let dst = sysroot.join("lib/rustlib/etc"); + t!(fs::create_dir_all(&dst)); + install(&build.src.join("src/etc/").join(file), &dst, 0o644); + }; + if host.contains("windows") { + // no debugger scripts + } else if host.contains("darwin") { + // lldb debugger scripts + install(&build.src.join("src/etc/rust-lldb"), &sysroot.join("bin"), + 0o755); + + cp_debugger_script("lldb_rust_formatters.py"); + cp_debugger_script("debugger_pretty_printers_common.py"); + } else { + // gdb debugger scripts + install(&build.src.join("src/etc/rust-gdb"), &sysroot.join("bin"), + 0o755); + + cp_debugger_script("gdb_load_rust_pretty_printers.py"); + cp_debugger_script("gdb_rust_pretty_printing.py"); + cp_debugger_script("debugger_pretty_printers_common.py"); + } +} + + pub fn std(build: &Build, compiler: &Compiler, target: &str) { println!("Dist std stage{} ({} -> {})", compiler.stage, compiler.host, target); diff --git a/src/bootstrap/build/mod.rs b/src/bootstrap/build/mod.rs index 7826139c598cd..fc7a883119a07 100644 --- a/src/bootstrap/build/mod.rs +++ b/src/bootstrap/build/mod.rs @@ -80,6 +80,10 @@ pub struct Build { package_vers: String, bootstrap_key: String, + // Probed tools at runtime + gdb_version: Option, + lldb_version: Option, + // Runtime state filled in later on cc: HashMap, cxx: HashMap, @@ -128,6 +132,8 @@ impl Build { cc: HashMap::new(), cxx: HashMap::new(), compiler_rt_built: RefCell::new(HashMap::new()), + gdb_version: None, + lldb_version: None, } } @@ -291,6 +297,13 @@ impl Build { DistRustc { stage } => dist::rustc(self, stage, target.target), DistStd { compiler } => dist::std(self, &compiler, target.target), + DebuggerScripts { stage } => { + let compiler = Compiler::new(stage, target.target); + dist::debugger_scripts(self, + &self.sysroot(&compiler), + target.target); + } + Dist { .. } | Doc { .. } | // pseudo-steps Check { .. } => {} @@ -588,8 +601,11 @@ impl Build { } fn cflags(&self, target: &str) -> Vec { + // Filter out -O and /O (the optimization flags) that we picked up from + // gcc-rs because the build scripts will determine that for themselves. let mut base = self.cc[target].0.args().iter() .map(|s| s.to_string_lossy().into_owned()) + .filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) .collect::>(); // If we're compiling on OSX then we add a few unconditional flags diff --git a/src/bootstrap/build/sanity.rs b/src/bootstrap/build/sanity.rs index 75ecfd82febe0..d67be0a12048d 100644 --- a/src/bootstrap/build/sanity.rs +++ b/src/bootstrap/build/sanity.rs @@ -137,4 +137,14 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake target); } } + + let version = |cmd: &str| { + Command::new(cmd).arg("--version").output().map(|output| { + String::from_utf8_lossy(&output.stdout) + .lines().next().unwrap() + .to_string() + }) + }; + build.gdb_version = version("gdb").ok(); + build.lldb_version = version("lldb").ok(); } diff --git a/src/bootstrap/build/step.rs b/src/bootstrap/build/step.rs index cf95a107c829e..ad94c5fd3c0d8 100644 --- a/src/bootstrap/build/step.rs +++ b/src/bootstrap/build/step.rs @@ -62,6 +62,7 @@ macro_rules! targets { (llvm, Llvm { _dummy: () }), (compiler_rt, CompilerRt { _dummy: () }), (test_helpers, TestHelpers { _dummy: () }), + (debugger_scripts, DebuggerScripts { stage: u32 }), // Steps for various pieces of documentation that we can generate, // the 'doc' step is just a pseudo target to depend on a bunch of @@ -289,6 +290,7 @@ impl<'a> Step<'a> { } Source::Llvm { _dummy } => Vec::new(), Source::TestHelpers { _dummy } => Vec::new(), + Source::DebuggerScripts { stage: _ } => Vec::new(), // Note that all doc targets depend on artifacts from the build // architecture, not the target (which is where we're generating @@ -355,9 +357,12 @@ impl<'a> Step<'a> { Source::CheckCFail { compiler } | Source::CheckRPassValgrind { compiler } | Source::CheckRPass { compiler } => { - vec![self.libtest(compiler), - self.tool_compiletest(compiler.stage), - self.test_helpers(())] + vec![ + self.libtest(compiler), + self.tool_compiletest(compiler.stage), + self.test_helpers(()), + self.debugger_scripts(compiler.stage), + ] } Source::CheckRPassFull { compiler } | Source::CheckCFailFull { compiler } => { From 808116fe2f72ccc559f6f95b5c46b2eb3336785c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 7 Apr 2016 13:38:05 -0700 Subject: [PATCH 3/3] rustbuild: Sync changes to Cargo.lock --- src/rustc/Cargo.lock | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/rustc/Cargo.lock b/src/rustc/Cargo.lock index 4b5c2850dab08..a3420d75218fb 100644 --- a/src/rustc/Cargo.lock +++ b/src/rustc/Cargo.lock @@ -73,7 +73,7 @@ dependencies = [ "rbml 0.0.0", "rustc_back 0.0.0", "rustc_bitflags 0.0.0", - "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_data_structures 0.0.0", "serialize 0.0.0", "syntax 0.0.0", @@ -106,6 +106,19 @@ dependencies = [ [[package]] name = "rustc_const_eval" version = "0.0.0" +dependencies = [ + "graphviz 0.0.0", + "log 0.0.0", + "rustc 0.0.0", + "rustc_back 0.0.0", + "rustc_const_math 0.0.0", + "serialize 0.0.0", + "syntax 0.0.0", +] + +[[package]] +name = "rustc_const_math" +version = "0.0.0" dependencies = [ "log 0.0.0", "serialize 0.0.0", @@ -131,6 +144,8 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_borrowck 0.0.0", + "rustc_const_eval 0.0.0", + "rustc_incremental 0.0.0", "rustc_lint 0.0.0", "rustc_llvm 0.0.0", "rustc_metadata 0.0.0", @@ -147,6 +162,19 @@ dependencies = [ "syntax_ext 0.0.0", ] +[[package]] +name = "rustc_incremental" +version = "0.0.0" +dependencies = [ + "graphviz 0.0.0", + "log 0.0.0", + "rbml 0.0.0", + "rustc 0.0.0", + "rustc_data_structures 0.0.0", + "serialize 0.0.0", + "syntax 0.0.0", +] + [[package]] name = "rustc_lint" version = "0.0.0" @@ -154,6 +182,7 @@ dependencies = [ "log 0.0.0", "rustc 0.0.0", "rustc_back 0.0.0", + "rustc_const_eval 0.0.0", "syntax 0.0.0", ] @@ -176,7 +205,7 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_bitflags 0.0.0", - "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_llvm 0.0.0", "serialize 0.0.0", "syntax 0.0.0", @@ -191,6 +220,7 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_data_structures 0.0.0", "syntax 0.0.0", ] @@ -201,6 +231,7 @@ version = "0.0.0" dependencies = [ "log 0.0.0", "rustc 0.0.0", + "rustc_const_eval 0.0.0", "syntax 0.0.0", ] @@ -247,7 +278,6 @@ version = "0.0.0" dependencies = [ "log 0.0.0", "rustc 0.0.0", - "rustc_front 0.0.0", "syntax 0.0.0", ] @@ -262,7 +292,9 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_data_structures 0.0.0", + "rustc_incremental 0.0.0", "rustc_llvm 0.0.0", "rustc_mir 0.0.0", "rustc_platform_intrinsics 0.0.0", @@ -280,6 +312,7 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_platform_intrinsics 0.0.0", "syntax 0.0.0", ] @@ -294,6 +327,7 @@ dependencies = [ "log 0.0.0", "rustc 0.0.0", "rustc_back 0.0.0", + "rustc_const_eval 0.0.0", "rustc_driver 0.0.0", "rustc_lint 0.0.0", "rustc_metadata 0.0.0",