@@ -222,20 +222,20 @@ impl PackageScript {
222
222
223
223
// Build the bootstrap and run a command
224
224
// FIXME (#4432): Use workcache to only compile the script when changed
225
- fn run(cmd: ~str) -> int {
225
+ fn run(cmd: ~str, test: bool ) -> int {
226
226
let work_dir = self.work_dir();
227
227
let input = self.input;
228
228
let sess = self.sess;
229
229
let cfg = self.cfg;
230
230
let crate = util::ready_crate(sess, self.crate);
231
231
let outputs = driver::build_output_filenames(input, &Some(work_dir),
232
232
&None, sess);
233
- let exe = work_dir.push(~"package " + util::exe_suffix());
233
+ let exe = work_dir.push(~"pkg " + util::exe_suffix());
234
234
let root = filesearch::get_rustpkg_sysroot().get().pop().pop();
235
235
236
236
driver::compile_rest(sess, cfg, driver::cu_parse,
237
- Some(outputs), Some(crate));
238
- run::run_program(exe.to_str(), ~[root.to_str(), cmd])
237
+ Some(outputs), Some(crate));
238
+ run::run_program(exe.to_str(), ~[root.to_str(), cmd, test.to_str() ])
239
239
}
240
240
241
241
fn hash() -> ~str {
@@ -338,10 +338,13 @@ impl Ctx {
338
338
}
339
339
340
340
fn do_cmd(cmd: ~str) -> bool {
341
- if cmd == ~"build" {
342
- util::error(~"the build cmd is reserved");
341
+ match cmd {
342
+ ~"build" | ~"test" => {
343
+ util::error(~"that command cannot be manually called");
343
344
344
- return false;
345
+ return false;
346
+ }
347
+ _ => {}
345
348
}
346
349
347
350
let cwd = &os::getcwd();
@@ -353,9 +356,9 @@ impl Ctx {
353
356
return false;
354
357
}
355
358
};
356
- let status = script.run(cmd);
359
+ let status = script.run(cmd, false );
357
360
358
- if status == 1 {
361
+ if status == 42 {
359
362
util::error(~"no fns are listening for that cmd");
360
363
361
364
return false;
@@ -406,12 +409,16 @@ impl Ctx {
406
409
// Build imperative crates
407
410
os::change_dir(dir);
408
411
409
- if script.custom && script.run(~"build") != 0 {
410
- util::error(
411
- fmt!("building %s v%s failed: custom build logic failed",
412
- script.name, script.vers.to_str()));
412
+ if script.custom {
413
+ let status = script.run(~"build", test);
413
414
414
- return None;
415
+ if status != 0 && status != 42 {
416
+ util::error(
417
+ fmt!("building %s v%s failed: custom logic failed (%d)",
418
+ script.name, script.vers.to_str(), status));
419
+
420
+ return None;
421
+ }
415
422
}
416
423
417
424
os::change_dir(cwd);
@@ -748,6 +755,19 @@ impl Ctx {
748
755
}
749
756
}
750
757
758
+ // Run custom test listener
759
+ if script.custom {
760
+ let status = script.run(~"test", false);
761
+
762
+ if status != 0 && status != 42 {
763
+ util::error(
764
+ fmt!("testing %s v%s failed: custom logic failed (%d)",
765
+ script.name, script.vers.to_str(), status));
766
+
767
+ os::set_exit_status(status);
768
+ }
769
+ }
770
+
751
771
util::note(fmt!("tested %s v%s", script.name, script.vers.to_str()));
752
772
753
773
true
@@ -888,7 +908,6 @@ pub fn main() {
888
908
}.run(cmd, args);
889
909
}
890
910
891
-
892
911
/// A crate is a unit of Rust code to be compiled into a binary or library
893
912
pub struct Crate {
894
913
file: ~str,
@@ -918,7 +937,7 @@ pub fn run(listeners: ~[Listener]) {
918
937
}
919
938
920
939
if !found {
921
- os::set_exit_status(1 );
940
+ os::set_exit_status(42 );
922
941
}
923
942
}
924
943
@@ -982,10 +1001,12 @@ pub fn src_dir() -> Path {
982
1001
983
1002
/// Build a set of crates, should be called once
984
1003
pub fn build(crates: ~[Crate]) -> bool {
1004
+ let args = os::args();
985
1005
let dir = src_dir();
986
1006
let work_dir = work_dir();
987
1007
let mut success = true;
988
- let sysroot = Path(os::args()[1]);
1008
+ let sysroot = Path(args[1]);
1009
+ let test = args[3] == ~"true";
989
1010
990
1011
for crates.each |&crate| {
991
1012
let path = &dir.push_rel(&Path(crate.file)).normalize();
@@ -994,13 +1015,13 @@ pub fn build(crates: ~[Crate]) -> bool {
994
1015
995
1016
success = util::compile_crate(Some(sysroot), path, &work_dir,
996
1017
crate.flags, crate.cfgs,
997
- false, false );
1018
+ false, test );
998
1019
999
1020
if !success { break; }
1000
1021
}
1001
1022
1002
1023
if !success {
1003
- os::set_exit_status(2 );
1024
+ os::set_exit_status(101 );
1004
1025
}
1005
1026
1006
1027
success
0 commit comments