Skip to content

Commit 2cc5b08

Browse files
Clarify meaning of Build.cargo, Build.rustc.
Rename Build.{cargo, rustc} to {initial_cargo, initial_rustc}.
1 parent 743af95 commit 2cc5b08

File tree

6 files changed

+50
-41
lines changed

6 files changed

+50
-41
lines changed

src/bootstrap/check.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {
109109
let _time = util::timeit();
110110
let mut cmd = Command::new(build.tool(&Compiler::new(0, host), "cargotest"));
111111
build.prepare_tool_cmd(&compiler, &mut cmd);
112-
try_run(build, cmd.arg(&build.cargo)
112+
try_run(build, cmd.arg(&build.initial_cargo)
113113
.arg(&out_dir)
114114
.env("RUSTC", build.compiler_path(&compiler))
115115
.env("RUSTDOC", build.rustdoc(&compiler)));
@@ -654,7 +654,7 @@ pub fn distcheck(build: &Build) {
654654
build.run(&mut cmd);
655655

656656
let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
657-
build.run(Command::new(&build.cargo)
657+
build.run(Command::new(&build.initial_cargo)
658658
.arg("generate-lockfile")
659659
.arg("--manifest-path")
660660
.arg(&toml)
@@ -663,12 +663,12 @@ pub fn distcheck(build: &Build) {
663663

664664
/// Test the build system itself
665665
pub fn bootstrap(build: &Build) {
666-
let mut cmd = Command::new(&build.cargo);
666+
let mut cmd = Command::new(&build.initial_cargo);
667667
cmd.arg("test")
668668
.current_dir(build.src.join("src/bootstrap"))
669669
.env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
670670
.env("RUSTC_BOOTSTRAP", "1")
671-
.env("RUSTC", &build.rustc);
671+
.env("RUSTC", &build.initial_rustc);
672672
if build.flags.cmd.no_fail_fast() {
673673
cmd.arg("--no-fail-fast");
674674
}

src/bootstrap/config.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ pub struct Config {
8181
pub build: String,
8282
pub host: Vec<String>,
8383
pub target: Vec<String>,
84-
pub rustc: Option<PathBuf>,
85-
pub cargo: Option<PathBuf>,
8684
pub local_rebuild: bool,
8785

8886
// dist misc
@@ -114,6 +112,12 @@ pub struct Config {
114112
pub python: Option<PathBuf>,
115113
pub configure_args: Vec<String>,
116114
pub openssl_static: bool,
115+
116+
117+
// These are either the stage0 downloaded binaries or the locally installed ones.
118+
pub initial_cargo: PathBuf,
119+
pub initial_rustc: PathBuf,
120+
117121
}
118122

119123
/// Per-target configuration stored in the global configuration structure.
@@ -308,8 +312,6 @@ impl Config {
308312
config.target.push(target.clone());
309313
}
310314
}
311-
config.rustc = build.rustc.map(PathBuf::from);
312-
config.cargo = build.cargo.map(PathBuf::from);
313315
config.nodejs = build.nodejs.map(PathBuf::from);
314316
config.gdb = build.gdb.map(PathBuf::from);
315317
config.python = build.python.map(PathBuf::from);
@@ -411,6 +413,18 @@ impl Config {
411413
set(&mut config.rust_dist_src, t.src_tarball);
412414
}
413415

416+
let cwd = t!(env::current_dir());
417+
let out = cwd.join("build");
418+
419+
let stage0_root = out.join(&config.build).join("stage0/bin");
420+
config.initial_rustc = match build.rustc {
421+
Some(s) => PathBuf::from(s),
422+
None => stage0_root.join(exe("rustc", &config.build)),
423+
};
424+
config.initial_cargo = match build.cargo {
425+
Some(s) => PathBuf::from(s),
426+
None => stage0_root.join(exe("cargo", &config.build)),
427+
};
414428

415429
// compat with `./configure` while we're still using that
416430
if fs::metadata("config.mk").is_ok() {
@@ -610,8 +624,8 @@ impl Config {
610624
}
611625
"CFG_LOCAL_RUST_ROOT" if value.len() > 0 => {
612626
let path = parse_configure_path(value);
613-
self.rustc = Some(push_exe_path(path.clone(), &["bin", "rustc"]));
614-
self.cargo = Some(push_exe_path(path, &["bin", "cargo"]));
627+
self.initial_rustc = push_exe_path(path.clone(), &["bin", "rustc"]);
628+
self.initial_cargo = push_exe_path(path, &["bin", "cargo"]);
615629
}
616630
"CFG_PYTHON" if value.len() > 0 => {
617631
let path = parse_configure_path(value);

src/bootstrap/dist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,23 +626,23 @@ pub fn plain_source_tarball(build: &Build) {
626626
if build.src_is_git {
627627
// Get cargo-vendor installed, if it isn't already.
628628
let mut has_cargo_vendor = false;
629-
let mut cmd = Command::new(&build.cargo);
629+
let mut cmd = Command::new(&build.initial_cargo);
630630
for line in output(cmd.arg("install").arg("--list")).lines() {
631631
has_cargo_vendor |= line.starts_with("cargo-vendor ");
632632
}
633633
if !has_cargo_vendor {
634-
let mut cmd = Command::new(&build.cargo);
634+
let mut cmd = Command::new(&build.initial_cargo);
635635
cmd.arg("install")
636636
.arg("--force")
637637
.arg("--debug")
638638
.arg("--vers").arg(CARGO_VENDOR_VERSION)
639639
.arg("cargo-vendor")
640-
.env("RUSTC", &build.rustc);
640+
.env("RUSTC", &build.initial_rustc);
641641
build.run(&mut cmd);
642642
}
643643

644644
// Vendor all Cargo dependencies
645-
let mut cmd = Command::new(&build.cargo);
645+
let mut cmd = Command::new(&build.initial_cargo);
646646
cmd.arg("vendor")
647647
.current_dir(&plain_dst_src.join("src"));
648648
build.run(&mut cmd);

src/bootstrap/flags.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Flags {
3535
pub host: Vec<String>,
3636
pub target: Vec<String>,
3737
pub config: Option<PathBuf>,
38-
pub src: Option<PathBuf>,
38+
pub src: PathBuf,
3939
pub jobs: Option<u32>,
4040
pub cmd: Subcommand,
4141
pub incremental: bool,
@@ -319,6 +319,11 @@ Arguments:
319319
stage = Some(1);
320320
}
321321

322+
let cwd = t!(env::current_dir());
323+
let src = matches.opt_str("src").map(PathBuf::from)
324+
.or_else(|| env::var_os("SRC").map(PathBuf::from))
325+
.unwrap_or(cwd);
326+
322327
Flags {
323328
verbose: matches.opt_count("verbose"),
324329
stage: stage,
@@ -330,7 +335,7 @@ Arguments:
330335
host: split(matches.opt_strs("host")),
331336
target: split(matches.opt_strs("target")),
332337
config: cfg_file,
333-
src: matches.opt_str("src").map(PathBuf::from),
338+
src: src,
334339
jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()),
335340
cmd: cmd,
336341
incremental: matches.opt_present("incremental"),

src/bootstrap/lib.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,17 @@ pub struct Build {
161161
flags: Flags,
162162

163163
// Derived properties from the above two configurations
164-
cargo: PathBuf,
165-
rustc: PathBuf,
166164
src: PathBuf,
167165
out: PathBuf,
168166
rust_info: channel::GitInfo,
169167
cargo_info: channel::GitInfo,
170168
rls_info: channel::GitInfo,
171169
local_rebuild: bool,
172170

171+
// Stage 0 (downloaded) compiler and cargo or their local rust equivalents.
172+
initial_rustc: PathBuf,
173+
initial_cargo: PathBuf,
174+
173175
// Probed tools at runtime
174176
lldb_version: Option<String>,
175177
lldb_python_dir: Option<String>,
@@ -224,22 +226,9 @@ impl Build {
224226
/// By default all build output will be placed in the current directory.
225227
pub fn new(flags: Flags, config: Config) -> Build {
226228
let cwd = t!(env::current_dir());
227-
let src = flags.src.clone().or_else(|| {
228-
env::var_os("SRC").map(|x| x.into())
229-
}).unwrap_or(cwd.clone());
229+
let src = flags.src.clone();
230230
let out = cwd.join("build");
231231

232-
let stage0_root = out.join(&config.build).join("stage0/bin");
233-
let rustc = match config.rustc {
234-
Some(ref s) => PathBuf::from(s),
235-
None => stage0_root.join(exe("rustc", &config.build)),
236-
};
237-
let cargo = match config.cargo {
238-
Some(ref s) => PathBuf::from(s),
239-
None => stage0_root.join(exe("cargo", &config.build)),
240-
};
241-
let local_rebuild = config.local_rebuild;
242-
243232
let is_sudo = match env::var_os("SUDO_USER") {
244233
Some(sudo_user) => {
245234
match env::var_os("USER") {
@@ -255,17 +244,18 @@ impl Build {
255244
let src_is_git = src.join(".git").exists();
256245

257246
Build {
247+
initial_rustc: config.initial_rustc.clone(),
248+
initial_cargo: config.initial_cargo.clone(),
249+
local_rebuild: config.local_rebuild,
250+
258251
flags: flags,
259252
config: config,
260-
cargo: cargo,
261-
rustc: rustc,
262253
src: src,
263254
out: out,
264255

265256
rust_info: rust_info,
266257
cargo_info: cargo_info,
267258
rls_info: rls_info,
268-
local_rebuild: local_rebuild,
269259
cc: HashMap::new(),
270260
cxx: HashMap::new(),
271261
crates: HashMap::new(),
@@ -294,7 +284,7 @@ impl Build {
294284
sanity::check(self);
295285
// If local-rust is the same major.minor as the current version, then force a local-rebuild
296286
let local_version_verbose = output(
297-
Command::new(&self.rustc).arg("--version").arg("--verbose"));
287+
Command::new(&self.initial_rustc).arg("--version").arg("--verbose"));
298288
let local_release = local_version_verbose
299289
.lines().filter(|x| x.starts_with("release:"))
300290
.next().unwrap().trim_left_matches("release:").trim();
@@ -336,7 +326,7 @@ impl Build {
336326
mode: Mode,
337327
target: &str,
338328
cmd: &str) -> Command {
339-
let mut cargo = Command::new(&self.cargo);
329+
let mut cargo = Command::new(&self.initial_cargo);
340330
let out_dir = self.stage_out(compiler, mode);
341331
cargo.env("CARGO_TARGET_DIR", out_dir)
342332
.arg(cmd)
@@ -420,7 +410,7 @@ impl Build {
420410
// library up and running, so we can use the normal compiler to compile
421411
// build scripts in that situation.
422412
if mode == Mode::Libstd {
423-
cargo.env("RUSTC_SNAPSHOT", &self.rustc)
413+
cargo.env("RUSTC_SNAPSHOT", &self.initial_rustc)
424414
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
425415
} else {
426416
cargo.env("RUSTC_SNAPSHOT", self.compiler_path(compiler))
@@ -500,7 +490,7 @@ impl Build {
500490
/// Get a path to the compiler specified.
501491
fn compiler_path(&self, compiler: &Compiler) -> PathBuf {
502492
if compiler.is_snapshot(self) {
503-
self.rustc.clone()
493+
self.initial_rustc.clone()
504494
} else {
505495
self.sysroot(compiler).join("bin").join(exe("rustc", compiler.host))
506496
}
@@ -758,7 +748,7 @@ impl Build {
758748

759749
/// Returns the libdir of the snapshot compiler.
760750
fn rustc_snapshot_libdir(&self) -> PathBuf {
761-
self.rustc.parent().unwrap().parent().unwrap()
751+
self.initial_rustc.parent().unwrap().parent().unwrap()
762752
.join(libdir(&self.config.build))
763753
}
764754

src/bootstrap/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn build_krate(build: &mut Build, krate: &str) {
5656
// of packages we're going to have to know what `-p` arguments to pass it
5757
// to know what crates to test. Here we run `cargo metadata` to learn about
5858
// the dependency graph and what `-p` arguments there are.
59-
let mut cargo = Command::new(&build.cargo);
59+
let mut cargo = Command::new(&build.initial_cargo);
6060
cargo.arg("metadata")
6161
.arg("--format-version").arg("1")
6262
.arg("--manifest-path").arg(build.src.join(krate).join("Cargo.toml"));

0 commit comments

Comments
 (0)