From 2e63bc5d8293d38cb3be7cb07d6267c9db385062 Mon Sep 17 00:00:00 2001 From: Tycho Sci Date: Mon, 20 Feb 2012 14:49:22 +0900 Subject: [PATCH 1/3] cargo: Use $sysroot/$libdir/cargo as work dir On win32 environment, it's "$sysroot/bin/cargo". On unix-y environment, it's "$sysroot/lib/cargo". --- src/comp/util/filesearch.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/comp/util/filesearch.rs b/src/comp/util/filesearch.rs index 82859ce22f1..d5919ea3e5a 100644 --- a/src/comp/util/filesearch.rs +++ b/src/comp/util/filesearch.rs @@ -48,8 +48,6 @@ fn mk_filesearch(maybe_sysroot: option, result::ok(p) { [p] } result::err(p) { [] } } - + [fs::connect(fs::connect(self.sysroot, ".cargo"), - libdir())] } fn get_target_lib_path() -> fs::path { make_target_lib_path(self.sysroot, self.target_triple) @@ -113,7 +111,9 @@ fn get_sysroot(maybe_sysroot: option) -> fs::path { } fn get_cargo_sysroot() -> result::t { - result::ok(fs::connect(get_default_sysroot(), ".cargo")) + let path = [get_default_sysroot(), libdir(), "cargo"]; + check vec::is_not_empty(path); + result::ok(fs::connect_many(path)) } fn get_cargo_root() -> result::t { From ff0ab6b7ee70fb39fe11069ead3e7ef62e92fe9e Mon Sep 17 00:00:00 2001 From: Tycho Sci Date: Mon, 20 Feb 2012 17:08:58 +0900 Subject: [PATCH 2/3] 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 --- src/cargo/cargo.rs | 56 +++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 820b8f113e4..1d95c929b17 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -346,39 +346,35 @@ fn build_cargo_options(argv: [str]) -> options { }; let test = opt_present(match, "test"); - let mode = if opt_present(match, "G") { - if opt_present(match, "mode") { fail "--mode and -G both provided"; } - if opt_present(match, "g") { fail "-G and -g both provided"; } - system_mode - } else if opt_present(match, "g") { - if opt_present(match, "mode") { fail "--mode and -g both provided"; } - if opt_present(match, "G") { fail "-G and -g both provided"; } - user_mode - } else if opt_present(match, "mode") { - alt getopts::opt_str(match, "mode") { - "system" { system_mode } - "user" { user_mode } - "local" { local_mode } - _ { fail "argument to `mode` must be one of `system`" + - ", `user`, or `normal`"; - } - } - } else { - local_mode - }; + let G = opt_present(match, "G"); + let g = opt_present(match, "g"); + let m = opt_present(match, "mode"); + let is_install = vec::len(match.free) > 1u && match.free[1] == "install"; - if mode == system_mode { - // FIXME: Per discussion on #1760, we need to think about how - // system mode works. It should install files to the normal - // sysroot paths, but it also needsd an area to place various - // cargo configuration and work files. - fail "system mode does not exist yet"; - } + if G && g { fail "-G and -g both provided"; } + if g && m { fail "--mode and -g both provided"; } + if G && m { fail "--mode and -G both provided"; } + + let mode = if is_install { + if G { system_mode } + else if g { user_mode } + else if m { + alt getopts::opt_str(match, "mode") { + "system" { system_mode } + "user" { user_mode } + "local" { local_mode } + _ { fail "argument to `mode` must be one of `system`" + + ", `user`, or `local`"; + } + } + } else { local_mode } + } else { system_mode }; {test: test, mode: mode, free: match.free} } fn configure(opts: options) -> cargo { + let syscargo = result::get(get_cargo_sysroot()); let get_cargo_dir = alt opts.mode { system_mode { get_cargo_sysroot } user_mode { get_cargo_root } @@ -391,15 +387,15 @@ fn configure(opts: options) -> cargo { }; let sources = map::new_str_hash::(); - try_parse_sources(fs::connect(p, "sources.json"), sources); - try_parse_sources(fs::connect(p, "local-sources.json"), sources); + try_parse_sources(fs::connect(syscargo, "sources.json"), sources); + try_parse_sources(fs::connect(syscargo, "local-sources.json"), sources); let c = { pgp: pgp::supported(), root: p, bindir: fs::connect(p, "bin"), libdir: fs::connect(p, "lib"), workdir: fs::connect(p, "work"), - sourcedir: fs::connect(p, "sources"), + sourcedir: fs::connect(syscargo, "sources"), sources: sources, opts: opts }; From b06cb0df5a6db06bbc93b0d1c69a7da2770f4a6b Mon Sep 17 00:00:00 2001 From: Tycho Sci Date: Mon, 20 Feb 2012 17:33:50 +0900 Subject: [PATCH 3/3] cargo: Install blobs to $sysroot/(bin|lib) on system-mode Issue #1795 --- src/cargo/cargo.rs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 1d95c929b17..4d67877afd8 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -6,7 +6,7 @@ use std; import rustc::syntax::{ast, codemap}; import rustc::syntax::parse::parser; import rustc::util::filesearch::{get_cargo_root, get_cargo_root_nearest, - get_cargo_sysroot}; + get_cargo_sysroot, libdir}; import rustc::driver::diagnostic; import std::fs; @@ -467,13 +467,34 @@ fn install_one_crate(c: cargo, _path: str, cf: str, _p: pkg) { #debug(" bin: %s", ct); // FIXME: need libstd fs::copy or something run::run_program("cp", [ct, c.bindir]); + if c.opts.mode == system_mode { + install_one_crate_to_sysroot(ct, "bin"); + } } else { #debug(" lib: %s", ct); run::run_program("cp", [ct, c.libdir]); + if c.opts.mode == system_mode { + install_one_crate_to_sysroot(ct, libdir()); + } } } } +fn install_one_crate_to_sysroot(ct: str, target: str) { + alt os::get_exe_path() { + some(_path) { + let path = [_path, "..", target]; + check vec::is_not_empty(path); + let target_dir = fs::normalize(fs::connect_many(path)); + let p = run::program_output("cp", [ct, target_dir]); + if p.status != 0 { + warn(#fmt["Copying %s to %s is failed", ct, target_dir]); + } + } + none { } + } +} + fn rustc_sysroot() -> str { alt os::get_exe_path() { some(_path) { @@ -827,8 +848,8 @@ fn cmd_usage() { " init Set up .cargo - install [--test] [source/]package-name Install by name - install [--test] uuid:[source/]package-uuid Install by uuid + install [options] [source/]package-name Install by name + install [options] uuid:[source/]package-uuid Install by uuid list [source] List packages search [tags...] Search packages sync Sync all sources @@ -836,14 +857,16 @@ fn cmd_usage() { Options: + cargo install + --mode=[system,user,local] change mode as (system/user/local) -g equivalent to --mode=user -G equivalent to --mode=system NOTE: -This command creates/uses local-level .cargo by default. -To create/use user-level .cargo, use option -g/--mode=user. -To create/use system-level .cargo, use option -G/--mode=system. +\"cargo install\" installs bin/libs to local-level .cargo by default. +To install them into user-level .cargo, use option -g/--mode=user. +To install them into bin/lib on sysroot, use option -G/--mode=system. "); }