Skip to content

Commit fbea4fb

Browse files
committed
---
yaml --- r: 13070 b: refs/heads/master c: 360194d h: refs/heads/master v: v3
1 parent 8fe38a4 commit fbea4fb

File tree

3 files changed

+68
-82
lines changed

3 files changed

+68
-82
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 1aa080463766da23d6c24366b258df251f55b39e
2+
refs/heads/master: 360194d282e1d819f45347f923dbe3e6ba2c815e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/cargo/cargo.rs

Lines changed: 57 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ type options = {
6161
test: bool,
6262
mode: mode,
6363
free: [str],
64-
help: bool,
6564
};
6665

6766
enum mode { system_mode, user_mode, local_mode }
6867

6968
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")]
7270
}
7371

7472
fn info(msg: str) {
@@ -174,7 +172,7 @@ fn rest(s: str, start: uint) -> str {
174172

175173
fn need_dir(s: str) {
176174
if os::path_is_dir(s) { ret; }
177-
if !os::make_dir(s, 493_i32 /* oct: 755 */) {
175+
if !os::make_dir(s, 0x1c0i32) {
178176
fail #fmt["can't make_dir %s", s];
179177
}
180178
}
@@ -339,55 +337,49 @@ fn build_cargo_options(argv: [str]) -> options {
339337
};
340338

341339
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");
347343
let is_install = vec::len(match.free) > 1u && match.free[1] == "install";
348344

349345
if G && g { fail "-G and -g both provided"; }
350346
if g && m { fail "--mode and -g both provided"; }
351347
if G && m { fail "--mode and -G both provided"; }
352348

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 {
362353
alt getopts::opt_str(match, "mode") {
363354
"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 };
369363

370-
{test: test, mode: mode, free: match.free, help: help}
364+
{test: test, mode: mode, free: match.free}
371365
}
372366

373367
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-
377368
let syscargo = result::get(get_cargo_sysroot());
378-
379369
let get_cargo_dir = alt opts.mode {
380370
system_mode { get_cargo_sysroot }
381371
user_mode { get_cargo_root }
382372
local_mode { get_cargo_root_nearest }
383373
};
384374

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+
};
386379

387380
let sources = map::str_hash::<source>();
388381
try_parse_sources(path::connect(syscargo, "sources.json"), sources);
389382
try_parse_sources(path::connect(syscargo, "local-sources.json"), sources);
390-
391383
let mut c = {
392384
pgp: pgp::supported(),
393385
root: p,
@@ -475,20 +467,17 @@ fn install_one_crate(c: cargo, path: str, cf: str) {
475467
let newv = os::list_dir_path(buildpath);
476468
let exec_suffix = os::exe_suffix();
477469
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-
481470
if (exec_suffix != "" && str::ends_with(ct, exec_suffix)) ||
482471
(exec_suffix == "" && !str::starts_with(path::basename(ct),
483472
"lib")) {
484473
#debug(" bin: %s", ct);
485-
install_to_dir(ct, c.bindir);
474+
copy_warn(ct, c.bindir);
486475
if c.opts.mode == system_mode {
487476
install_one_crate_to_sysroot(ct, "bin");
488477
}
489478
} else {
490479
#debug(" lib: %s", ct);
491-
install_to_dir(ct, c.bindir);
480+
copy_warn(ct, c.bindir);
492481
if c.opts.mode == system_mode {
493482
install_one_crate_to_sysroot(ct, libdir());
494483
}
@@ -502,7 +491,7 @@ fn install_one_crate_to_sysroot(ct: str, target: str) {
502491
let path = [_path, "..", target];
503492
check vec::is_not_empty(path);
504493
let target_dir = path::normalize(path::connect_many(path));
505-
install_to_dir(ct, target_dir);
494+
copy_warn(ct, target_dir);
506495
}
507496
none { }
508497
}
@@ -695,10 +684,9 @@ fn cmd_install(c: cargo) unsafe {
695684

696685
let target = c.opts.free[2];
697686

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(), "") {
700688
some(_wd) { _wd }
701-
none { fail #fmt("needed temp dir: %s", wd_base); }
689+
none { fail "needed temp dir"; }
702690
};
703691

704692
if str::starts_with(target, "uuid:") {
@@ -814,9 +802,9 @@ fn cmd_init(c: cargo) {
814802

815803
let r = pgp::verify(c.root, srcfile, sigfile, pgp::signing_key_fp());
816804
if !r {
817-
warn(#fmt["signature verification failed for '%s'", srcfile]);
805+
warn(#fmt["signature verification failed for sources.json"]);
818806
} else {
819-
info(#fmt["signature ok for '%s'", srcfile]);
807+
info(#fmt["signature ok for sources.json"]);
820808
}
821809
copy_warn(srcfile, destsrcfile);
822810

@@ -859,56 +847,44 @@ fn cmd_search(c: cargo) {
859847
info(#fmt["Found %d packages.", n]);
860848
}
861849

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]);
872853
}
873854
}
874855

875-
// FIXME: decide on either [-g | -G] or [--mode=...] and remove the other
876856
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.
905881
");
906882
}
907883

908884
fn main(argv: [str]) {
909885
let o = build_cargo_options(argv);
910886

911-
if vec::len(o.free) < 2u || o.help {
887+
if vec::len(o.free) < 2u {
912888
cmd_usage();
913889
ret;
914890
}

trunk/src/libstd/bitv.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ fn each(v: bitv, f: fn(bool) -> bool) {
197197
let mut i = 0u;
198198
while i < v.nbits {
199199
if !f(get(v, i)) { break; }
200+
i = i + 1u;
200201
}
201202
}
202203

@@ -233,6 +234,15 @@ fn eq_vec(v0: bitv, v1: [uint]) -> bool {
233234

234235
#[cfg(test)]
235236
mod tests {
237+
#[test]
238+
fn test_to_str() {
239+
let zerolen = bitv(0u, false);
240+
assert to_str(zerolen) == "";
241+
242+
let eightbits = bitv(8u, false);
243+
assert to_str(eightbits) == "00000000";
244+
}
245+
236246
#[test]
237247
fn test_0_elements() {
238248
let mut act;

0 commit comments

Comments
 (0)