Skip to content

Commit 86251da

Browse files
committed
Refactor setup_config_toml into a function
1 parent 71fd3ab commit 86251da

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/bootstrap/setup.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
use crate::Config;
12
use crate::{t, VERSION};
2-
use crate::{Config, TargetSelection};
33
use std::env::consts::EXE_SUFFIX;
44
use std::fmt::Write as _;
55
use std::fs::File;
6+
use std::io::Write;
67
use std::path::{Path, PathBuf, MAIN_SEPARATOR};
78
use std::process::Command;
89
use std::str::FromStr;
9-
use std::{
10-
env, fmt, fs,
11-
io::{self, Write},
12-
};
10+
use std::{fmt, fs, io};
1311

1412
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1513
pub enum Profile {
@@ -84,34 +82,10 @@ impl fmt::Display for Profile {
8482
pub fn setup(config: &Config, profile: Option<Profile>) {
8583
let path = &config.config.clone().unwrap_or(PathBuf::from("config.toml"));
8684
let profile = profile.unwrap_or_else(|| t!(interactive_path()));
85+
setup_config_toml(path, profile, config);
8786

88-
if path.exists() {
89-
eprintln!(
90-
"error: you asked `x.py` to setup a new config file, but one already exists at `{}`",
91-
path.display()
92-
);
93-
eprintln!("help: try adding `profile = \"{}\"` at the top of {}", profile, path.display());
94-
eprintln!(
95-
"note: this will use the configuration in {}",
96-
profile.include_path(&config.src).display()
97-
);
98-
crate::detail_exit(1);
99-
}
100-
101-
let settings = format!(
102-
"# Includes one of the default files in src/bootstrap/defaults\n\
103-
profile = \"{}\"\n\
104-
changelog-seen = {}\n",
105-
profile, VERSION
106-
);
107-
t!(fs::write(path, settings));
108-
109-
let include_path = profile.include_path(&config.src);
110-
println!("`x.py` will now use the configuration at {}", include_path.display());
111-
112-
let build = TargetSelection::from_user(&env!("BUILD_TRIPLE"));
11387
let stage_path =
114-
["build", build.rustc_target_arg(), "stage1"].join(&MAIN_SEPARATOR.to_string());
88+
["build", config.build.rustc_target_arg(), "stage1"].join(&MAIN_SEPARATOR.to_string());
11589

11690
println!();
11791

@@ -153,6 +127,32 @@ pub fn setup(config: &Config, profile: Option<Profile>) {
153127
}
154128
}
155129

130+
fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
131+
if path.exists() {
132+
eprintln!(
133+
"error: you asked `x.py` to setup a new config file, but one already exists at `{}`",
134+
path.display()
135+
);
136+
eprintln!("help: try adding `profile = \"{}\"` at the top of {}", profile, path.display());
137+
eprintln!(
138+
"note: this will use the configuration in {}",
139+
profile.include_path(&config.src).display()
140+
);
141+
crate::detail_exit(1);
142+
}
143+
144+
let settings = format!(
145+
"# Includes one of the default files in src/bootstrap/defaults\n\
146+
profile = \"{}\"\n\
147+
changelog-seen = {}\n",
148+
profile, VERSION
149+
);
150+
t!(fs::write(path, settings));
151+
152+
let include_path = profile.include_path(&config.src);
153+
println!("`x.py` will now use the configuration at {}", include_path.display());
154+
}
155+
156156
fn rustup_installed() -> bool {
157157
Command::new("rustup")
158158
.arg("--version")

0 commit comments

Comments
 (0)