@@ -23,6 +23,9 @@ use build_helper::output;
23
23
use bootstrap:: { dylib_path, dylib_path_var} ;
24
24
25
25
use build:: { Build , Compiler , Mode } ;
26
+ use build:: util;
27
+
28
+ const ADB_TEST_DIR : & ' static str = "/data/tmp" ;
26
29
27
30
/// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
28
31
///
@@ -88,6 +91,7 @@ pub fn compiletest(build: &Build,
88
91
target : & str ,
89
92
mode : & str ,
90
93
suite : & str ) {
94
+ println ! ( "Check compiletest {} ({} -> {})" , suite, compiler. host, target) ;
91
95
let mut cmd = build. tool_cmd ( compiler, "compiletest" ) ;
92
96
93
97
// compiletest currently has... a lot of arguments, so let's just pass all
@@ -105,21 +109,23 @@ pub fn compiletest(build: &Build,
105
109
cmd. arg ( "--host" ) . arg ( compiler. host ) ;
106
110
cmd. arg ( "--llvm-filecheck" ) . arg ( build. llvm_filecheck ( & build. config . build ) ) ;
107
111
108
- let mut flags = format ! ( "-Crpath" ) ;
112
+ let mut flags = vec ! [ "-Crpath" . to_string ( ) ] ;
109
113
if build. config . rust_optimize_tests {
110
- flags. push_str ( " -O") ;
114
+ flags. push ( " -O". to_string ( ) ) ;
111
115
}
112
116
if build. config . rust_debuginfo_tests {
113
- flags. push_str ( " -g") ;
117
+ flags. push ( " -g". to_string ( ) ) ;
114
118
}
115
119
116
- cmd. arg ( "--host-rustcflags" ) . arg ( & flags) ;
117
-
118
- let linkflag = format ! ( "-Lnative={}" , build. test_helpers_out( target) . display( ) ) ;
119
- cmd. arg ( "--target-rustcflags" ) . arg ( format ! ( "{} {}" , flags, linkflag) ) ;
120
+ let mut hostflags = build. rustc_flags ( & compiler. host ) ;
121
+ hostflags. extend ( flags. clone ( ) ) ;
122
+ cmd. arg ( "--host-rustcflags" ) . arg ( hostflags. join ( " " ) ) ;
120
123
121
- // FIXME: needs android support
122
- cmd. arg ( "--android-cross-path" ) . arg ( "" ) ;
124
+ let mut targetflags = build. rustc_flags ( & target) ;
125
+ targetflags. extend ( flags) ;
126
+ targetflags. push ( format ! ( "-Lnative={}" ,
127
+ build. test_helpers_out( target) . display( ) ) ) ;
128
+ cmd. arg ( "--target-rustcflags" ) . arg ( targetflags. join ( " " ) ) ;
123
129
124
130
// FIXME: CFG_PYTHON should probably be detected more robustly elsewhere
125
131
let python_default = "python" ;
@@ -180,6 +186,16 @@ pub fn compiletest(build: &Build,
180
186
}
181
187
build. add_bootstrap_key ( compiler, & mut cmd) ;
182
188
189
+ cmd. arg ( "--adb-path" ) . arg ( "adb" ) ;
190
+ cmd. arg ( "--adb-test-dir" ) . arg ( ADB_TEST_DIR ) ;
191
+ if target. contains ( "android" ) {
192
+ // Assume that cc for this target comes from the android sysroot
193
+ cmd. arg ( "--android-cross-path" )
194
+ . arg ( build. cc ( target) . parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) ) ;
195
+ } else {
196
+ cmd. arg ( "--android-cross-path" ) . arg ( "" ) ;
197
+ }
198
+
183
199
build. run ( & mut cmd) ;
184
200
}
185
201
@@ -302,7 +318,97 @@ pub fn krate(build: &Build,
302
318
let mut dylib_path = dylib_path ( ) ;
303
319
dylib_path. insert ( 0 , build. sysroot_libdir ( compiler, target) ) ;
304
320
cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
305
- cargo. args ( & build. flags . args ) ;
306
321
307
- build. run ( & mut cargo) ;
322
+ if target. contains ( "android" ) {
323
+ build. run ( cargo. arg ( "--no-run" ) ) ;
324
+ krate_android ( build, compiler, target, mode) ;
325
+ } else {
326
+ cargo. args ( & build. flags . args ) ;
327
+ build. run ( & mut cargo) ;
328
+ }
329
+ }
330
+
331
+ fn krate_android ( build : & Build ,
332
+ compiler : & Compiler ,
333
+ target : & str ,
334
+ mode : Mode ) {
335
+ let mut tests = Vec :: new ( ) ;
336
+ let out_dir = build. cargo_out ( compiler, mode, target) ;
337
+ find_tests ( & out_dir, target, & mut tests) ;
338
+ find_tests ( & out_dir. join ( "deps" ) , target, & mut tests) ;
339
+
340
+ for test in tests {
341
+ build. run ( Command :: new ( "adb" ) . arg ( "push" ) . arg ( & test) . arg ( ADB_TEST_DIR ) ) ;
342
+
343
+ let test_file_name = test. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
344
+ let log = format ! ( "{}/check-stage{}-T-{}-H-{}-{}.log" ,
345
+ ADB_TEST_DIR ,
346
+ compiler. stage,
347
+ target,
348
+ compiler. host,
349
+ test_file_name) ;
350
+ let program = format ! ( "(cd {dir}; \
351
+ LD_LIBRARY_PATH=./{target} ./{test} \
352
+ --logfile {log} \
353
+ {args})",
354
+ dir = ADB_TEST_DIR ,
355
+ target = target,
356
+ test = test_file_name,
357
+ log = log,
358
+ args = build. flags. args. join( " " ) ) ;
359
+
360
+ let output = output ( Command :: new ( "adb" ) . arg ( "shell" ) . arg ( & program) ) ;
361
+ println ! ( "{}" , output) ;
362
+ build. run ( Command :: new ( "adb" )
363
+ . arg ( "pull" )
364
+ . arg ( & log)
365
+ . arg ( build. out . join ( "tmp" ) ) ) ;
366
+ build. run ( Command :: new ( "adb" ) . arg ( "shell" ) . arg ( "rm" ) . arg ( & log) ) ;
367
+ if !output. contains ( "result: ok" ) {
368
+ panic ! ( "some tests failed" ) ;
369
+ }
370
+ }
371
+ }
372
+
373
+ fn find_tests ( dir : & Path ,
374
+ target : & str ,
375
+ dst : & mut Vec < PathBuf > ) {
376
+ for e in t ! ( dir. read_dir( ) ) . map ( |e| t ! ( e) ) {
377
+ let file_type = t ! ( e. file_type( ) ) ;
378
+ if !file_type. is_file ( ) {
379
+ continue
380
+ }
381
+ let filename = e. file_name ( ) . into_string ( ) . unwrap ( ) ;
382
+ if ( target. contains ( "windows" ) && filename. ends_with ( ".exe" ) ) ||
383
+ ( !target. contains ( "windows" ) && !filename. contains ( "." ) ) {
384
+ dst. push ( e. path ( ) ) ;
385
+ }
386
+ }
387
+ }
388
+
389
+ pub fn android_copy_libs ( build : & Build ,
390
+ compiler : & Compiler ,
391
+ target : & str ) {
392
+ println ! ( "Android copy libs to emulator ({})" , target) ;
393
+ build. run ( Command :: new ( "adb" ) . arg ( "remount" ) ) ;
394
+ build. run ( Command :: new ( "adb" ) . args ( & [ "shell" , "rm" , "-r" , ADB_TEST_DIR ] ) ) ;
395
+ build. run ( Command :: new ( "adb" ) . args ( & [ "shell" , "mkdir" , ADB_TEST_DIR ] ) ) ;
396
+ build. run ( Command :: new ( "adb" )
397
+ . arg ( "push" )
398
+ . arg ( build. src . join ( "src/etc/adb_run_wrapper.sh" ) )
399
+ . arg ( ADB_TEST_DIR ) ) ;
400
+
401
+ let target_dir = format ! ( "{}/{}" , ADB_TEST_DIR , target) ;
402
+ build. run ( Command :: new ( "adb" ) . args ( & [ "shell" , "mkdir" , & target_dir[ ..] ] ) ) ;
403
+
404
+ for f in t ! ( build. sysroot_libdir( compiler, target) . read_dir( ) ) {
405
+ let f = t ! ( f) ;
406
+ let name = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
407
+ if util:: is_dylib ( & name) {
408
+ build. run ( Command :: new ( "adb" )
409
+ . arg ( "push" )
410
+ . arg ( f. path ( ) )
411
+ . arg ( & target_dir) ) ;
412
+ }
413
+ }
308
414
}
0 commit comments