@@ -61,14 +61,12 @@ type options = {
61
61
test : bool ,
62
62
mode : mode ,
63
63
free : [ str ] ,
64
- help : bool ,
65
64
} ;
66
65
67
66
enum mode { system_mode, user_mode, local_mode }
68
67
69
68
fn opts ( ) -> [ getopts:: opt ] {
70
- [ optflag ( "g" ) , optflag ( "G" ) , optopt ( "mode" ) , optflag ( "test" ) ,
71
- optflag ( "h" ) , optflag ( "help" ) ]
69
+ [ optflag ( "g" ) , optflag ( "G" ) , optopt ( "mode" ) , optflag ( "test" ) ]
72
70
}
73
71
74
72
fn info ( msg : str ) {
@@ -174,7 +172,7 @@ fn rest(s: str, start: uint) -> str {
174
172
175
173
fn need_dir( s: str ) {
176
174
if os:: path_is_dir( s) { ret; }
177
- if !os:: make_dir( s, 493_i32 /* oct: 755 */ ) {
175
+ if !os:: make_dir( s, 0x1c0i32 ) {
178
176
fail #fmt[ "can' t make_dir %s", s] ;
179
177
}
180
178
}
@@ -339,55 +337,49 @@ fn build_cargo_options(argv: [str]) -> options {
339
337
} ;
340
338
341
339
let test = opt_present( match , "test") ;
342
- let G = opt_present( match , "G ") ;
343
- let g = opt_present( match , "g") ;
344
- let m = opt_present( match , "mode") ;
345
- let help = opt_present( match , "h") || opt_present( match , "help") ;
346
-
340
+ let G = opt_present( match , "G ") ;
341
+ let g = opt_present( match , "g") ;
342
+ let m = opt_present( match , "mode") ;
347
343
let is_install = vec:: len( match . free) > 1 u && match . free[ 1 ] == "install";
348
344
349
345
if G && g { fail "-G and -g both provided"; }
350
346
if g && m { fail "--mode and -g both provided"; }
351
347
if G && m { fail "--mode and -G both provided"; }
352
348
353
- if !is_install && ( g || G || m) {
354
- fail "-g, -G , --mode are only valid for `install`";
355
- }
356
-
357
- let mode =
358
- if !is_install || G { system_mode }
359
- else if g { user_mode }
360
- else if !m { local_mode }
361
- else {
349
+ let mode = if is_install {
350
+ if G { system_mode }
351
+ else if g { user_mode }
352
+ else if m {
362
353
alt getopts:: opt_str( match , "mode") {
363
354
"system" { system_mode }
364
- "user" { user_mode }
365
- "local" { local_mode }
366
- _ { fail "argument to `mode` must be" +
367
- "one of `system`, `user`, or `local`"; } }
368
- } ;
355
+ "user" { user_mode }
356
+ "local" { local_mode }
357
+ _ { fail "argument to `mode` must be one of `system`" +
358
+ ", `user`, or `local`";
359
+ }
360
+ }
361
+ } else { local_mode }
362
+ } else { system_mode } ;
369
363
370
- { test: test, mode: mode, free: match . free, help : help }
364
+ { test: test, mode: mode, free: match . free}
371
365
}
372
366
373
367
fn configure( opts: options) -> cargo {
374
- // NOTE: to make init and sync save into non-root level directories
375
- // simply get rid of syscargo, below
376
-
377
368
let syscargo = result:: get( get_cargo_sysroot( ) ) ;
378
-
379
369
let get_cargo_dir = alt opts. mode {
380
370
system_mode { get_cargo_sysroot }
381
371
user_mode { get_cargo_root }
382
372
local_mode { get_cargo_root_nearest }
383
373
} ;
384
374
385
- let p = result:: get( get_cargo_dir( ) ) ;
375
+ let p = alt get_cargo_dir( ) {
376
+ result:: ok( p) { p }
377
+ result:: err( e) { fail e }
378
+ } ;
386
379
387
380
let sources = map:: str_hash:: <source>( ) ;
388
381
try_parse_sources( path:: connect( syscargo, "sources. json") , sources) ;
389
382
try_parse_sources( path:: connect( syscargo, "local-sources. json") , sources) ;
390
-
391
383
let mut c = {
392
384
pgp: pgp:: supported( ) ,
393
385
root: p,
@@ -475,20 +467,17 @@ fn install_one_crate(c: cargo, path: str, cf: str) {
475
467
let newv = os:: list_dir_path( buildpath) ;
476
468
let exec_suffix = os:: exe_suffix( ) ;
477
469
for newv. each { |ct|
478
- // FIXME: What's up with the dual installation? Both `install_to_dir`
479
- // and `install_one_crate_to_sysroot` install the binary files...
480
-
481
470
if ( exec_suffix != "" && str :: ends_with( ct, exec_suffix) ) ||
482
471
( exec_suffix == "" && !str :: starts_with( path:: basename( ct) ,
483
472
"lib") ) {
484
473
#debug( " bin: %s", ct) ;
485
- install_to_dir ( ct, c. bindir) ;
474
+ copy_warn ( ct, c. bindir) ;
486
475
if c. opts. mode == system_mode {
487
476
install_one_crate_to_sysroot( ct, "bin") ;
488
477
}
489
478
} else {
490
479
#debug( " lib: %s", ct) ;
491
- install_to_dir ( ct, c. bindir) ;
480
+ copy_warn ( ct, c. bindir) ;
492
481
if c. opts. mode == system_mode {
493
482
install_one_crate_to_sysroot( ct, libdir( ) ) ;
494
483
}
@@ -502,7 +491,7 @@ fn install_one_crate_to_sysroot(ct: str, target: str) {
502
491
let path = [ _path, "..", target] ;
503
492
check vec:: is_not_empty( path) ;
504
493
let target_dir = path:: normalize( path:: connect_many( path) ) ;
505
- install_to_dir ( ct, target_dir) ;
494
+ copy_warn ( ct, target_dir) ;
506
495
}
507
496
none { }
508
497
}
@@ -695,10 +684,9 @@ fn cmd_install(c: cargo) unsafe {
695
684
696
685
let target = c. opts. free[ 2 ] ;
697
686
698
- let wd_base = c. workdir + path:: path_sep( ) ;
699
- let wd = alt tempfile:: mkdtemp( wd_base, "") {
687
+ let wd = alt tempfile:: mkdtemp( c. workdir + path:: path_sep( ) , "") {
700
688
some( _wd) { _wd }
701
- none { fail #fmt ( "needed temp dir: %s" , wd_base ) ; }
689
+ none { fail "needed temp dir" ; }
702
690
} ;
703
691
704
692
if str :: starts_with( target, "uuid: ") {
@@ -814,9 +802,9 @@ fn cmd_init(c: cargo) {
814
802
815
803
let r = pgp:: verify( c. root, srcfile, sigfile, pgp:: signing_key_fp( ) ) ;
816
804
if !r {
817
- warn( #fmt[ "signature verification failed for ' %s ' " , srcfile ] ) ;
805
+ warn( #fmt[ "signature verification failed for sources . json" ] ) ;
818
806
} else {
819
- info( #fmt[ "signature ok for ' %s ' " , srcfile ] ) ;
807
+ info( #fmt[ "signature ok for sources . json" ] ) ;
820
808
}
821
809
copy_warn( srcfile, destsrcfile) ;
822
810
@@ -859,56 +847,44 @@ fn cmd_search(c: cargo) {
859
847
info( #fmt[ "Found %d packages. ", n] ) ;
860
848
}
861
849
862
- fn install_to_dir( srcfile: str , destdir: str ) {
863
- let newfile = path:: connect( destdir, path:: basename( srcfile) ) ;
864
- info( #fmt[ "Installing ' %s' ...", newfile] ) ;
865
-
866
- run:: run_program( "cp", [ srcfile, newfile] ) ;
867
- }
868
-
869
- fn copy_warn( srcfile: str , destfile: str ) {
870
- if !os:: copy_file( srcfile, destfile) {
871
- warn( #fmt[ "Copying %s to %s failed", srcfile, destfile] ) ;
850
+ fn copy_warn( src: str , dest: str ) {
851
+ if !os:: copy_file( src, dest) {
852
+ warn( #fmt[ "Copying %s to %s failed", src, dest] ) ;
872
853
}
873
854
}
874
855
875
- // FIXME: decide on either [-g | -G] or [--mode=...] and remove the other
876
856
fn cmd_usage( ) {
877
- print( "Usage : cargo <verb> [ options] [ args...] \n " +
878
- " e. g. : cargo [ init | sync] \n " +
879
- " e. g. : cargo install [ -g | -G | --mode=MODE ] ] [ PACKAGE ...]
880
-
881
- Initialization :
882
- init Set up the cargo system near this binary,
883
- for example, at /usr/local/lib/cargo/
884
- sync Sync all package sources
885
-
886
- Querying :
887
- list [ source] List packages
888
- search <name | '*' > [ tags...] Search packages
889
- usage Display this message
890
-
891
- Package installation:
892
- [ options] [ source/] PKGNAME Install a package by name
893
- [ options] uuid: [ source/] PKGUUID Install a package by uuid
894
-
895
- Package installation options:
896
- --mode=MODE Install to one of the following locations:
897
- local ( . /. cargo/bin/, which is the default ) ,
898
- user ( ~/. cargo/bin/) , or system ( /usr/local/lib/cargo/bin/)
899
- --test Run crate tests before installing
900
- -g Equivalent to --mode=user
901
- -G Equivalent to --mode=system
902
-
903
- Other :
904
- -h, --help Display this message
857
+ print( "Usage : cargo <verb> [ options] [ args...] " +
858
+ "
859
+
860
+ init Set up . cargo
861
+ install [ options] [ source/] package-name Install by name
862
+ install [ options] uuid: [ source/] package-uuid Install by uuid
863
+ list [ source] List packages
864
+ search <name | '*' > [ tags...] Search packages
865
+ sync Sync all sources
866
+ usage This
867
+
868
+ Options :
869
+
870
+ cargo install
871
+
872
+ --mode=[ system, user, local] change mode as ( system/user/local)
873
+ --test run crate tests before installing
874
+ -g equivalent to --mode=user
875
+ -G equivalent to --mode=system
876
+
877
+ NOTE :
878
+ \"cargo install\" installs bin/libs to local-level . cargo by default .
879
+ To install them into user-level . cargo, use option -g/--mode=user.
880
+ To install them into bin/lib on sysroot, use option -G /--mode=system.
905
881
") ;
906
882
}
907
883
908
884
fn main( argv: [ str ] ) {
909
885
let o = build_cargo_options( argv) ;
910
886
911
- if vec:: len( o. free) < 2 u || o . help {
887
+ if vec:: len( o. free) < 2 u {
912
888
cmd_usage( ) ;
913
889
ret;
914
890
}
0 commit comments