@@ -26,7 +26,7 @@ use build_helper::output;
2626
2727use { Build , Compiler , Mode } ;
2828use dist;
29- use util:: { self , dylib_path, dylib_path_var} ;
29+ use util:: { self , dylib_path, dylib_path_var, exe } ;
3030
3131const ADB_TEST_DIR : & ' static str = "/data/tmp" ;
3232
@@ -221,6 +221,12 @@ pub fn compiletest(build: &Build,
221221 . arg ( "--llvm-cxxflags" ) . arg ( "" ) ;
222222 }
223223
224+ if build. qemu_rootfs ( target) . is_some ( ) {
225+ cmd. arg ( "--qemu-test-client" )
226+ . arg ( build. tool ( & Compiler :: new ( 0 , & build. config . build ) ,
227+ "qemu-test-client" ) ) ;
228+ }
229+
224230 // Running a C compiler on MSVC requires a few env vars to be set, to be
225231 // sure to set them here.
226232 //
@@ -403,9 +409,9 @@ pub fn krate(build: &Build,
403409 dylib_path. insert ( 0 , build. sysroot_libdir ( & compiler, target) ) ;
404410 cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
405411
406- if target. contains ( "android" ) {
407- cargo . arg ( "--no-run" ) ;
408- } else if target. contains ( "emscripten" ) {
412+ if target. contains ( "android" ) ||
413+ target . contains ( "emscripten" ) ||
414+ build . qemu_rootfs ( target) . is_some ( ) {
409415 cargo. arg ( "--no-run" ) ;
410416 }
411417
@@ -423,6 +429,9 @@ pub fn krate(build: &Build,
423429 } else if target. contains ( "emscripten" ) {
424430 build. run ( & mut cargo) ;
425431 krate_emscripten ( build, & compiler, target, mode) ;
432+ } else if build. qemu_rootfs ( target) . is_some ( ) {
433+ build. run ( & mut cargo) ;
434+ krate_qemu ( build, & compiler, target, mode) ;
426435 } else {
427436 cargo. args ( & build. flags . cmd . test_args ( ) ) ;
428437 build. run ( & mut cargo) ;
@@ -480,23 +489,46 @@ fn krate_emscripten(build: &Build,
480489 compiler : & Compiler ,
481490 target : & str ,
482491 mode : Mode ) {
483- let mut tests = Vec :: new ( ) ;
484- let out_dir = build. cargo_out ( compiler, mode, target) ;
485- find_tests ( & out_dir, target, & mut tests) ;
486- find_tests ( & out_dir. join ( "deps" ) , target, & mut tests) ;
487-
488- for test in tests {
489- let test_file_name = test. to_string_lossy ( ) . into_owned ( ) ;
490- println ! ( "running {}" , test_file_name) ;
491- let nodejs = build. config . nodejs . as_ref ( ) . expect ( "nodejs not configured" ) ;
492- let mut cmd = Command :: new ( nodejs) ;
493- cmd. arg ( & test_file_name) ;
494- if build. config . quiet_tests {
495- cmd. arg ( "--quiet" ) ;
496- }
497- build. run ( & mut cmd) ;
498- }
499- }
492+ let mut tests = Vec :: new ( ) ;
493+ let out_dir = build. cargo_out ( compiler, mode, target) ;
494+ find_tests ( & out_dir, target, & mut tests) ;
495+ find_tests ( & out_dir. join ( "deps" ) , target, & mut tests) ;
496+
497+ for test in tests {
498+ let test_file_name = test. to_string_lossy ( ) . into_owned ( ) ;
499+ println ! ( "running {}" , test_file_name) ;
500+ let nodejs = build. config . nodejs . as_ref ( ) . expect ( "nodejs not configured" ) ;
501+ let mut cmd = Command :: new ( nodejs) ;
502+ cmd. arg ( & test_file_name) ;
503+ if build. config . quiet_tests {
504+ cmd. arg ( "--quiet" ) ;
505+ }
506+ build. run ( & mut cmd) ;
507+ }
508+ }
509+
510+ fn krate_qemu ( build : & Build ,
511+ compiler : & Compiler ,
512+ target : & str ,
513+ mode : Mode ) {
514+ let mut tests = Vec :: new ( ) ;
515+ let out_dir = build. cargo_out ( compiler, mode, target) ;
516+ find_tests ( & out_dir, target, & mut tests) ;
517+ find_tests ( & out_dir. join ( "deps" ) , target, & mut tests) ;
518+
519+ let tool = build. tool ( & Compiler :: new ( 0 , & build. config . build ) ,
520+ "qemu-test-client" ) ;
521+ for test in tests {
522+ let mut cmd = Command :: new ( & tool) ;
523+ cmd. arg ( "run" )
524+ . arg ( & test) ;
525+ if build. config . quiet_tests {
526+ cmd. arg ( "--quiet" ) ;
527+ }
528+ cmd. args ( & build. flags . cmd . test_args ( ) ) ;
529+ build. run ( & mut cmd) ;
530+ }
531+ }
500532
501533
502534fn find_tests ( dir : & Path ,
@@ -516,13 +548,15 @@ fn find_tests(dir: &Path,
516548 }
517549}
518550
519- pub fn android_copy_libs ( build : & Build ,
520- compiler : & Compiler ,
521- target : & str ) {
522- if !target . contains ( "android" ) {
523- return
551+ pub fn emulator_copy_libs ( build : & Build , compiler : & Compiler , target : & str ) {
552+ if target . contains ( "android" ) {
553+ android_copy_libs ( build , compiler , target)
554+ } else if let Some ( s ) = build . qemu_rootfs ( target ) {
555+ qemu_copy_libs ( build , compiler , target , s )
524556 }
557+ }
525558
559+ fn android_copy_libs ( build : & Build , compiler : & Compiler , target : & str ) {
526560 println ! ( "Android copy libs to emulator ({})" , target) ;
527561 build. run ( Command :: new ( "adb" ) . arg ( "wait-for-device" ) ) ;
528562 build. run ( Command :: new ( "adb" ) . arg ( "remount" ) ) ;
@@ -548,6 +582,39 @@ pub fn android_copy_libs(build: &Build,
548582 }
549583}
550584
585+ fn qemu_copy_libs ( build : & Build ,
586+ compiler : & Compiler ,
587+ target : & str ,
588+ rootfs : & Path ) {
589+ println ! ( "QEMU copy libs to emulator ({})" , target) ;
590+ assert ! ( target. starts_with( "arm" ) , "only works with arm for now" ) ;
591+ t ! ( fs:: create_dir_all( build. out. join( "tmp" ) ) ) ;
592+
593+ // Copy our freshly compiled test server over to the rootfs
594+ let server = build. cargo_out ( compiler, Mode :: Tool , target)
595+ . join ( exe ( "qemu-test-server" , target) ) ;
596+ t ! ( fs:: copy( & server, rootfs. join( "testd" ) ) ) ;
597+
598+ // Spawn the emulator and wait for it to come online
599+ let tool = build. tool ( & Compiler :: new ( 0 , & build. config . build ) ,
600+ "qemu-test-client" ) ;
601+ build. run ( Command :: new ( & tool)
602+ . arg ( "spawn-emulator" )
603+ . arg ( rootfs)
604+ . arg ( build. out . join ( "tmp" ) ) ) ;
605+
606+ // Push all our dylibs to the emulator
607+ for f in t ! ( build. sysroot_libdir( compiler, target) . read_dir( ) ) {
608+ let f = t ! ( f) ;
609+ let name = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
610+ if util:: is_dylib ( & name) {
611+ build. run ( Command :: new ( & tool)
612+ . arg ( "push" )
613+ . arg ( f. path ( ) ) ) ;
614+ }
615+ }
616+ }
617+
551618/// Run "distcheck", a 'make check' from a tarball
552619pub fn distcheck ( build : & Build ) {
553620 if build. config . build != "x86_64-unknown-linux-gnu" {
0 commit comments