Skip to content

Commit

Permalink
thread tool modes through
Browse files Browse the repository at this point in the history
  • Loading branch information
Collins Abitekaniza committed Jun 3, 2018
1 parent ce10910 commit fb949b5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/check.rs
Expand Up @@ -219,6 +219,7 @@ impl Step for Rustdoc {

let mut cargo = prepare_tool_cargo(builder,
compiler,
Mode::Rustc,
target,
"check",
"src/tools/rustdoc");
Expand Down
28 changes: 18 additions & 10 deletions src/bootstrap/test.rs
Expand Up @@ -281,7 +281,12 @@ impl Step for Rls {
return;
}

let mut cargo = tool::prepare_tool_cargo(builder, compiler, host, "test", "src/tools/rls");
let mut cargo = tool::prepare_tool_cargo(builder,
compiler,
Mode::Rustc,
host,
"test",
"src/tools/rls");

// Don't build tests dynamically, just a pain to work with
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
Expand Down Expand Up @@ -331,8 +336,12 @@ impl Step for Rustfmt {
return;
}

let mut cargo =
tool::prepare_tool_cargo(builder, compiler, host, "test", "src/tools/rustfmt");
let mut cargo = tool::prepare_tool_cargo(builder,
compiler,
Mode::Rustc,
host,
"test",
"src/tools/rustfmt");

// Don't build tests dynamically, just a pain to work with
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
Expand Down Expand Up @@ -1718,13 +1727,12 @@ impl Step for CrateRustdoc {
let compiler = builder.compiler(builder.top_stage, self.host);
let target = compiler.host;

let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
target,
test_kind.subcommand(),
"src/tools/rustdoc",
);
let mut cargo = tool::prepare_tool_cargo(builder,
compiler,
Mode::Rustc,
target,
test_kind.subcommand(),
"src/tools/rustdoc");
if test_kind.subcommand() == "test" && !builder.fail_fast {
cargo.arg("--no-fail-fast");
}
Expand Down
23 changes: 17 additions & 6 deletions src/bootstrap/tool.rs
Expand Up @@ -110,7 +110,7 @@ impl Step for ToolBuild {
_ => panic!("unexpected Mode for tool build")
}

let mut cargo = prepare_tool_cargo(builder, compiler, target, "build", path);
let mut cargo = prepare_tool_cargo(builder, compiler, self.mode, target, "build", path);
cargo.arg("--features").arg(self.extra_features.join(" "));

let _folder = builder.fold_output(|| format!("stage{}-{}", compiler.stage, tool));
Expand Down Expand Up @@ -202,7 +202,7 @@ impl Step for ToolBuild {
return None;
}
} else {
let cargo_out = builder.cargo_out(compiler, Mode::ToolRustc, target)
let cargo_out = builder.cargo_out(compiler, self.mode, target)
.join(exe(tool, &compiler.host));
let bin = builder.tools_dir(compiler).join(exe(tool, &compiler.host));
builder.copy(&cargo_out, &bin);
Expand All @@ -214,11 +214,12 @@ impl Step for ToolBuild {
pub fn prepare_tool_cargo(
builder: &Builder,
compiler: Compiler,
mode: Mode,
target: Interned<String>,
command: &'static str,
path: &'static str,
) -> Command {
let mut cargo = builder.cargo(compiler, Mode::ToolRustc, target, command);
let mut cargo = builder.cargo(compiler, mode, target, command);
let dir = builder.src.join(path);
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));

Expand Down Expand Up @@ -261,6 +262,15 @@ macro_rules! tool {
)+
}

impl Tool {
pub fn get_mode(&self) -> Mode {
let mode = match self {
$(Tool::$name => $mode,)+
};
mode
}
}

impl<'a> Builder<'a> {
pub fn tool_exe(&self, tool: Tool) -> PathBuf {
let stage = self.tool_default_stage(tool);
Expand Down Expand Up @@ -414,6 +424,7 @@ impl Step for Rustdoc {

let mut cargo = prepare_tool_cargo(builder,
build_compiler,
Mode::ToolRustc,
target,
"build",
"src/tools/rustdoc");
Expand Down Expand Up @@ -575,19 +586,19 @@ impl<'a> Builder<'a> {
pub fn tool_cmd(&self, tool: Tool) -> Command {
let mut cmd = Command::new(self.tool_exe(tool));
let compiler = self.compiler(self.tool_default_stage(tool), self.config.build);
self.prepare_tool_cmd(compiler, &mut cmd);
self.prepare_tool_cmd(compiler, tool.get_mode(), &mut cmd);
cmd
}

/// Prepares the `cmd` provided to be able to run the `compiler` provided.
///
/// Notably this munges the dynamic library lookup path to point to the
/// right location to run `compiler`.
fn prepare_tool_cmd(&self, compiler: Compiler, cmd: &mut Command) {
fn prepare_tool_cmd(&self, compiler: Compiler, mode: Mode, cmd: &mut Command) {
let host = &compiler.host;
let mut lib_paths: Vec<PathBuf> = vec![
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host)),
self.cargo_out(compiler, Mode::ToolRustc, *host).join("deps"),
self.cargo_out(compiler, mode, *host).join("deps"),
];

// On MSVC a tool may invoke a C compiler (e.g. compiletest in run-make
Expand Down

0 comments on commit fb949b5

Please sign in to comment.