|
| 1 | +use crate::Config; |
1 | 2 | use crate::{t, VERSION};
|
2 |
| -use crate::{Config, TargetSelection}; |
3 | 3 | use std::env::consts::EXE_SUFFIX;
|
4 | 4 | use std::fmt::Write as _;
|
5 | 5 | use std::fs::File;
|
| 6 | +use std::io::Write; |
6 | 7 | use std::path::{Path, PathBuf, MAIN_SEPARATOR};
|
7 | 8 | use std::process::Command;
|
8 | 9 | use std::str::FromStr;
|
9 |
| -use std::{ |
10 |
| - env, fmt, fs, |
11 |
| - io::{self, Write}, |
12 |
| -}; |
| 10 | +use std::{fmt, fs, io}; |
13 | 11 |
|
14 | 12 | #[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
15 | 13 | pub enum Profile {
|
@@ -84,34 +82,10 @@ impl fmt::Display for Profile {
|
84 | 82 | pub fn setup(config: &Config, profile: Option<Profile>) {
|
85 | 83 | let path = &config.config.clone().unwrap_or(PathBuf::from("config.toml"));
|
86 | 84 | let profile = profile.unwrap_or_else(|| t!(interactive_path()));
|
| 85 | + setup_config_toml(path, profile, config); |
87 | 86 |
|
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")); |
113 | 87 | 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()); |
115 | 89 |
|
116 | 90 | println!();
|
117 | 91 |
|
@@ -153,6 +127,32 @@ pub fn setup(config: &Config, profile: Option<Profile>) {
|
153 | 127 | }
|
154 | 128 | }
|
155 | 129 |
|
| 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 | + |
156 | 156 | fn rustup_installed() -> bool {
|
157 | 157 | Command::new("rustup")
|
158 | 158 | .arg("--version")
|
|
0 commit comments