Skip to content

Commit 6e7f679

Browse files
author
Jorge Aparicio
committed
more verbose error messages when Command fails
1 parent c1b600a commit 6e7f679

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

cargo-ify.patch

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,31 @@ index 0000000..e161e91
2525
+path = "../liblibc"
2626
diff --git a/src/liballoc/build.rs b/src/liballoc/build.rs
2727
new file mode 100644
28-
index 0000000..13da524
28+
index 0000000..7fb1260
2929
--- /dev/null
3030
+++ b/src/liballoc/build.rs
31-
@@ -0,0 +1,196 @@
31+
@@ -0,0 +1,208 @@
3232
+#![allow(dead_code)]
3333
+
3434
+use std::fs::File;
3535
+use std::io::Read;
3636
+use std::ops::Range;
3737
+use std::path::{Path, PathBuf};
38-
+use std::process::Command;
38+
+use std::process::{Command, ExitStatus};
3939
+use std::{env, fs, iter};
4040
+
41+
+trait StatusOrPanic {
42+
+ fn status_or_panic(&mut self) -> ExitStatus;
43+
+}
44+
+
45+
+impl StatusOrPanic for Command {
46+
+ fn status_or_panic(&mut self) -> ExitStatus {
47+
+ self.status().unwrap_or_else(|_| {
48+
+ panic!("error: failed to execute {:?}", self)
49+
+ })
50+
+ }
51+
+}
52+
+
4153
+fn main() {
4254
+ let ref ctxt = Ctxt::new().unwrap();
4355
+
@@ -204,14 +216,14 @@ index 0000000..13da524
204216
+ .arg(format!("RANLIB={} s", ar))
205217
+ .arg(format!("CPPFLAGS=-I {}", ctxt.src().join("../rt/").display()))
206218
+ .arg("EXTRA_CFLAGS=-g1 -ffunction-sections -fdata-sections")
207-
+ .status().unwrap().success()
219+
+ .status_or_panic().success()
208220
+ }
209221
+
210222
+ assert! {
211223
+ Command::new("make")
212224
+ .arg("-C").arg(dst)
213225
+ .arg(if dynamic { "build_lib_shared" } else { "build_lib_static" })
214-
+ .status().unwrap().success()
226+
+ .status_or_panic().success()
215227
+ }
216228
+
217229
+ if dynamic {
@@ -378,10 +390,10 @@ index 0000000..cb7a399
378390
+path = "../librustc_unicode"
379391
diff --git a/src/libstd/build.rs b/src/libstd/build.rs
380392
new file mode 100644
381-
index 0000000..13400eb
393+
index 0000000..5f03064
382394
--- /dev/null
383395
+++ b/src/libstd/build.rs
384-
@@ -0,0 +1,308 @@
396+
@@ -0,0 +1,320 @@
385397
+#![allow(dead_code)]
386398
+
387399
+extern crate gcc;
@@ -391,9 +403,21 @@ index 0000000..13400eb
391403
+use std::io::{Read, Write};
392404
+use std::ops::{Range, RangeTo};
393405
+use std::path::{Path, PathBuf};
394-
+use std::process::Command;
406+
+use std::process::{Command, ExitStatus};
395407
+use std::{env, iter};
396408
+
409+
+trait StatusOrPanic {
410+
+ fn status_or_panic(&mut self) -> ExitStatus;
411+
+}
412+
+
413+
+impl StatusOrPanic for Command {
414+
+ fn status_or_panic(&mut self) -> ExitStatus {
415+
+ self.status().unwrap_or_else(|_| {
416+
+ panic!("error: failed to execute {:?}", self)
417+
+ })
418+
+ }
419+
+}
420+
+
397421
+fn main() {
398422
+ let ref ctxt = Ctxt::new().unwrap();
399423
+
@@ -575,7 +599,7 @@ index 0000000..13400eb
575599
+ .env("CFLAGS", cflags.connect(" "))
576600
+ .arg(format!("--target={}", ctxt.target()))
577601
+ .arg(format!("--host={}", ctxt.host()))
578-
+ .status().unwrap().success()
602+
+ .status_or_panic().success()
579603
+ }
580604
+
581605
+ let mut options = OpenOptions::new();
@@ -592,7 +616,7 @@ index 0000000..13400eb
592616
+ Command::new("make")
593617
+ .arg(format!("INCDIR={}", src.display()))
594618
+ .arg("-C").arg(build_dir)
595-
+ .status().unwrap().success()
619+
+ .status_or_panic().success()
596620
+ }
597621
+
598622
+ fs::copy(build_dir.join(".libs/libbacktrace.a"), dst.join("libbacktrace.a")).unwrap();
@@ -613,7 +637,7 @@ index 0000000..13400eb
613637
+ .arg("-relocation-model=pic")
614638
+ .arg("-o").arg(dst.join("rust_try.o"))
615639
+ .arg(src.join("../rt/rust_try.ll"))
616-
+ .status().unwrap().success()
640+
+ .status_or_panic().success()
617641
+ }
618642
+
619643
+ let mut cmd = Command::new(ctxt.cc());
@@ -626,7 +650,7 @@ index 0000000..13400eb
626650
+ .arg(src.join(format!("../rt/arch/{}/record_sp.S", ctxt.arch())))
627651
+ .arg("-c")
628652
+ .arg("-o").arg(dst.join("record_sp.o"))
629-
+ .status().unwrap().success()
653+
+ .status_or_panic().success()
630654
+ }
631655
+
632656
+ assert! {
@@ -635,7 +659,7 @@ index 0000000..13400eb
635659
+ .arg(dst.join("librustrt_native.a"))
636660
+ .arg(dst.join("rust_try.o"))
637661
+ .arg(dst.join("record_sp.o"))
638-
+ .status().unwrap().success()
662+
+ .status_or_panic().success()
639663
+ }
640664
+
641665
+ println!("cargo:rustc-link-lib=static=rustrt_native");
@@ -653,15 +677,15 @@ index 0000000..13400eb
653677
+ .arg(format!("-triple={}", ctxt.target()))
654678
+ .arg("-o").arg(dst.join("morestack.o"))
655679
+ .arg(ctxt.src().join(format!("../rt/arch/{}/morestack.S", ctxt.arch())))
656-
+ .status().unwrap().success()
680+
+ .status_or_panic().success()
657681
+ }
658682
+
659683
+ assert! {
660684
+ Command::new(ctxt.ar())
661685
+ .arg("crus")
662686
+ .arg(dst.join("libmorestack.a"))
663687
+ .arg(dst.join("morestack.o"))
664-
+ .status().unwrap().success()
688+
+ .status_or_panic().success()
665689
+ }
666690
+}
667691
+
@@ -685,7 +709,7 @@ index 0000000..13400eb
685709
+ .arg(format!("ProjObjRoot={}", build_dir.display()))
686710
+ .arg(format!("TargetTriple={}", ctxt.target()))
687711
+ .arg("triple-builtins")
688-
+ .status().unwrap().success()
712+
+ .status_or_panic().success()
689713
+ }
690714
+
691715
+ fs::copy(build_dir.join("triple/builtins/libcompiler_rt.a"), dst.join("libcompiler-rt.a")).unwrap();

0 commit comments

Comments
 (0)