mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
fix linking stage1 toolchain in setup
This commit is contained in:
parent
7cc28c128b
commit
a4112dc7b5
@ -1,7 +1,9 @@
|
|||||||
use crate::TargetSelection;
|
use crate::TargetSelection;
|
||||||
use crate::{t, VERSION};
|
use crate::{t, VERSION};
|
||||||
|
use std::env::consts::EXE_SUFFIX;
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
use std::path::{Path, PathBuf};
|
use std::fs::File;
|
||||||
|
use std::path::{Path, PathBuf, MAIN_SEPARATOR};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::{
|
use std::{
|
||||||
@ -109,7 +111,8 @@ pub fn setup(src_path: &Path, profile: Profile) {
|
|||||||
println!("`x.py` will now use the configuration at {}", include_path.display());
|
println!("`x.py` will now use the configuration at {}", include_path.display());
|
||||||
|
|
||||||
let build = TargetSelection::from_user(&env!("BUILD_TRIPLE"));
|
let build = TargetSelection::from_user(&env!("BUILD_TRIPLE"));
|
||||||
let stage_path = ["build", build.rustc_target_arg(), "stage1"].join("/");
|
let stage_path =
|
||||||
|
["build", build.rustc_target_arg(), "stage1"].join(&MAIN_SEPARATOR.to_string());
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
|
|
||||||
@ -171,6 +174,13 @@ fn attempt_toolchain_link(stage_path: &str) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !ensure_stage1_toolchain_placeholder_exists(stage_path) {
|
||||||
|
println!(
|
||||||
|
"Failed to create a template for stage 1 toolchain or confirm that it already exists"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if try_link_toolchain(&stage_path[..]) {
|
if try_link_toolchain(&stage_path[..]) {
|
||||||
println!(
|
println!(
|
||||||
"Added `stage1` rustup toolchain; try `cargo +stage1 build` on a separate rust project to run a newly-built toolchain"
|
"Added `stage1` rustup toolchain; try `cargo +stage1 build` on a separate rust project to run a newly-built toolchain"
|
||||||
@ -219,6 +229,33 @@ fn try_link_toolchain(stage_path: &str) -> bool {
|
|||||||
.map_or(false, |output| output.status.success())
|
.map_or(false, |output| output.status.success())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ensure_stage1_toolchain_placeholder_exists(stage_path: &str) -> bool {
|
||||||
|
let pathbuf = PathBuf::from(stage_path);
|
||||||
|
|
||||||
|
if fs::create_dir_all(pathbuf.join("lib")).is_err() {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
let pathbuf = pathbuf.join("bin");
|
||||||
|
if fs::create_dir_all(&pathbuf).is_err() {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
let pathbuf = pathbuf.join(format!("rustc{}", EXE_SUFFIX));
|
||||||
|
|
||||||
|
if pathbuf.exists() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Take care not to overwrite the file
|
||||||
|
let result = File::options().append(true).create(true).open(&pathbuf);
|
||||||
|
if result.is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Used to get the path for `Subcommand::Setup`
|
// Used to get the path for `Subcommand::Setup`
|
||||||
pub fn interactive_path() -> io::Result<Profile> {
|
pub fn interactive_path() -> io::Result<Profile> {
|
||||||
fn abbrev_all() -> impl Iterator<Item = ((String, String), Profile)> {
|
fn abbrev_all() -> impl Iterator<Item = ((String, String), Profile)> {
|
||||||
|
Loading…
Reference in New Issue
Block a user