Skip to content

Commit ff0ab6b

Browse files
committed
cargo: Use system-mode by default except "install"
I think it is confused that you need to "cargo init" and "cargo sync" every time to setup local-level .cargo
1 parent 2e63bc5 commit ff0ab6b

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

src/cargo/cargo.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -346,39 +346,35 @@ fn build_cargo_options(argv: [str]) -> options {
346346
};
347347

348348
let test = opt_present(match, "test");
349-
let mode = if opt_present(match, "G") {
350-
if opt_present(match, "mode") { fail "--mode and -G both provided"; }
351-
if opt_present(match, "g") { fail "-G and -g both provided"; }
352-
system_mode
353-
} else if opt_present(match, "g") {
354-
if opt_present(match, "mode") { fail "--mode and -g both provided"; }
355-
if opt_present(match, "G") { fail "-G and -g both provided"; }
356-
user_mode
357-
} else if opt_present(match, "mode") {
358-
alt getopts::opt_str(match, "mode") {
359-
"system" { system_mode }
360-
"user" { user_mode }
361-
"local" { local_mode }
362-
_ { fail "argument to `mode` must be one of `system`" +
363-
", `user`, or `normal`";
349+
let G = opt_present(match, "G");
350+
let g = opt_present(match, "g");
351+
let m = opt_present(match, "mode");
352+
let is_install = vec::len(match.free) > 1u && match.free[1] == "install";
353+
354+
if G && g { fail "-G and -g both provided"; }
355+
if g && m { fail "--mode and -g both provided"; }
356+
if G && m { fail "--mode and -G both provided"; }
357+
358+
let mode = if is_install {
359+
if G { system_mode }
360+
else if g { user_mode }
361+
else if m {
362+
alt getopts::opt_str(match, "mode") {
363+
"system" { system_mode }
364+
"user" { user_mode }
365+
"local" { local_mode }
366+
_ { fail "argument to `mode` must be one of `system`" +
367+
", `user`, or `local`";
368+
}
364369
}
365-
}
366-
} else {
367-
local_mode
368-
};
369-
370-
if mode == system_mode {
371-
// FIXME: Per discussion on #1760, we need to think about how
372-
// system mode works. It should install files to the normal
373-
// sysroot paths, but it also needsd an area to place various
374-
// cargo configuration and work files.
375-
fail "system mode does not exist yet";
376-
}
370+
} else { local_mode }
371+
} else { system_mode };
377372

378373
{test: test, mode: mode, free: match.free}
379374
}
380375

381376
fn configure(opts: options) -> cargo {
377+
let syscargo = result::get(get_cargo_sysroot());
382378
let get_cargo_dir = alt opts.mode {
383379
system_mode { get_cargo_sysroot }
384380
user_mode { get_cargo_root }
@@ -391,15 +387,15 @@ fn configure(opts: options) -> cargo {
391387
};
392388

393389
let sources = map::new_str_hash::<source>();
394-
try_parse_sources(fs::connect(p, "sources.json"), sources);
395-
try_parse_sources(fs::connect(p, "local-sources.json"), sources);
390+
try_parse_sources(fs::connect(syscargo, "sources.json"), sources);
391+
try_parse_sources(fs::connect(syscargo, "local-sources.json"), sources);
396392
let c = {
397393
pgp: pgp::supported(),
398394
root: p,
399395
bindir: fs::connect(p, "bin"),
400396
libdir: fs::connect(p, "lib"),
401397
workdir: fs::connect(p, "work"),
402-
sourcedir: fs::connect(p, "sources"),
398+
sourcedir: fs::connect(syscargo, "sources"),
403399
sources: sources,
404400
opts: opts
405401
};

0 commit comments

Comments
 (0)