Skip to content

Commit c6707dc

Browse files
committed
return dummy cc and friends during dry runs
Some targets are added to these hashmaps at runtime, and are not present during dry runs. To avoid errors, this commit changes all the related functions to always return empty strings/paths during dry runs.
1 parent 68d458b commit c6707dc

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/bootstrap/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ impl<'a> Builder<'a> {
16501650
}
16511651
};
16521652
cargo.env(profile_var("DEBUG"), debuginfo_level.to_string());
1653-
if self.cc.borrow()[&target].args().iter().any(|arg| arg == "-gz") {
1653+
if !self.config.dry_run() && self.cc.borrow()[&target].args().iter().any(|arg| arg == "-gz") {
16541654
rustflags.arg("-Clink-arg=-gz");
16551655
}
16561656
cargo.env(

src/bootstrap/compile.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,9 @@ pub fn compiler_file(
12721272
c: CLang,
12731273
file: &str,
12741274
) -> PathBuf {
1275+
if builder.config.dry_run() {
1276+
return PathBuf::new();
1277+
}
12751278
let mut cmd = Command::new(compiler);
12761279
cmd.args(builder.cflags(target, GitRepo::Rustc, c));
12771280
cmd.arg(format!("-print-file-name={}", file));

src/bootstrap/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,12 +1104,18 @@ impl Build {
11041104

11051105
/// Returns the path to the C compiler for the target specified.
11061106
fn cc(&self, target: TargetSelection) -> PathBuf {
1107+
if self.config.dry_run() {
1108+
return PathBuf::new();
1109+
}
11071110
self.cc.borrow()[&target].path().into()
11081111
}
11091112

11101113
/// Returns a list of flags to pass to the C compiler for the target
11111114
/// specified.
11121115
fn cflags(&self, target: TargetSelection, which: GitRepo, c: CLang) -> Vec<String> {
1116+
if self.config.dry_run() {
1117+
return Vec::new();
1118+
}
11131119
let base = match c {
11141120
CLang::C => self.cc.borrow()[&target].clone(),
11151121
CLang::Cxx => self.cxx.borrow()[&target].clone(),
@@ -1154,16 +1160,25 @@ impl Build {
11541160

11551161
/// Returns the path to the `ar` archive utility for the target specified.
11561162
fn ar(&self, target: TargetSelection) -> Option<PathBuf> {
1163+
if self.config.dry_run() {
1164+
return None;
1165+
}
11571166
self.ar.borrow().get(&target).cloned()
11581167
}
11591168

11601169
/// Returns the path to the `ranlib` utility for the target specified.
11611170
fn ranlib(&self, target: TargetSelection) -> Option<PathBuf> {
1171+
if self.config.dry_run() {
1172+
return None;
1173+
}
11621174
self.ranlib.borrow().get(&target).cloned()
11631175
}
11641176

11651177
/// Returns the path to the C++ compiler for the target specified.
11661178
fn cxx(&self, target: TargetSelection) -> Result<PathBuf, String> {
1179+
if self.config.dry_run() {
1180+
return Ok(PathBuf::new());
1181+
}
11671182
match self.cxx.borrow().get(&target) {
11681183
Some(p) => Ok(p.path().into()),
11691184
None => {
@@ -1174,6 +1189,9 @@ impl Build {
11741189

11751190
/// Returns the path to the linker for the given target if it needs to be overridden.
11761191
fn linker(&self, target: TargetSelection) -> Option<PathBuf> {
1192+
if self.config.dry_run() {
1193+
return Some(PathBuf::new());
1194+
}
11771195
if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.clone())
11781196
{
11791197
Some(linker)

0 commit comments

Comments
 (0)