@@ -26,7 +26,7 @@ use build_helper::output;
26
26
27
27
use { Build , Compiler , Mode } ;
28
28
use dist;
29
- use util:: { self , dylib_path, dylib_path_var} ;
29
+ use util:: { self , dylib_path, dylib_path_var, exe } ;
30
30
31
31
const ADB_TEST_DIR : & ' static str = "/data/tmp" ;
32
32
@@ -221,6 +221,12 @@ pub fn compiletest(build: &Build,
221
221
. arg ( "--llvm-cxxflags" ) . arg ( "" ) ;
222
222
}
223
223
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
+
224
230
// Running a C compiler on MSVC requires a few env vars to be set, to be
225
231
// sure to set them here.
226
232
//
@@ -403,9 +409,9 @@ pub fn krate(build: &Build,
403
409
dylib_path. insert ( 0 , build. sysroot_libdir ( & compiler, target) ) ;
404
410
cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
405
411
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 ( ) {
409
415
cargo. arg ( "--no-run" ) ;
410
416
}
411
417
@@ -423,6 +429,9 @@ pub fn krate(build: &Build,
423
429
} else if target. contains ( "emscripten" ) {
424
430
build. run ( & mut cargo) ;
425
431
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) ;
426
435
} else {
427
436
cargo. args ( & build. flags . cmd . test_args ( ) ) ;
428
437
build. run ( & mut cargo) ;
@@ -480,23 +489,46 @@ fn krate_emscripten(build: &Build,
480
489
compiler : & Compiler ,
481
490
target : & str ,
482
491
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
+ }
500
532
501
533
502
534
fn find_tests ( dir : & Path ,
@@ -516,13 +548,15 @@ fn find_tests(dir: &Path,
516
548
}
517
549
}
518
550
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 )
524
556
}
557
+ }
525
558
559
+ fn android_copy_libs ( build : & Build , compiler : & Compiler , target : & str ) {
526
560
println ! ( "Android copy libs to emulator ({})" , target) ;
527
561
build. run ( Command :: new ( "adb" ) . arg ( "wait-for-device" ) ) ;
528
562
build. run ( Command :: new ( "adb" ) . arg ( "remount" ) ) ;
@@ -548,6 +582,39 @@ pub fn android_copy_libs(build: &Build,
548
582
}
549
583
}
550
584
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
+
551
618
/// Run "distcheck", a 'make check' from a tarball
552
619
pub fn distcheck ( build : & Build ) {
553
620
if build. config . build != "x86_64-unknown-linux-gnu" {
0 commit comments