]> git.lizzy.rs Git - rust.git/commitdiff
Make Build.cxx() return a Result instead of panicking
authorIan Douglas Scott <ian@iandouglasscott.com>
Thu, 22 Jun 2017 18:51:32 +0000 (11:51 -0700)
committerIan Douglas Scott <ian@iandouglasscott.com>
Thu, 22 Jun 2017 18:51:32 +0000 (11:51 -0700)
src/bootstrap/check.rs
src/bootstrap/compile.rs
src/bootstrap/lib.rs
src/bootstrap/native.rs
src/bootstrap/sanity.rs

index 068efe18cce3d74737ac3bf792dfb59508f2e023..277728b90b763c0b0381512653ecdb332ac0a5b2 100644 (file)
@@ -265,7 +265,7 @@ pub fn compiletest(build: &Build,
         let llvm_components = output(Command::new(&llvm_config).arg("--components"));
         let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
         cmd.arg("--cc").arg(build.cc(target))
-           .arg("--cxx").arg(build.cxx(target))
+           .arg("--cxx").arg(build.cxx(target).unwrap())
            .arg("--cflags").arg(build.cflags(target).join(" "))
            .arg("--llvm-components").arg(llvm_components.trim())
            .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
index f92a199fa3fea08b459f5739c80229eeeafa08ba..c8ab3a8fc1d9947ddf4f47460fa8a597fc8afd0d 100644 (file)
@@ -291,7 +291,7 @@ pub fn rustc(build: &Build, target: &str, compiler: &Compiler) {
        !target.contains("windows") &&
        !target.contains("apple") {
         cargo.env("LLVM_STATIC_STDCPP",
-                  compiler_file(build.cxx(target), "libstdc++.a"));
+                  compiler_file(build.cxx(target).unwrap(), "libstdc++.a"));
     }
     if build.config.llvm_link_shared {
         cargo.env("LLVM_LINK_SHARED", "1");
index 3a43cc0c29d8e13ad30805e8b664044cf3de7c7f..ce7cde8fc9494b6eec53118d5bc0f4c312e8845c 100644 (file)
@@ -450,9 +450,12 @@ fn cargo(&self,
         // FIXME: the guard against msvc shouldn't need to be here
         if !target.contains("msvc") {
             cargo.env(format!("CC_{}", target), self.cc(target))
-                 .env(format!("CXX_{}", target), self.cxx(target))
                  .env(format!("AR_{}", target), self.ar(target).unwrap()) // only msvc is None
                  .env(format!("CFLAGS_{}", target), self.cflags(target).join(" "));
+
+            if let Ok(cxx) = self.cxx(target) {
+                 cargo.env(format!("CXX_{}", target), cxx);
+            }
         }
 
         if self.config.extended && compiler.is_final_stage(self) {
@@ -839,13 +842,13 @@ fn ar(&self, target: &str) -> Option<&Path> {
         self.cc[target].1.as_ref().map(|p| &**p)
     }
 
-    /// Returns the path to the C++ compiler for the target specified, may panic
-    /// if no C++ compiler was configured for the target.
-    fn cxx(&self, target: &str) -> &Path {
+    /// Returns the path to the C++ compiler for the target specified.
+    fn cxx(&self, target: &str) -> Result<&Path, String> {
         match self.cxx.get(target) {
-            Some(p) => p.path(),
-            None => panic!("\n\ntarget `{}` is not configured as a host,
-                            only as a target\n\n", target),
+            Some(p) => Ok(p.path()),
+            None => Err(format!(
+                    "target `{}` is not configured as a host, only as a target",
+                    target))
         }
     }
 
index a23be37b15e0edde19286cdf66830d1fcf255666..f150df6cdcdb0aa9745c450808ab47618ad09564 100644 (file)
@@ -155,7 +155,7 @@ pub fn llvm(build: &Build, target: &str) {
         }
 
         let cc = build.cc(target);
-        let cxx = build.cxx(target);
+        let cxx = build.cxx(target).unwrap();
 
         // Handle msvc + ninja + ccache specially (this is what the bots use)
         if target.contains("msvc") &&
index 5ccd131b77ae46f845c24ee186664ea6a18cc595..46d047bb015e51134c279dff2fbd5e5acd77671e 100644 (file)
@@ -139,7 +139,7 @@ pub fn check(build: &mut Build) {
         }
     }
     for host in build.config.host.iter() {
-        need_cmd(build.cxx(host).as_ref());
+        need_cmd(build.cxx(host).unwrap().as_ref());
     }
 
     // The msvc hosts don't use jemalloc, turn it off globally to