@@ -54,7 +54,8 @@ type cargo = {
54
54
libdir : str ,
55
55
workdir : str ,
56
56
sourcedir : str ,
57
- sources : map:: hashmap < str , source >
57
+ sources : map:: hashmap < str , source > ,
58
+ mutable test: bool
58
59
} ;
59
60
60
61
type pkg = {
@@ -67,7 +68,7 @@ type pkg = {
67
68
} ;
68
69
69
70
fn info ( msg : str ) {
70
- io:: stdout ( ) . write_line ( msg) ;
71
+ io:: stdout ( ) . write_line ( "info: " + msg) ;
71
72
}
72
73
73
74
fn warn ( msg : str ) {
@@ -323,7 +324,8 @@ fn configure() -> cargo {
323
324
libdir: fs:: connect ( p, "lib" ) ,
324
325
workdir: fs:: connect ( p, "work" ) ,
325
326
sourcedir: fs:: connect ( p, "sources" ) ,
326
- sources: sources
327
+ sources: sources,
328
+ mutable test: false
327
329
} ;
328
330
329
331
need_dir ( c. root ) ;
@@ -353,15 +355,16 @@ fn for_each_package(c: cargo, b: block(source, package)) {
353
355
} )
354
356
}
355
357
356
- fn install_one_crate ( c : cargo , _path : str , cf : str , _p : pkg ) {
358
+ // FIXME: deduplicate code with install_one_crate
359
+ fn test_one_crate ( c : cargo , _path : str , cf : str , _p : pkg ) {
357
360
let name = fs:: basename ( cf) ;
358
361
let ri = str:: index ( name, '.' as u8 ) ;
359
362
if ri != -1 {
360
363
name = str:: slice ( name, 0 u, ri as uint ) ;
361
364
}
362
365
#debug ( "Installing: %s" , name) ;
363
366
let old = fs:: list_dir ( "." ) ;
364
- let p = run:: program_output ( "rustc" , [ name + ".rc" ] ) ;
367
+ let p = run:: program_output ( "rustc" , [ "--test" , name + ".rc" ] ) ;
365
368
if p. status != 0 {
366
369
error ( #fmt[ "rustc failed: %d\n %s\n %s" , p. status , p. err , p. out ] ) ;
367
370
ret;
@@ -371,6 +374,26 @@ fn install_one_crate(c: cargo, _path: str, cf: str, _p: pkg) {
371
374
vec:: filter :: < str > ( new, { |n| !vec:: member :: < str > ( n, old) } ) ;
372
375
let exec_suffix = os:: exec_suffix ( ) ;
373
376
for ct: str in created {
377
+ if ( exec_suffix != "" && str:: ends_with ( ct, exec_suffix) ) ||
378
+ ( exec_suffix == "" && !str:: starts_with ( ct, "./lib" ) ) {
379
+ // FIXME: need libstd fs::copy or something
380
+ run:: run_program ( ct, [ ] ) ;
381
+ }
382
+ }
383
+ }
384
+
385
+ fn install_one_crate ( c : cargo , _path : str , cf : str , _p : pkg ) {
386
+ let buildpath = fs:: connect ( _path, "/build" ) ;
387
+ need_dir ( buildpath) ;
388
+ #debug ( "Installing: %s -> %s" , cf, buildpath) ;
389
+ let p = run:: program_output ( "rustc" , [ "--out-dir" , buildpath, cf] ) ;
390
+ if p. status != 0 {
391
+ error ( #fmt[ "rustc failed: %d\n %s\n %s" , p. status , p. err , p. out ] ) ;
392
+ ret;
393
+ }
394
+ let new = fs:: list_dir ( buildpath) ;
395
+ let exec_suffix = os:: exec_suffix ( ) ;
396
+ for ct: str in new {
374
397
if ( exec_suffix != "" && str:: ends_with ( ct, exec_suffix) ) ||
375
398
( exec_suffix == "" && !str:: starts_with ( ct, "./lib" ) ) {
376
399
#debug ( " bin: %s" , ct) ;
@@ -402,6 +425,9 @@ fn install_source(c: cargo, path: str) {
402
425
alt p {
403
426
none. { cont; }
404
427
some ( _p) {
428
+ if c. test {
429
+ test_one_crate ( c, path, cf, _p) ;
430
+ }
405
431
install_one_crate ( c, path, cf, _p) ;
406
432
}
407
433
}
@@ -530,13 +556,20 @@ fn cmd_install(c: cargo, argv: [str]) {
530
556
ret;
531
557
}
532
558
559
+ let target = argv[ 2 ] ;
560
+ // TODO: getopts
561
+ if vec:: len ( argv) > 3 u && argv[ 2 ] == "--test" {
562
+ c. test = true ;
563
+ target = argv[ 3 ] ;
564
+ }
565
+
533
566
let wd = alt tempfile:: mkdtemp ( c. workdir + fs:: path_sep ( ) , "" ) {
534
567
some ( _wd) { _wd }
535
568
none. { fail "needed temp dir" ; }
536
569
} ;
537
570
538
- if str:: starts_with ( argv [ 2 ] , "uuid:" ) {
539
- let uuid = rest ( argv [ 2 ] , 5 u) ;
571
+ if str:: starts_with ( target , "uuid:" ) {
572
+ let uuid = rest ( target , 5 u) ;
540
573
let idx = str:: index ( uuid, '/' as u8 ) ;
541
574
if idx != -1 {
542
575
let source = str:: slice ( uuid, 0 u, idx as uint ) ;
@@ -546,7 +579,7 @@ fn cmd_install(c: cargo, argv: [str]) {
546
579
install_uuid ( c, wd, uuid) ;
547
580
}
548
581
} else {
549
- let name = argv [ 2 ] ;
582
+ let name = target ;
550
583
let idx = str:: index ( name, '/' as u8 ) ;
551
584
if idx != -1 {
552
585
let source = str:: slice ( name, 0 u, idx as uint ) ;
@@ -686,13 +719,13 @@ fn cmd_search(c: cargo, argv: [str]) {
686
719
687
720
fn cmd_usage ( ) {
688
721
print ( "Usage: cargo <verb> [args...]" ) ;
689
- print ( " init Fetch default sources" ) ;
690
- print ( " install [source/]package-name Install by name" ) ;
691
- print ( " install uuid:[source/]package-uuid Install by uuid" ) ;
692
- print ( " list [source] List packages" ) ;
693
- print ( " search <name | '*'> [tags...] Search packages" ) ;
694
- print ( " sync Sync all sources" ) ;
695
- print ( " usage This" ) ;
722
+ print ( " init Fetch default sources" ) ;
723
+ print ( " install [--test] [ source/]package-name Install by name" ) ;
724
+ print ( " install [--test] uuid:[source/]package-uuid Install by uuid" ) ;
725
+ print ( " list [source] List packages" ) ;
726
+ print ( " search <name | '*'> [tags...] Search packages" ) ;
727
+ print ( " sync Sync all sources" ) ;
728
+ print ( " usage This" ) ;
696
729
}
697
730
698
731
fn main ( argv : [ str ] ) {
0 commit comments