@@ -61,12 +61,14 @@ type options = {
61
61
test : bool ,
62
62
mode : mode ,
63
63
free : [ str ] ,
64
+ help : bool ,
64
65
} ;
65
66
66
67
enum mode { system_mode, user_mode, local_mode }
67
68
68
69
fn opts ( ) -> [ getopts:: opt ] {
69
- [ optflag ( "g" ) , optflag ( "G" ) , optopt ( "mode" ) , optflag ( "test" ) ]
70
+ [ optflag ( "g" ) , optflag ( "G" ) , optopt ( "mode" ) , optflag ( "test" ) ,
71
+ optflag ( "h" ) , optflag ( "help" ) ]
70
72
}
71
73
72
74
fn info ( msg : str ) {
@@ -172,7 +174,7 @@ fn rest(s: str, start: uint) -> str {
172
174
173
175
fn need_dir( s: str ) {
174
176
if os:: path_is_dir( s) { ret; }
175
- if !os:: make_dir( s, 0x1c0i32 ) {
177
+ if !os:: make_dir( s, 493_i32 /* oct: 755 */ ) {
176
178
fail #fmt[ "can' t make_dir %s", s] ;
177
179
}
178
180
}
@@ -337,49 +339,55 @@ fn build_cargo_options(argv: [str]) -> options {
337
339
} ;
338
340
339
341
let test = opt_present( match , "test") ;
340
- let G = opt_present( match , "G ") ;
341
- let g = opt_present( match , "g") ;
342
- let m = opt_present( match , "mode") ;
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
+
343
347
let is_install = vec:: len( match . free) > 1 u && match . free[ 1 ] == "install";
344
348
345
349
if G && g { fail "-G and -g both provided"; }
346
350
if g && m { fail "--mode and -g both provided"; }
347
351
if G && m { fail "--mode and -G both provided"; }
348
352
349
- let mode = if is_install {
350
- if G { system_mode }
351
- else if g { user_mode }
352
- else if m {
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 {
353
362
alt getopts:: opt_str( match , "mode") {
354
363
"system" { system_mode }
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 } ;
364
+ "user" { user_mode }
365
+ "local" { local_mode }
366
+ _ { fail "argument to `mode` must be" +
367
+ "one of `system`, `user`, or `local`"; } }
368
+ } ;
363
369
364
- { test: test, mode: mode, free: match . free}
370
+ { test: test, mode: mode, free: match . free, help : help }
365
371
}
366
372
367
373
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
+
368
377
let syscargo = result:: get( get_cargo_sysroot( ) ) ;
378
+
369
379
let get_cargo_dir = alt opts. mode {
370
380
system_mode { get_cargo_sysroot }
371
381
user_mode { get_cargo_root }
372
382
local_mode { get_cargo_root_nearest }
373
383
} ;
374
384
375
- let p = alt get_cargo_dir( ) {
376
- result:: ok( p) { p }
377
- result:: err( e) { fail e }
378
- } ;
385
+ let p = result:: get( get_cargo_dir( ) ) ;
379
386
380
387
let sources = map:: str_hash:: <source>( ) ;
381
388
try_parse_sources( path:: connect( syscargo, "sources. json") , sources) ;
382
389
try_parse_sources( path:: connect( syscargo, "local-sources. json") , sources) ;
390
+
383
391
let mut c = {
384
392
pgp: pgp:: supported( ) ,
385
393
root: p,
@@ -467,17 +475,20 @@ fn install_one_crate(c: cargo, path: str, cf: str) {
467
475
let newv = os:: list_dir_path( buildpath) ;
468
476
let exec_suffix = os:: exe_suffix( ) ;
469
477
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
+
470
481
if ( exec_suffix != "" && str :: ends_with( ct, exec_suffix) ) ||
471
482
( exec_suffix == "" && !str :: starts_with( path:: basename( ct) ,
472
483
"lib") ) {
473
484
#debug( " bin: %s", ct) ;
474
- copy_warn ( ct, c. bindir) ;
485
+ install_to_dir ( ct, c. bindir) ;
475
486
if c. opts. mode == system_mode {
476
487
install_one_crate_to_sysroot( ct, "bin") ;
477
488
}
478
489
} else {
479
490
#debug( " lib: %s", ct) ;
480
- copy_warn ( ct, c. bindir ) ;
491
+ install_to_dir ( ct, c. libdir ) ;
481
492
if c. opts. mode == system_mode {
482
493
install_one_crate_to_sysroot( ct, libdir( ) ) ;
483
494
}
@@ -491,7 +502,7 @@ fn install_one_crate_to_sysroot(ct: str, target: str) {
491
502
let path = [ _path, "..", target] ;
492
503
check vec:: is_not_empty( path) ;
493
504
let target_dir = path:: normalize( path:: connect_many( path) ) ;
494
- copy_warn ( ct, target_dir) ;
505
+ install_to_dir ( ct, target_dir) ;
495
506
}
496
507
none { }
497
508
}
@@ -684,9 +695,10 @@ fn cmd_install(c: cargo) unsafe {
684
695
685
696
let target = c. opts. free[ 2 ] ;
686
697
687
- let wd = alt tempfile:: mkdtemp( c. workdir + path:: path_sep( ) , "") {
698
+ let wd_base = c. workdir + path:: path_sep( ) ;
699
+ let wd = alt tempfile:: mkdtemp( wd_base, "") {
688
700
some( _wd) { _wd }
689
- none { fail "needed temp dir" ; }
701
+ none { fail #fmt ( "needed temp dir: %s" , wd_base ) ; }
690
702
} ;
691
703
692
704
if str :: starts_with( target, "uuid: ") {
@@ -802,9 +814,9 @@ fn cmd_init(c: cargo) {
802
814
803
815
let r = pgp:: verify( c. root, srcfile, sigfile, pgp:: signing_key_fp( ) ) ;
804
816
if !r {
805
- warn( #fmt[ "signature verification failed for sources . json" ] ) ;
817
+ warn( #fmt[ "signature verification failed for ' %s ' " , srcfile ] ) ;
806
818
} else {
807
- info( #fmt[ "signature ok for sources . json" ] ) ;
819
+ info( #fmt[ "signature ok for ' %s ' " , srcfile ] ) ;
808
820
}
809
821
copy_warn( srcfile, destsrcfile) ;
810
822
@@ -847,44 +859,56 @@ fn cmd_search(c: cargo) {
847
859
info( #fmt[ "Found %d packages. ", n] ) ;
848
860
}
849
861
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] ) ;
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] ) ;
853
872
}
854
873
}
855
874
875
+ // FIXME: decide on either [-g | -G] or [--mode=...] and remove the other
856
876
fn cmd_usage( ) {
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.
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
881
905
") ;
882
906
}
883
907
884
908
fn main( argv: [ str ] ) {
885
909
let o = build_cargo_options( argv) ;
886
910
887
- if vec:: len( o. free) < 2 u {
911
+ if vec:: len( o. free) < 2 u || o . help {
888
912
cmd_usage( ) ;
889
913
ret;
890
914
}
0 commit comments