Skip to content

Commit

Permalink
Rollup merge of rust-lang#43042 - Mark-Simulacrum:rustbuild-cleanup, …
Browse files Browse the repository at this point in the history
…r=alexcrichton

Various minor cleanups to rustbuild

This is work I did before the migration to the new rustbuild. I'd prefer to land this first, before my other PR, to make the diff a little clearer.

r? @alexcrichton
  • Loading branch information
Mark-Simulacrum authored Jul 4, 2017
2 parents 2b7cd5a + e04754b commit 1d0c2e9
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 394 deletions.
15 changes: 5 additions & 10 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,11 @@ fn main() {
Err(_) => 0,
};

// Build scripts always use the snapshot compiler which is guaranteed to be
// able to produce an executable, whereas intermediate compilers may not
// have the standard library built yet and may not be able to produce an
// executable. Otherwise we just use the standard compiler we're
// bootstrapping with.
//
// Also note that cargo will detect the version of the compiler to trigger
// a rebuild when the compiler changes. If this happens, we want to make
// sure to use the actual compiler instead of the snapshot compiler becase
// that's the one that's actually changing.
// Use a different compiler for build scripts, since there may not yet be a
// libstd for the real compiler to use. However, if Cargo is attempting to
// determine the version of the compiler, the real compiler needs to be
// used. Currently, these two states are differentiated based on whether
// --target and -vV is/isn't passed.
let (rustc, libdir) = if target.is_none() && version.is_none() {
("RUSTC_SNAPSHOT", "RUSTC_SNAPSHOT_LIBDIR")
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ use config::Target;
pub fn find(build: &mut Build) {
// For all targets we're going to need a C compiler for building some shims
// and such as well as for being a linker for Rust code.
for target in build.config.target.iter() {
for target in &build.targets {
let mut cfg = gcc::Config::new();
cfg.cargo_metadata(false).opt_level(0).debug(false)
.target(target).host(&build.config.build);
.target(target).host(&build.build);

let config = build.config.target_config.get(target);
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
Expand All @@ -64,10 +64,10 @@ pub fn find(build: &mut Build) {
}

// For all host triples we need to find a C++ compiler as well
for host in build.config.host.iter() {
for host in &build.hosts {
let mut cfg = gcc::Config::new();
cfg.cargo_metadata(false).opt_level(0).debug(false).cpp(true)
.target(host).host(&build.config.build);
.target(host).host(&build.build);
let config = build.config.target_config.get(host);
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
Expand Down
10 changes: 7 additions & 3 deletions src/bootstrap/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ use build_helper::output;
use Build;

// The version number
pub const CFG_RELEASE_NUM: &'static str = "1.20.0";
pub const CFG_RELEASE_NUM: &str = "1.20.0";

// An optional number to put after the label, e.g. '.2' -> '-beta.2'
// Be sure to make this starts with a dot to conform to semver pre-release
// versions (section 9)
pub const CFG_PRERELEASE_VERSION: &'static str = ".1";
pub const CFG_PRERELEASE_VERSION: &str = ".1";

pub struct GitInfo {
inner: Option<Info>,
Expand Down Expand Up @@ -99,6 +99,10 @@ impl GitInfo {
version.push_str(&inner.commit_date);
version.push_str(")");
}
return version
version
}

pub fn is_git(&self) -> bool {
self.inner.is_some()
}
}
77 changes: 36 additions & 41 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@
//! This file implements the various regression test suites that we execute on
//! our CI.
extern crate build_helper;

use std::collections::HashSet;
use std::env;
use std::iter;
use std::fmt;
use std::fs::{self, File};
use std::path::{PathBuf, Path};
use std::process::Command;
use std::io::Read;

use build_helper::output;
use build_helper::{self, output};

use {Build, Compiler, Mode};
use dist;
use util::{self, dylib_path, dylib_path_var, exe};

const ADB_TEST_DIR: &'static str = "/data/tmp/work";
const ADB_TEST_DIR: &str = "/data/tmp/work";

/// The two modes of the test runner; tests or benchmarks.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -60,7 +59,7 @@ impl fmt::Display for TestKind {
}

fn try_run(build: &Build, cmd: &mut Command) {
if build.flags.cmd.no_fail_fast() {
if !build.fail_fast {
if !build.try_run(cmd) {
let failures = build.delayed_failures.get();
build.delayed_failures.set(failures + 1);
Expand All @@ -71,7 +70,7 @@ fn try_run(build: &Build, cmd: &mut Command) {
}

fn try_run_quiet(build: &Build, cmd: &mut Command) {
if build.flags.cmd.no_fail_fast() {
if !build.fail_fast {
if !build.try_run_quiet(cmd) {
let failures = build.delayed_failures.get();
build.delayed_failures.set(failures + 1);
Expand Down Expand Up @@ -99,7 +98,7 @@ pub fn linkcheck(build: &Build, host: &str) {
/// This tool in `src/tools` will check out a few Rust projects and run `cargo
/// test` to ensure that we don't regress the test suites there.
pub fn cargotest(build: &Build, stage: u32, host: &str) {
let ref compiler = Compiler::new(stage, host);
let compiler = Compiler::new(stage, host);

// Note that this is a short, cryptic, and not scoped directory name. This
// is currently to minimize the length of path on Windows where we otherwise
Expand All @@ -109,11 +108,11 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {

let _time = util::timeit();
let mut cmd = Command::new(build.tool(&Compiler::new(0, host), "cargotest"));
build.prepare_tool_cmd(compiler, &mut cmd);
try_run(build, cmd.arg(&build.cargo)
build.prepare_tool_cmd(&compiler, &mut cmd);
try_run(build, cmd.arg(&build.initial_cargo)
.arg(&out_dir)
.env("RUSTC", build.compiler_path(compiler))
.env("RUSTDOC", build.rustdoc(compiler)));
.env("RUSTC", build.compiler_path(&compiler))
.env("RUSTDOC", build.rustdoc(&compiler)));
}

/// Runs `cargo test` for `cargo` packaged with Rust.
Expand All @@ -124,13 +123,12 @@ pub fn cargo(build: &Build, stage: u32, host: &str) {
// and not RUSTC because the Cargo test suite has tests that will
// fail if rustc is not spelled `rustc`.
let path = build.sysroot(compiler).join("bin");
let old_path = ::std::env::var("PATH").expect("");
let sep = if cfg!(windows) { ";" } else {":" };
let ref newpath = format!("{}{}{}", path.display(), sep, old_path);
let old_path = env::var_os("PATH").unwrap_or_default();
let newpath = env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("");

let mut cargo = build.cargo(compiler, Mode::Tool, host, "test");
cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
if build.flags.cmd.no_fail_fast() {
if !build.fail_fast {
cargo.arg("--no-fail-fast");
}

Expand Down Expand Up @@ -198,9 +196,9 @@ pub fn compiletest(build: &Build,
cmd.arg("--mode").arg(mode);
cmd.arg("--target").arg(target);
cmd.arg("--host").arg(compiler.host);
cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.config.build));
cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.build));

if let Some(nodejs) = build.config.nodejs.as_ref() {
if let Some(ref nodejs) = build.config.nodejs {
cmd.arg("--nodejs").arg(nodejs);
}

Expand All @@ -224,7 +222,7 @@ pub fn compiletest(build: &Build,

cmd.arg("--docck-python").arg(build.python());

if build.config.build.ends_with("apple-darwin") {
if build.build.ends_with("apple-darwin") {
// Force /usr/bin/python on macOS for LLDB tests because we're loading the
// LLDB plugin's compiled module which only works with the system python
// (namely not Homebrew-installed python)
Expand All @@ -251,7 +249,7 @@ pub fn compiletest(build: &Build,

cmd.args(&build.flags.cmd.test_args());

if build.config.verbose() || build.flags.verbose() {
if build.is_verbose() {
cmd.arg("--verbose");
}

Expand Down Expand Up @@ -279,7 +277,7 @@ pub fn compiletest(build: &Build,

if build.remote_tested(target) {
cmd.arg("--remote-test-client")
.arg(build.tool(&Compiler::new(0, &build.config.build),
.arg(build.tool(&Compiler::new(0, &build.build),
"remote-test-client"));
}

Expand Down Expand Up @@ -368,7 +366,7 @@ pub fn error_index(build: &Build, compiler: &Compiler) {
"error_index_generator")
.arg("markdown")
.arg(&output)
.env("CFG_BUILD", &build.config.build));
.env("CFG_BUILD", &build.build));

markdown_test(build, compiler, &output);
}
Expand Down Expand Up @@ -450,7 +448,7 @@ pub fn krate(build: &Build,
cargo.arg("--manifest-path")
.arg(build.src.join(path).join("Cargo.toml"))
.arg("--features").arg(features);
if test_kind.subcommand() == "test" && build.flags.cmd.no_fail_fast() {
if test_kind.subcommand() == "test" && !build.fail_fast {
cargo.arg("--no-fail-fast");
}

Expand Down Expand Up @@ -520,16 +518,14 @@ fn krate_emscripten(build: &Build,
compiler: &Compiler,
target: &str,
mode: Mode) {
let mut tests = Vec::new();
let out_dir = build.cargo_out(compiler, mode, target);
find_tests(&out_dir.join("deps"), target, &mut tests);
let tests = find_tests(&out_dir.join("deps"), target);

let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
for test in tests {
let test_file_name = test.to_string_lossy().into_owned();
println!("running {}", test_file_name);
let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
println!("running {}", test.display());
let mut cmd = Command::new(nodejs);
cmd.arg(&test_file_name);
cmd.arg(&test);
if build.config.quiet_tests {
cmd.arg("--quiet");
}
Expand All @@ -541,11 +537,10 @@ fn krate_remote(build: &Build,
compiler: &Compiler,
target: &str,
mode: Mode) {
let mut tests = Vec::new();
let out_dir = build.cargo_out(compiler, mode, target);
find_tests(&out_dir.join("deps"), target, &mut tests);
let tests = find_tests(&out_dir.join("deps"), target);

let tool = build.tool(&Compiler::new(0, &build.config.build),
let tool = build.tool(&Compiler::new(0, &build.build),
"remote-test-client");
for test in tests {
let mut cmd = Command::new(&tool);
Expand All @@ -559,9 +554,8 @@ fn krate_remote(build: &Build,
}
}

fn find_tests(dir: &Path,
target: &str,
dst: &mut Vec<PathBuf>) {
fn find_tests(dir: &Path, target: &str) -> Vec<PathBuf> {
let mut dst = Vec::new();
for e in t!(dir.read_dir()).map(|e| t!(e)) {
let file_type = t!(e.file_type());
if !file_type.is_file() {
Expand All @@ -576,6 +570,7 @@ fn find_tests(dir: &Path,
dst.push(e.path());
}
}
dst
}

pub fn remote_copy_libs(build: &Build, compiler: &Compiler, target: &str) {
Expand All @@ -590,7 +585,7 @@ pub fn remote_copy_libs(build: &Build, compiler: &Compiler, target: &str) {
.join(exe("remote-test-server", target));

// Spawn the emulator and wait for it to come online
let tool = build.tool(&Compiler::new(0, &build.config.build),
let tool = build.tool(&Compiler::new(0, &build.build),
"remote-test-client");
let mut cmd = Command::new(&tool);
cmd.arg("spawn-emulator")
Expand All @@ -616,7 +611,7 @@ pub fn remote_copy_libs(build: &Build, compiler: &Compiler, target: &str) {

/// Run "distcheck", a 'make check' from a tarball
pub fn distcheck(build: &Build) {
if build.config.build != "x86_64-unknown-linux-gnu" {
if build.build != "x86_64-unknown-linux-gnu" {
return
}
if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
Expand All @@ -641,7 +636,7 @@ pub fn distcheck(build: &Build) {
.args(&build.config.configure_args)
.arg("--enable-vendor")
.current_dir(&dir));
build.run(Command::new(build_helper::make(&build.config.build))
build.run(Command::new(build_helper::make(&build.build))
.arg("check")
.current_dir(&dir));

Expand All @@ -659,7 +654,7 @@ pub fn distcheck(build: &Build) {
build.run(&mut cmd);

let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
build.run(Command::new(&build.cargo)
build.run(Command::new(&build.initial_cargo)
.arg("generate-lockfile")
.arg("--manifest-path")
.arg(&toml)
Expand All @@ -668,13 +663,13 @@ pub fn distcheck(build: &Build) {

/// Test the build system itself
pub fn bootstrap(build: &Build) {
let mut cmd = Command::new(&build.cargo);
let mut cmd = Command::new(&build.initial_cargo);
cmd.arg("test")
.current_dir(build.src.join("src/bootstrap"))
.env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
.env("RUSTC_BOOTSTRAP", "1")
.env("RUSTC", &build.rustc);
if build.flags.cmd.no_fail_fast() {
.env("RUSTC", &build.initial_rustc);
if !build.fail_fast {
cmd.arg("--no-fail-fast");
}
cmd.arg("--").args(&build.flags.cmd.test_args());
Expand Down
Loading

0 comments on commit 1d0c2e9

Please sign in to comment.