Skip to content

Commit d4e71da

Browse files
z0w0graydon
authored andcommitted
rustpkg: Fix do listeners and support custom test logic
1 parent 15440f4 commit d4e71da

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

src/librustpkg/rustpkg.rc

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,20 @@ impl PackageScript {
222222

223223
// Build the bootstrap and run a command
224224
// 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 {
226226
let work_dir = self.work_dir();
227227
let input = self.input;
228228
let sess = self.sess;
229229
let cfg = self.cfg;
230230
let crate = util::ready_crate(sess, self.crate);
231231
let outputs = driver::build_output_filenames(input, &Some(work_dir),
232232
&None, sess);
233-
let exe = work_dir.push(~"package" + util::exe_suffix());
233+
let exe = work_dir.push(~"pkg" + util::exe_suffix());
234234
let root = filesearch::get_rustpkg_sysroot().get().pop().pop();
235235

236236
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()])
239239
}
240240

241241
fn hash() -> ~str {
@@ -338,10 +338,13 @@ impl Ctx {
338338
}
339339

340340
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");
343344

344-
return false;
345+
return false;
346+
}
347+
_ => {}
345348
}
346349

347350
let cwd = &os::getcwd();
@@ -353,9 +356,9 @@ impl Ctx {
353356
return false;
354357
}
355358
};
356-
let status = script.run(cmd);
359+
let status = script.run(cmd, false);
357360

358-
if status == 1 {
361+
if status == 42 {
359362
util::error(~"no fns are listening for that cmd");
360363

361364
return false;
@@ -406,12 +409,16 @@ impl Ctx {
406409
// Build imperative crates
407410
os::change_dir(dir);
408411

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);
413414

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+
}
415422
}
416423

417424
os::change_dir(cwd);
@@ -748,6 +755,19 @@ impl Ctx {
748755
}
749756
}
750757

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+
751771
util::note(fmt!("tested %s v%s", script.name, script.vers.to_str()));
752772

753773
true
@@ -888,7 +908,6 @@ pub fn main() {
888908
}.run(cmd, args);
889909
}
890910

891-
892911
/// A crate is a unit of Rust code to be compiled into a binary or library
893912
pub struct Crate {
894913
file: ~str,
@@ -918,7 +937,7 @@ pub fn run(listeners: ~[Listener]) {
918937
}
919938

920939
if !found {
921-
os::set_exit_status(1);
940+
os::set_exit_status(42);
922941
}
923942
}
924943

@@ -982,10 +1001,12 @@ pub fn src_dir() -> Path {
9821001

9831002
/// Build a set of crates, should be called once
9841003
pub fn build(crates: ~[Crate]) -> bool {
1004+
let args = os::args();
9851005
let dir = src_dir();
9861006
let work_dir = work_dir();
9871007
let mut success = true;
988-
let sysroot = Path(os::args()[1]);
1008+
let sysroot = Path(args[1]);
1009+
let test = args[3] == ~"true";
9891010

9901011
for crates.each |&crate| {
9911012
let path = &dir.push_rel(&Path(crate.file)).normalize();
@@ -994,13 +1015,13 @@ pub fn build(crates: ~[Crate]) -> bool {
9941015

9951016
success = util::compile_crate(Some(sysroot), path, &work_dir,
9961017
crate.flags, crate.cfgs,
997-
false, false);
1018+
false, test);
9981019

9991020
if !success { break; }
10001021
}
10011022

10021023
if !success {
1003-
os::set_exit_status(2);
1024+
os::set_exit_status(101);
10041025
}
10051026

10061027
success

0 commit comments

Comments
 (0)