Skip to content

Commit f98ffb5

Browse files
committed
Make Build.cxx() return a Result instead of panicking
1 parent 526afcb commit f98ffb5

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

src/bootstrap/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub fn compiletest(build: &Build,
265265
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
266266
let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
267267
cmd.arg("--cc").arg(build.cc(target))
268-
.arg("--cxx").arg(build.cxx(target))
268+
.arg("--cxx").arg(build.cxx(target).unwrap())
269269
.arg("--cflags").arg(build.cflags(target).join(" "))
270270
.arg("--llvm-components").arg(llvm_components.trim())
271271
.arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub fn rustc(build: &Build, target: &str, compiler: &Compiler) {
291291
!target.contains("windows") &&
292292
!target.contains("apple") {
293293
cargo.env("LLVM_STATIC_STDCPP",
294-
compiler_file(build.cxx(target), "libstdc++.a"));
294+
compiler_file(build.cxx(target).unwrap(), "libstdc++.a"));
295295
}
296296
if build.config.llvm_link_shared {
297297
cargo.env("LLVM_LINK_SHARED", "1");

src/bootstrap/lib.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,12 @@ impl Build {
450450
// FIXME: the guard against msvc shouldn't need to be here
451451
if !target.contains("msvc") {
452452
cargo.env(format!("CC_{}", target), self.cc(target))
453-
.env(format!("CXX_{}", target), self.cxx(target))
454453
.env(format!("AR_{}", target), self.ar(target).unwrap()) // only msvc is None
455454
.env(format!("CFLAGS_{}", target), self.cflags(target).join(" "));
455+
456+
if let Ok(cxx) = self.cxx(target) {
457+
cargo.env(format!("CXX_{}", target), cxx);
458+
}
456459
}
457460

458461
if self.config.extended && compiler.is_final_stage(self) {
@@ -839,13 +842,13 @@ impl Build {
839842
self.cc[target].1.as_ref().map(|p| &**p)
840843
}
841844

842-
/// Returns the path to the C++ compiler for the target specified, may panic
843-
/// if no C++ compiler was configured for the target.
844-
fn cxx(&self, target: &str) -> &Path {
845+
/// Returns the path to the C++ compiler for the target specified.
846+
fn cxx(&self, target: &str) -> Result<&Path, String> {
845847
match self.cxx.get(target) {
846-
Some(p) => p.path(),
847-
None => panic!("\n\ntarget `{}` is not configured as a host,
848-
only as a target\n\n", target),
848+
Some(p) => Ok(p.path()),
849+
None => Err(format!(
850+
"target `{}` is not configured as a host, only as a target",
851+
target))
849852
}
850853
}
851854

src/bootstrap/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn llvm(build: &Build, target: &str) {
155155
}
156156

157157
let cc = build.cc(target);
158-
let cxx = build.cxx(target);
158+
let cxx = build.cxx(target).unwrap();
159159

160160
// Handle msvc + ninja + ccache specially (this is what the bots use)
161161
if target.contains("msvc") &&

src/bootstrap/sanity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn check(build: &mut Build) {
139139
}
140140
}
141141
for host in build.config.host.iter() {
142-
need_cmd(build.cxx(host).as_ref());
142+
need_cmd(build.cxx(host).unwrap().as_ref());
143143
}
144144

145145
// The msvc hosts don't use jemalloc, turn it off globally to

0 commit comments

Comments
 (0)