Skip to content

Commit 588db24

Browse files
Correctly handle --use-system-gcc
1 parent 560e65c commit 588db24

File tree

5 files changed

+42
-50
lines changed

5 files changed

+42
-50
lines changed

build_system/src/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
207207
}
208208
run_command_with_output_and_env(&command, None, Some(&env))?;
209209

210-
args.config_info.setup(&mut env, None)?;
210+
args.config_info.setup(&mut env, false)?;
211211

212212
// We voluntarily ignore the error.
213213
let _ = fs::remove_dir_all("target/out");
@@ -229,7 +229,7 @@ pub fn run() -> Result<(), String> {
229229
Some(args) => args,
230230
None => return Ok(()),
231231
};
232-
args.config_info.setup_gcc_path(None)?;
232+
args.config_info.setup_gcc_path()?;
233233
build_codegen(&mut args)?;
234234
Ok(())
235235
}

build_system/src/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn run() -> Result<(), String> {
7777
})?;
7878

7979
let mut env: HashMap<String, String> = std::env::vars().collect();
80-
ConfigInfo::default().setup(&mut env, None)?;
80+
ConfigInfo::default().setup(&mut env, false)?;
8181
let toolchain = get_toolchain()?;
8282

8383
let toolchain_version = rustc_toolchain_version_info(&toolchain)?;

build_system/src/config.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,17 @@ impl ConfigInfo {
159159
command
160160
}
161161

162-
pub fn setup_gcc_path(&mut self, override_gcc_path: Option<&str>) -> Result<(), String> {
162+
pub fn setup_gcc_path(&mut self) -> Result<(), String> {
163163
let ConfigFile { gcc_path, .. } = ConfigFile::new(self.config_file.as_deref())?;
164164

165-
self.gcc_path = match override_gcc_path {
166-
Some(path) => {
167-
if gcc_path.is_some() {
168-
println!(
169-
"overriding setting from `{}`",
170-
self.config_file.as_deref().unwrap_or("config.toml")
171-
);
172-
}
173-
path.to_string()
174-
}
165+
self.gcc_path = match gcc_path {
166+
Some(path) => path,
167+
// FIXME: Once we support "download", rewrite this.
175168
None => {
176-
match gcc_path {
177-
Some(path) => path,
178-
// FIXME: Once we support "download", rewrite this.
179-
None => {
180-
return Err(format!(
181-
"missing `gcc-path` value from `{}`",
182-
self.config_file.as_deref().unwrap_or("config.toml"),
183-
))
184-
}
185-
}
169+
return Err(format!(
170+
"missing `gcc-path` value from `{}`",
171+
self.config_file.as_deref().unwrap_or("config.toml"),
172+
))
186173
}
187174
};
188175
Ok(())
@@ -191,12 +178,12 @@ impl ConfigInfo {
191178
pub fn setup(
192179
&mut self,
193180
env: &mut HashMap<String, String>,
194-
override_gcc_path: Option<&str>,
181+
use_system_gcc: bool,
195182
) -> Result<(), String> {
196183
env.insert("CARGO_INCREMENTAL".to_string(), "0".to_string());
197184

198-
if self.gcc_path.is_empty() || override_gcc_path.is_some() {
199-
self.setup_gcc_path(override_gcc_path)?;
185+
if self.gcc_path.is_empty() && !use_system_gcc {
186+
self.setup_gcc_path()?;
200187
}
201188
env.insert("GCC_PATH".to_string(), self.gcc_path.clone());
202189

build_system/src/test.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ fn get_runners() -> Runners {
3131
"--test-failing-rustc",
3232
("Run failing rustc tests", test_failing_rustc),
3333
);
34-
runners.insert("--projects", ("Run the tests of popular crates", test_projects));
34+
runners.insert(
35+
"--projects",
36+
("Run the tests of popular crates", test_projects),
37+
);
3538
runners.insert("--test-libcore", ("Run libcore tests", test_libcore));
3639
runners.insert("--clean", ("Empty cargo target directory", clean));
3740
runners.insert("--build-sysroot", ("Build sysroot", build_sysroot));
@@ -109,7 +112,7 @@ fn show_usage() {
109112
struct TestArg {
110113
no_default_features: bool,
111114
build_only: bool,
112-
gcc_path: Option<String>,
115+
use_system_gcc: bool,
113116
runners: BTreeSet<String>,
114117
flags: Vec<String>,
115118
backend: Option<String>,
@@ -121,7 +124,6 @@ struct TestArg {
121124

122125
impl TestArg {
123126
fn new() -> Result<Option<Self>, String> {
124-
let mut use_system_gcc = false;
125127
let mut test_arg = Self::default();
126128

127129
// We skip binary name and the `test` command.
@@ -147,7 +149,10 @@ impl TestArg {
147149
return Err("Expected an argument after `--features`, found nothing".into())
148150
}
149151
},
150-
"--use-system-gcc" => use_system_gcc = true,
152+
"--use-system-gcc" => {
153+
println!("Using system GCC");
154+
test_arg.use_system_gcc = true;
155+
}
151156
"--build-only" => test_arg.build_only = true,
152157
"--use-backend" => match args.next() {
153158
Some(backend) if !backend.is_empty() => test_arg.backend = Some(backend),
@@ -180,11 +185,6 @@ impl TestArg {
180185
}
181186
}
182187
}
183-
184-
if use_system_gcc {
185-
println!("Using system GCC");
186-
test_arg.gcc_path = Some("gcc".to_string());
187-
}
188188
}
189189
match (test_arg.current_part, test_arg.nb_parts) {
190190
(Some(_), Some(_)) | (None, None) => {}
@@ -703,7 +703,7 @@ fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
703703
//"https://github.com/rust-lang/cargo", // TODO: very slow, only run on master?
704704
];
705705

706-
let run_tests = |projects_path, iter: &mut dyn Iterator<Item=&&str>| -> Result<(), String> {
706+
let run_tests = |projects_path, iter: &mut dyn Iterator<Item = &&str>| -> Result<(), String> {
707707
for project in iter {
708708
let clone_result = git_clone(project, Some(projects_path), true)?;
709709
let repo_path = Path::new(&clone_result.repo_dir);
@@ -727,8 +727,7 @@ fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
727727
let start = current_part * count;
728728
// We remove the projects we don't want to test.
729729
run_tests(projects_path, &mut projects.iter().skip(start).take(count))?;
730-
}
731-
else {
730+
} else {
732731
run_tests(projects_path, &mut projects.iter())?;
733732
}
734733

@@ -1166,23 +1165,25 @@ pub fn run() -> Result<(), String> {
11661165
};
11671166
let mut env: HashMap<String, String> = std::env::vars().collect();
11681167

1169-
args.config_info.setup_gcc_path(None)?;
1170-
env.insert(
1171-
"LIBRARY_PATH".to_string(),
1172-
args.config_info.gcc_path.clone(),
1173-
);
1174-
env.insert(
1175-
"LD_LIBRARY_PATH".to_string(),
1176-
args.config_info.gcc_path.clone(),
1177-
);
1168+
if !args.use_system_gcc {
1169+
args.config_info.setup_gcc_path()?;
1170+
env.insert(
1171+
"LIBRARY_PATH".to_string(),
1172+
args.config_info.gcc_path.clone(),
1173+
);
1174+
env.insert(
1175+
"LD_LIBRARY_PATH".to_string(),
1176+
args.config_info.gcc_path.clone(),
1177+
);
1178+
}
11781179

11791180
build_if_no_backend(&env, &args)?;
11801181
if args.build_only {
11811182
println!("Since it's build only, exiting...");
11821183
return Ok(());
11831184
}
11841185

1185-
args.config_info.setup(&mut env, args.gcc_path.as_deref())?;
1186+
args.config_info.setup(&mut env, args.use_system_gcc)?;
11861187

11871188
if args.runners.is_empty() {
11881189
run_all(&env, &args)?;

build_system/src/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ pub struct CloneResult {
254254
pub repo_dir: String,
255255
}
256256

257-
pub fn git_clone(to_clone: &str, dest: Option<&Path>, shallow_clone: bool) -> Result<CloneResult, String> {
257+
pub fn git_clone(
258+
to_clone: &str,
259+
dest: Option<&Path>,
260+
shallow_clone: bool,
261+
) -> Result<CloneResult, String> {
258262
let repo_name = to_clone.split('/').last().unwrap();
259263
let repo_name = match repo_name.strip_suffix(".git") {
260264
Some(n) => n.to_string(),

0 commit comments

Comments
 (0)