2011-11-30 17:57:46 -06:00
|
|
|
// cargo.rs - Rust package manager
|
|
|
|
|
2012-05-13 19:12:56 -05:00
|
|
|
import syntax::{ast, codemap};
|
|
|
|
import syntax::parse;
|
2012-02-07 02:15:39 -06:00
|
|
|
import rustc::util::filesearch::{get_cargo_root, get_cargo_root_nearest,
|
2012-02-20 02:33:50 -06:00
|
|
|
get_cargo_sysroot, libdir};
|
2012-05-13 19:12:56 -05:00
|
|
|
import syntax::diagnostic;
|
2011-11-30 17:57:46 -06:00
|
|
|
|
2012-02-25 18:39:32 -06:00
|
|
|
import result::{ok, err};
|
2012-01-11 08:15:54 -06:00
|
|
|
import io::writer_util;
|
2011-12-15 19:27:55 -06:00
|
|
|
import std::json;
|
2011-12-16 19:33:39 -06:00
|
|
|
import result;
|
|
|
|
import std::map;
|
2012-03-07 18:48:57 -06:00
|
|
|
import std::map::hashmap;
|
2011-12-13 18:25:51 -06:00
|
|
|
import str;
|
2011-11-30 17:57:46 -06:00
|
|
|
import std::tempfile;
|
2011-12-13 18:25:51 -06:00
|
|
|
import vec;
|
2012-02-05 03:30:03 -06:00
|
|
|
import std::getopts;
|
2012-02-07 02:15:39 -06:00
|
|
|
import getopts::{optflag, optopt, opt_present};
|
2011-11-30 17:57:46 -06:00
|
|
|
|
2011-12-16 19:33:39 -06:00
|
|
|
type package = {
|
|
|
|
name: str,
|
|
|
|
uuid: str,
|
2011-12-16 21:08:25 -06:00
|
|
|
url: str,
|
2011-12-20 19:41:23 -06:00
|
|
|
method: str,
|
2012-01-23 20:23:31 -06:00
|
|
|
description: str,
|
2012-01-31 19:05:20 -06:00
|
|
|
ref: option<str>,
|
2011-12-20 19:41:23 -06:00
|
|
|
tags: [str]
|
2011-12-16 19:33:39 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
type source = {
|
|
|
|
name: str,
|
|
|
|
url: str,
|
2012-01-31 19:05:20 -06:00
|
|
|
sig: option<str>,
|
|
|
|
key: option<str>,
|
|
|
|
keyfp: option<str>,
|
2012-03-26 20:35:18 -05:00
|
|
|
mut packages: [package]
|
2011-12-16 19:33:39 -06:00
|
|
|
};
|
|
|
|
|
2011-12-08 22:50:25 -06:00
|
|
|
type cargo = {
|
2011-12-20 18:59:37 -06:00
|
|
|
pgp: bool,
|
2011-12-08 22:50:25 -06:00
|
|
|
root: str,
|
|
|
|
bindir: str,
|
|
|
|
libdir: str,
|
|
|
|
workdir: str,
|
2011-12-16 19:33:39 -06:00
|
|
|
sourcedir: str,
|
2012-01-18 21:16:14 -06:00
|
|
|
sources: map::hashmap<str, source>,
|
2012-02-05 03:30:03 -06:00
|
|
|
opts: options
|
2011-12-08 22:50:25 -06:00
|
|
|
};
|
|
|
|
|
2011-11-30 17:57:46 -06:00
|
|
|
type pkg = {
|
|
|
|
name: str,
|
|
|
|
vers: str,
|
|
|
|
uuid: str,
|
2012-01-31 19:05:20 -06:00
|
|
|
desc: option<str>,
|
|
|
|
sigs: option<str>,
|
|
|
|
crate_type: option<str>
|
2011-11-30 17:57:46 -06:00
|
|
|
};
|
|
|
|
|
2012-02-05 03:30:03 -06:00
|
|
|
type options = {
|
|
|
|
test: bool,
|
2012-02-07 02:15:39 -06:00
|
|
|
mode: mode,
|
2012-02-05 03:30:03 -06:00
|
|
|
free: [str],
|
2012-05-26 10:35:54 -05:00
|
|
|
help: bool,
|
2012-02-05 03:30:03 -06:00
|
|
|
};
|
|
|
|
|
2012-02-07 02:15:39 -06:00
|
|
|
enum mode { system_mode, user_mode, local_mode }
|
|
|
|
|
2012-02-05 03:30:03 -06:00
|
|
|
fn opts() -> [getopts::opt] {
|
2012-05-26 10:35:54 -05:00
|
|
|
[optflag("g"), optflag("G"), optopt("mode"), optflag("test"),
|
|
|
|
optflag("h"), optflag("help")]
|
2012-02-05 03:30:03 -06:00
|
|
|
}
|
|
|
|
|
2011-12-16 19:33:39 -06:00
|
|
|
fn info(msg: str) {
|
2012-01-18 21:16:14 -06:00
|
|
|
io::stdout().write_line("info: " + msg);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn warn(msg: str) {
|
|
|
|
io::stdout().write_line("warning: " + msg);
|
|
|
|
}
|
|
|
|
|
2011-12-16 21:08:25 -06:00
|
|
|
fn error(msg: str) {
|
|
|
|
io::stdout().write_line("error: " + msg);
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:05:20 -06:00
|
|
|
fn load_link(mis: [@ast::meta_item]) -> (option<str>,
|
|
|
|
option<str>,
|
|
|
|
option<str>) {
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut name = none;
|
|
|
|
let mut vers = none;
|
|
|
|
let mut uuid = none;
|
2012-04-06 13:01:43 -05:00
|
|
|
for mis.each {|a|
|
2011-11-30 17:57:46 -06:00
|
|
|
alt a.node {
|
|
|
|
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
|
|
|
|
alt v {
|
|
|
|
"name" { name = some(s); }
|
|
|
|
"vers" { vers = some(s); }
|
|
|
|
"uuid" { uuid = some(s); }
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
_ { fail "load_link: meta items must be name-values"; }
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
(name, vers, uuid)
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:05:20 -06:00
|
|
|
fn load_pkg(filename: str) -> option<pkg> {
|
2012-01-13 19:33:16 -06:00
|
|
|
let cm = codemap::new_codemap();
|
2012-01-24 23:42:54 -06:00
|
|
|
let handler = diagnostic::mk_handler(none);
|
2012-01-13 19:33:16 -06:00
|
|
|
let sess = @{
|
|
|
|
cm: cm,
|
2012-03-26 20:35:18 -05:00
|
|
|
mut next_id: 1,
|
2012-01-24 23:42:54 -06:00
|
|
|
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
|
2012-03-26 20:35:18 -05:00
|
|
|
mut chpos: 0u,
|
|
|
|
mut byte_pos: 0u
|
2012-01-13 19:33:16 -06:00
|
|
|
};
|
2012-04-18 01:34:48 -05:00
|
|
|
let c = parse::parse_crate_from_crate_file(filename, [], sess);
|
2011-11-30 17:57:46 -06:00
|
|
|
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut name = none;
|
|
|
|
let mut vers = none;
|
|
|
|
let mut uuid = none;
|
|
|
|
let mut desc = none;
|
|
|
|
let mut sigs = none;
|
|
|
|
let mut crate_type = none;
|
2011-11-30 17:57:46 -06:00
|
|
|
|
2012-04-06 13:01:43 -05:00
|
|
|
for c.node.attrs.each {|a|
|
2011-11-30 17:57:46 -06:00
|
|
|
alt a.node.value.node {
|
|
|
|
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
|
|
|
|
alt v {
|
|
|
|
"desc" { desc = some(v); }
|
|
|
|
"sigs" { sigs = some(v); }
|
2011-12-08 22:41:29 -06:00
|
|
|
"crate_type" { crate_type = some(v); }
|
2011-11-30 17:57:46 -06:00
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast::meta_list(v, mis) {
|
|
|
|
if v == "link" {
|
|
|
|
let (n, v, u) = load_link(mis);
|
|
|
|
name = n;
|
|
|
|
vers = v;
|
|
|
|
uuid = u;
|
|
|
|
}
|
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
_ { fail "load_pkg: pkg attributes may not contain meta_words"; }
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
alt (name, vers, uuid) {
|
|
|
|
(some(name0), some(vers0), some(uuid0)) {
|
|
|
|
some({
|
|
|
|
name: name0,
|
|
|
|
vers: vers0,
|
|
|
|
uuid: uuid0,
|
|
|
|
desc: desc,
|
2011-12-08 22:41:29 -06:00
|
|
|
sigs: sigs,
|
|
|
|
crate_type: crate_type})
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
_ { ret none; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print(s: str) {
|
|
|
|
io::stdout().write_line(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rest(s: str, start: uint) -> str {
|
2012-02-23 03:44:04 -06:00
|
|
|
if (start >= str::len(s)) {
|
2011-11-30 17:57:46 -06:00
|
|
|
""
|
|
|
|
} else {
|
2012-02-23 03:44:04 -06:00
|
|
|
str::slice(s, start, str::len(s))
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 22:41:29 -06:00
|
|
|
fn need_dir(s: str) {
|
2012-03-12 22:04:27 -05:00
|
|
|
if os::path_is_dir(s) { ret; }
|
2012-05-26 10:35:54 -05:00
|
|
|
if !os::make_dir(s, 493_i32 /* oct: 755 */) {
|
2011-12-08 22:41:29 -06:00
|
|
|
fail #fmt["can't make_dir %s", s];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 19:33:39 -06:00
|
|
|
fn parse_source(name: str, j: json::json) -> source {
|
|
|
|
alt j {
|
|
|
|
json::dict(_j) {
|
2011-12-20 18:59:37 -06:00
|
|
|
let url = alt _j.find("url") {
|
2011-12-16 19:33:39 -06:00
|
|
|
some(json::string(u)) {
|
2011-12-20 18:59:37 -06:00
|
|
|
u
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
_ { fail "Needed 'url' field in source."; }
|
|
|
|
};
|
2011-12-20 18:59:37 -06:00
|
|
|
let sig = alt _j.find("sig") {
|
|
|
|
some(json::string(u)) {
|
|
|
|
some(u)
|
|
|
|
}
|
|
|
|
_ { none }
|
|
|
|
};
|
|
|
|
let key = alt _j.find("key") {
|
|
|
|
some(json::string(u)) {
|
|
|
|
some(u)
|
|
|
|
}
|
|
|
|
_ { none }
|
|
|
|
};
|
|
|
|
let keyfp = alt _j.find("keyfp") {
|
|
|
|
some(json::string(u)) {
|
|
|
|
some(u)
|
|
|
|
}
|
|
|
|
_ { none }
|
|
|
|
};
|
|
|
|
ret { name: name, url: url, sig: sig, key: key, keyfp: keyfp,
|
2012-03-26 20:35:18 -05:00
|
|
|
mut packages: [] };
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
_ { fail "Needed dict value in source."; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn try_parse_sources(filename: str, sources: map::hashmap<str, source>) {
|
2012-03-12 22:04:27 -05:00
|
|
|
if !os::path_exists(filename) { ret; }
|
2011-12-16 19:33:39 -06:00
|
|
|
let c = io::read_whole_file_str(filename);
|
2012-02-25 18:39:32 -06:00
|
|
|
alt json::from_str(result::get(c)) {
|
|
|
|
ok(json::dict(j)) {
|
2012-04-23 06:42:15 -05:00
|
|
|
for j.each { |k, v|
|
2011-12-16 19:33:39 -06:00
|
|
|
sources.insert(k, parse_source(k, v));
|
2011-12-22 16:42:52 -06:00
|
|
|
#debug("source: %s", k);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-25 18:39:32 -06:00
|
|
|
ok(_) { fail "malformed sources.json"; }
|
|
|
|
err(e) { fail #fmt("%s:%u:%u: %s", filename, e.line, e.col, e.msg); }
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 21:27:04 -06:00
|
|
|
fn load_one_source_package(&src: source, p: map::hashmap<str, json::json>) {
|
2011-12-16 19:33:39 -06:00
|
|
|
let name = alt p.find("name") {
|
|
|
|
some(json::string(_n)) { _n }
|
|
|
|
_ {
|
|
|
|
warn("Malformed source json: " + src.name + " (missing name)");
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let uuid = alt p.find("uuid") {
|
|
|
|
some(json::string(_n)) { _n }
|
|
|
|
_ {
|
|
|
|
warn("Malformed source json: " + src.name + " (missing uuid)");
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let url = alt p.find("url") {
|
|
|
|
some(json::string(_n)) { _n }
|
|
|
|
_ {
|
|
|
|
warn("Malformed source json: " + src.name + " (missing url)");
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-16 21:08:25 -06:00
|
|
|
let method = alt p.find("method") {
|
|
|
|
some(json::string(_n)) { _n }
|
|
|
|
_ {
|
|
|
|
warn("Malformed source json: " + src.name + " (missing method)");
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-20 22:41:22 -06:00
|
|
|
let ref = alt p.find("ref") {
|
|
|
|
some(json::string(_n)) { some(_n) }
|
|
|
|
_ { none }
|
|
|
|
};
|
|
|
|
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut tags = [];
|
2011-12-20 19:41:23 -06:00
|
|
|
alt p.find("tags") {
|
|
|
|
some(json::list(js)) {
|
2012-04-06 13:01:43 -05:00
|
|
|
for js.each {|j|
|
2011-12-20 19:41:23 -06:00
|
|
|
alt j {
|
|
|
|
json::string(_j) { vec::grow(tags, 1u, _j); }
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
2012-01-23 21:42:29 -06:00
|
|
|
|
|
|
|
let description = alt p.find("description") {
|
|
|
|
some(json::string(_n)) { _n }
|
|
|
|
_ {
|
2012-01-23 23:14:48 -06:00
|
|
|
warn("Malformed source json: " + src.name
|
|
|
|
+ " (missing description)");
|
2012-01-23 21:42:29 -06:00
|
|
|
ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-16 19:33:39 -06:00
|
|
|
vec::grow(src.packages, 1u, {
|
|
|
|
name: name,
|
|
|
|
uuid: uuid,
|
2011-12-16 21:08:25 -06:00
|
|
|
url: url,
|
2011-12-20 19:41:23 -06:00
|
|
|
method: method,
|
2012-01-23 20:23:31 -06:00
|
|
|
description: description,
|
2011-12-20 22:41:22 -06:00
|
|
|
ref: ref,
|
2011-12-20 19:41:23 -06:00
|
|
|
tags: tags
|
2011-12-16 19:33:39 -06:00
|
|
|
});
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, " Loaded package: " + src.name + "/" + name);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
|
2011-12-16 21:08:25 -06:00
|
|
|
fn load_source_packages(&c: cargo, &src: source) {
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, "Loading source: " + src.name);
|
2012-03-12 22:04:27 -05:00
|
|
|
let dir = path::connect(c.sourcedir, src.name);
|
|
|
|
let pkgfile = path::connect(dir, "packages.json");
|
|
|
|
if !os::path_exists(pkgfile) { ret; }
|
2011-12-16 19:33:39 -06:00
|
|
|
let pkgstr = io::read_whole_file_str(pkgfile);
|
2012-02-25 18:39:32 -06:00
|
|
|
alt json::from_str(result::get(pkgstr)) {
|
|
|
|
ok(json::list(js)) {
|
2012-04-06 13:01:43 -05:00
|
|
|
for js.each {|_j|
|
2011-12-16 19:33:39 -06:00
|
|
|
alt _j {
|
|
|
|
json::dict(_p) {
|
2011-12-16 21:27:04 -06:00
|
|
|
load_one_source_package(src, _p);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
_ {
|
2011-12-16 22:15:13 -06:00
|
|
|
warn("Malformed source json: " + src.name +
|
|
|
|
" (non-dict pkg)");
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-25 18:39:32 -06:00
|
|
|
ok(_) {
|
|
|
|
warn("Malformed source json: " + src.name +
|
|
|
|
"(packages is not a list)");
|
|
|
|
}
|
|
|
|
err(e) {
|
|
|
|
warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg));
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-02-05 03:30:03 -06:00
|
|
|
fn build_cargo_options(argv: [str]) -> options {
|
|
|
|
let match = alt getopts::getopts(argv, opts()) {
|
|
|
|
result::ok(m) { m }
|
|
|
|
result::err(f) {
|
|
|
|
fail #fmt["%s", getopts::fail_str(f)];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let test = opt_present(match, "test");
|
2012-05-26 10:35:54 -05:00
|
|
|
let G = opt_present(match, "G");
|
|
|
|
let g = opt_present(match, "g");
|
|
|
|
let m = opt_present(match, "mode");
|
|
|
|
let help = opt_present(match, "h") || opt_present(match, "help");
|
|
|
|
|
2012-02-20 02:08:58 -06:00
|
|
|
let is_install = vec::len(match.free) > 1u && match.free[1] == "install";
|
|
|
|
|
|
|
|
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"; }
|
|
|
|
|
2012-05-26 10:35:54 -05:00
|
|
|
if !is_install && (g || G || m) {
|
|
|
|
fail "-g, -G, --mode are only valid for `install`";
|
|
|
|
}
|
|
|
|
|
|
|
|
let mode =
|
|
|
|
if !is_install || G { system_mode }
|
|
|
|
else if g { user_mode }
|
|
|
|
else if !m { local_mode }
|
|
|
|
else {
|
2012-02-20 02:08:58 -06:00
|
|
|
alt getopts::opt_str(match, "mode") {
|
|
|
|
"system" { system_mode }
|
2012-05-26 10:35:54 -05:00
|
|
|
"user" { user_mode }
|
|
|
|
"local" { local_mode }
|
|
|
|
_ { fail "argument to `mode` must be" +
|
|
|
|
"one of `system`, `user`, or `local`"; }}
|
|
|
|
};
|
2012-02-09 15:42:59 -06:00
|
|
|
|
2012-05-26 10:35:54 -05:00
|
|
|
{test: test, mode: mode, free: match.free, help: help}
|
2012-02-05 03:30:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn configure(opts: options) -> cargo {
|
2012-05-26 10:35:54 -05:00
|
|
|
// NOTE: to make init and sync save into non-root level directories
|
|
|
|
// simply get rid of syscargo, below
|
|
|
|
|
2012-02-20 02:08:58 -06:00
|
|
|
let syscargo = result::get(get_cargo_sysroot());
|
2012-05-26 10:35:54 -05:00
|
|
|
|
2012-02-07 02:15:39 -06:00
|
|
|
let get_cargo_dir = alt opts.mode {
|
|
|
|
system_mode { get_cargo_sysroot }
|
|
|
|
user_mode { get_cargo_root }
|
|
|
|
local_mode { get_cargo_root_nearest }
|
2012-02-05 03:30:03 -06:00
|
|
|
};
|
|
|
|
|
2012-05-26 10:35:54 -05:00
|
|
|
let p = result::get(get_cargo_dir());
|
2011-12-08 22:41:29 -06:00
|
|
|
|
2012-03-14 14:07:23 -05:00
|
|
|
let sources = map::str_hash::<source>();
|
2012-03-12 22:04:27 -05:00
|
|
|
try_parse_sources(path::connect(syscargo, "sources.json"), sources);
|
|
|
|
try_parse_sources(path::connect(syscargo, "local-sources.json"), sources);
|
2012-05-26 10:35:54 -05:00
|
|
|
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut c = {
|
2011-12-20 18:59:37 -06:00
|
|
|
pgp: pgp::supported(),
|
2011-12-08 22:50:25 -06:00
|
|
|
root: p,
|
2012-03-12 22:04:27 -05:00
|
|
|
bindir: path::connect(p, "bin"),
|
|
|
|
libdir: path::connect(p, "lib"),
|
|
|
|
workdir: path::connect(p, "work"),
|
|
|
|
sourcedir: path::connect(syscargo, "sources"),
|
2012-01-18 21:16:14 -06:00
|
|
|
sources: sources,
|
2012-02-05 03:30:03 -06:00
|
|
|
opts: opts
|
2011-12-08 22:50:25 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
need_dir(c.root);
|
2011-12-16 19:33:39 -06:00
|
|
|
need_dir(c.sourcedir);
|
2011-12-08 22:50:25 -06:00
|
|
|
need_dir(c.workdir);
|
|
|
|
need_dir(c.libdir);
|
|
|
|
need_dir(c.bindir);
|
2011-12-08 22:41:29 -06:00
|
|
|
|
2012-04-23 06:42:15 -05:00
|
|
|
for sources.each_key { |k|
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut s = sources.get(k);
|
2011-12-16 21:08:25 -06:00
|
|
|
load_source_packages(c, s);
|
|
|
|
sources.insert(k, s);
|
2012-04-23 06:42:15 -05:00
|
|
|
}
|
2011-12-16 19:33:39 -06:00
|
|
|
|
2011-12-20 18:59:37 -06:00
|
|
|
if c.pgp {
|
|
|
|
pgp::init(c.root);
|
2012-02-13 19:06:20 -06:00
|
|
|
} else {
|
|
|
|
warn("command \"gpg\" is not found");
|
|
|
|
warn("you have to install \"gpg\" from source " +
|
|
|
|
" or package manager to get it to work correctly");
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
|
|
|
|
2011-12-08 22:50:25 -06:00
|
|
|
c
|
2011-12-08 22:41:29 -06:00
|
|
|
}
|
|
|
|
|
2012-01-23 16:59:00 -06:00
|
|
|
fn for_each_package(c: cargo, b: fn(source, package)) {
|
2012-04-23 06:42:15 -05:00
|
|
|
for c.sources.each_value {|v|
|
2012-04-24 17:18:24 -05:00
|
|
|
// FIXME (#2280): this temporary shouldn't be
|
|
|
|
// necessary, but seems to be, for borrowing.
|
|
|
|
let pks = copy v.packages;
|
|
|
|
for vec::each(pks) {|p|
|
2011-12-16 21:08:25 -06:00
|
|
|
b(v, p);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
2012-04-23 06:42:15 -05:00
|
|
|
}
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
|
2012-03-15 16:03:30 -05:00
|
|
|
// Runs all programs in directory <buildpath>
|
|
|
|
fn run_programs(buildpath: str) {
|
2012-04-01 10:39:17 -05:00
|
|
|
let newv = os::list_dir_path(buildpath);
|
2012-04-06 13:01:43 -05:00
|
|
|
for newv.each {|ct|
|
2012-01-21 13:59:10 -06:00
|
|
|
run::run_program(ct, []);
|
2012-01-18 21:24:07 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-15 16:03:30 -05:00
|
|
|
// Runs rustc in <path + subdir> with the given flags
|
|
|
|
// and returns <path + subdir>
|
|
|
|
fn run_in_buildpath(what: str, path: str, subdir: str, cf: str,
|
|
|
|
extra_flags: [str]) -> option<str> {
|
|
|
|
let buildpath = path::connect(path, subdir);
|
2012-01-18 21:16:14 -06:00
|
|
|
need_dir(buildpath);
|
2012-03-15 16:03:30 -05:00
|
|
|
#debug("%s: %s -> %s", what, cf, buildpath);
|
2012-02-13 18:33:59 -06:00
|
|
|
let p = run::program_output(rustc_sysroot(),
|
2012-03-15 16:03:30 -05:00
|
|
|
["--out-dir", buildpath, cf] + extra_flags);
|
2012-01-18 21:16:14 -06:00
|
|
|
if p.status != 0 {
|
|
|
|
error(#fmt["rustc failed: %d\n%s\n%s", p.status, p.err, p.out]);
|
2012-03-15 16:03:30 -05:00
|
|
|
ret none;
|
2012-01-18 21:16:14 -06:00
|
|
|
}
|
2012-03-15 16:03:30 -05:00
|
|
|
some(buildpath)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_one_crate(_c: cargo, path: str, cf: str) {
|
|
|
|
let buildpath = alt run_in_buildpath("Testing", path, "/test", cf,
|
|
|
|
[ "--test"]) {
|
|
|
|
none { ret; }
|
|
|
|
some(bp) { bp }
|
|
|
|
};
|
|
|
|
run_programs(buildpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn install_one_crate(c: cargo, path: str, cf: str) {
|
|
|
|
let buildpath = alt run_in_buildpath("Installing", path,
|
|
|
|
"/build", cf, []) {
|
|
|
|
none { ret; }
|
|
|
|
some(bp) { bp }
|
|
|
|
};
|
2012-04-01 10:39:17 -05:00
|
|
|
let newv = os::list_dir_path(buildpath);
|
2012-03-12 22:04:27 -05:00
|
|
|
let exec_suffix = os::exe_suffix();
|
2012-04-06 13:01:43 -05:00
|
|
|
for newv.each {|ct|
|
2012-05-26 10:35:54 -05:00
|
|
|
// FIXME: What's up with the dual installation? Both `install_to_dir`
|
|
|
|
// and `install_one_crate_to_sysroot` install the binary files...
|
|
|
|
|
2011-12-16 03:08:24 -06:00
|
|
|
if (exec_suffix != "" && str::ends_with(ct, exec_suffix)) ||
|
2012-03-12 22:04:27 -05:00
|
|
|
(exec_suffix == "" && !str::starts_with(path::basename(ct),
|
2012-01-21 13:59:10 -06:00
|
|
|
"lib")) {
|
2011-12-22 16:42:52 -06:00
|
|
|
#debug(" bin: %s", ct);
|
2012-05-26 10:35:54 -05:00
|
|
|
install_to_dir(ct, c.bindir);
|
2012-02-20 02:33:50 -06:00
|
|
|
if c.opts.mode == system_mode {
|
|
|
|
install_one_crate_to_sysroot(ct, "bin");
|
|
|
|
}
|
2011-12-08 22:41:29 -06:00
|
|
|
} else {
|
2011-12-22 16:42:52 -06:00
|
|
|
#debug(" lib: %s", ct);
|
2012-05-26 10:35:54 -05:00
|
|
|
install_to_dir(ct, c.bindir);
|
2012-02-20 02:33:50 -06:00
|
|
|
if c.opts.mode == system_mode {
|
|
|
|
install_one_crate_to_sysroot(ct, libdir());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn install_one_crate_to_sysroot(ct: str, target: str) {
|
2012-03-12 22:04:27 -05:00
|
|
|
alt os::self_exe_path() {
|
2012-02-20 02:33:50 -06:00
|
|
|
some(_path) {
|
|
|
|
let path = [_path, "..", target];
|
|
|
|
check vec::is_not_empty(path);
|
2012-03-12 22:04:27 -05:00
|
|
|
let target_dir = path::normalize(path::connect_many(path));
|
2012-05-26 10:35:54 -05:00
|
|
|
install_to_dir(ct, target_dir);
|
2011-12-08 22:41:29 -06:00
|
|
|
}
|
2012-02-20 02:33:50 -06:00
|
|
|
none { }
|
2011-12-08 22:41:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-13 18:33:59 -06:00
|
|
|
fn rustc_sysroot() -> str {
|
2012-03-12 22:04:27 -05:00
|
|
|
alt os::self_exe_path() {
|
2012-02-13 18:33:59 -06:00
|
|
|
some(_path) {
|
|
|
|
let path = [_path, "..", "bin", "rustc"];
|
|
|
|
check vec::is_not_empty(path);
|
2012-03-12 22:04:27 -05:00
|
|
|
let rustc = path::normalize(path::connect_many(path));
|
2012-02-13 18:33:59 -06:00
|
|
|
#debug(" rustc: %s", rustc);
|
|
|
|
rustc
|
|
|
|
}
|
|
|
|
none { "rustc" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 22:50:25 -06:00
|
|
|
fn install_source(c: cargo, path: str) {
|
2011-12-22 16:42:52 -06:00
|
|
|
#debug("source: %s", path);
|
2012-03-12 22:04:27 -05:00
|
|
|
os::change_dir(path);
|
2011-12-01 21:37:56 -06:00
|
|
|
|
2012-04-21 17:46:05 -05:00
|
|
|
let mut cratefiles = [];
|
|
|
|
for os::walk_dir(".") {|p|
|
|
|
|
if str::ends_with(p, ".rc") {
|
|
|
|
cratefiles += [p];
|
|
|
|
}
|
|
|
|
}
|
2011-12-01 21:37:56 -06:00
|
|
|
|
2011-12-08 22:41:29 -06:00
|
|
|
if vec::is_empty(cratefiles) {
|
|
|
|
fail "This doesn't look like a rust package (no .rc files).";
|
2011-12-01 21:37:56 -06:00
|
|
|
}
|
|
|
|
|
2012-04-06 13:01:43 -05:00
|
|
|
for cratefiles.each {|cf|
|
2011-12-08 22:41:29 -06:00
|
|
|
let p = load_pkg(cf);
|
|
|
|
alt p {
|
2012-01-19 00:37:22 -06:00
|
|
|
none { cont; }
|
2012-03-15 16:03:30 -05:00
|
|
|
some(_) {
|
2012-02-05 03:30:03 -06:00
|
|
|
if c.opts.test {
|
2012-03-15 16:03:30 -05:00
|
|
|
test_one_crate(c, path, cf);
|
2012-01-18 21:16:14 -06:00
|
|
|
}
|
2012-03-15 16:03:30 -05:00
|
|
|
install_one_crate(c, path, cf);
|
2011-12-08 22:41:29 -06:00
|
|
|
}
|
|
|
|
}
|
2011-12-01 21:37:56 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:05:20 -06:00
|
|
|
fn install_git(c: cargo, wd: str, url: str, ref: option<str>) {
|
2011-12-16 21:08:25 -06:00
|
|
|
run::run_program("git", ["clone", url, wd]);
|
2011-12-20 22:41:22 -06:00
|
|
|
if option::is_some::<str>(ref) {
|
|
|
|
let r = option::get::<str>(ref);
|
2012-03-12 22:04:27 -05:00
|
|
|
os::change_dir(wd);
|
2011-12-20 22:41:22 -06:00
|
|
|
run::run_program("git", ["checkout", r]);
|
|
|
|
}
|
|
|
|
|
2011-12-08 23:39:41 -06:00
|
|
|
install_source(c, wd);
|
2011-12-08 23:34:06 -06:00
|
|
|
}
|
|
|
|
|
2011-12-16 21:08:25 -06:00
|
|
|
fn install_curl(c: cargo, wd: str, url: str) {
|
2012-03-12 22:04:27 -05:00
|
|
|
let tarpath = path::connect(wd, "pkg.tar");
|
2011-12-16 21:08:25 -06:00
|
|
|
let p = run::program_output("curl", ["-f", "-s", "-o",
|
|
|
|
tarpath, url]);
|
|
|
|
if p.status != 0 {
|
|
|
|
fail #fmt["Fetch of %s failed: %s", url, p.err];
|
|
|
|
}
|
2011-12-08 23:39:41 -06:00
|
|
|
run::run_program("tar", ["-x", "--strip-components=1",
|
2011-12-16 21:08:25 -06:00
|
|
|
"-C", wd, "-f", tarpath]);
|
2011-12-16 21:27:04 -06:00
|
|
|
install_source(c, wd);
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn install_file(c: cargo, wd: str, path: str) {
|
|
|
|
run::run_program("tar", ["-x", "--strip-components=1",
|
|
|
|
"-C", wd, "-f", path]);
|
2011-12-08 23:39:41 -06:00
|
|
|
install_source(c, wd);
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
|
2011-12-16 21:08:25 -06:00
|
|
|
fn install_package(c: cargo, wd: str, pkg: package) {
|
|
|
|
info("Installing with " + pkg.method + " from " + pkg.url + "...");
|
|
|
|
if pkg.method == "git" {
|
2011-12-20 22:41:22 -06:00
|
|
|
install_git(c, wd, pkg.url, pkg.ref);
|
2011-12-16 21:08:25 -06:00
|
|
|
} else if pkg.method == "http" {
|
|
|
|
install_curl(c, wd, pkg.url);
|
|
|
|
} else if pkg.method == "file" {
|
|
|
|
install_file(c, wd, pkg.url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-24 10:08:58 -06:00
|
|
|
fn cargo_suggestion(c: cargo, syncing: bool, fallback: fn())
|
|
|
|
{
|
|
|
|
if c.sources.size() == 0u {
|
|
|
|
error("No sources defined. You may wish to run " +
|
|
|
|
"\"cargo init\" then \"cargo sync\".");
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
if !syncing {
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut npkg = 0u;
|
2012-04-23 06:42:15 -05:00
|
|
|
for c.sources.each_value { |v| npkg += vec::len(v.packages) }
|
2012-01-24 10:08:58 -06:00
|
|
|
if npkg == 0u {
|
|
|
|
error("No packages known. You may wish to run " +
|
|
|
|
"\"cargo sync\".");
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fallback();
|
|
|
|
}
|
|
|
|
|
2011-12-15 19:27:55 -06:00
|
|
|
fn install_uuid(c: cargo, wd: str, uuid: str) {
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut ps = [];
|
2011-12-16 21:08:25 -06:00
|
|
|
for_each_package(c, { |s, p|
|
|
|
|
info(#fmt["%s ? %s", p.uuid, uuid]);
|
2011-12-16 19:33:39 -06:00
|
|
|
if p.uuid == uuid {
|
2012-05-24 16:49:39 -05:00
|
|
|
vec::grow(ps, 1u, (s.name, p));
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
});
|
2011-12-16 21:08:25 -06:00
|
|
|
if vec::len(ps) == 1u {
|
2011-12-16 21:27:04 -06:00
|
|
|
let (_, p) = ps[0];
|
2011-12-16 21:08:25 -06:00
|
|
|
install_package(c, wd, p);
|
|
|
|
ret;
|
|
|
|
} else if vec::len(ps) == 0u {
|
2012-01-24 10:08:58 -06:00
|
|
|
cargo_suggestion(c, false, { || error("No packages match uuid."); });
|
2011-12-16 21:08:25 -06:00
|
|
|
ret;
|
|
|
|
}
|
|
|
|
error("Found multiple packages:");
|
2012-04-06 13:01:43 -05:00
|
|
|
for ps.each {|elt|
|
2012-05-24 16:49:39 -05:00
|
|
|
let (sname,p) = elt;
|
|
|
|
info(" " + sname + "/" + p.uuid + " (" + p.name + ")");
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
2011-12-15 19:27:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn install_named(c: cargo, wd: str, name: str) {
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut ps = [];
|
2011-12-16 21:08:25 -06:00
|
|
|
for_each_package(c, { |s, p|
|
2011-12-16 19:33:39 -06:00
|
|
|
if p.name == name {
|
2012-05-24 16:49:39 -05:00
|
|
|
vec::grow(ps, 1u, (s.name, p));
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
});
|
2011-12-16 21:08:25 -06:00
|
|
|
if vec::len(ps) == 1u {
|
2011-12-16 21:27:04 -06:00
|
|
|
let (_, p) = ps[0];
|
2011-12-16 21:08:25 -06:00
|
|
|
install_package(c, wd, p);
|
|
|
|
ret;
|
|
|
|
} else if vec::len(ps) == 0u {
|
2012-01-24 10:08:58 -06:00
|
|
|
cargo_suggestion(c, false, { || error("No packages match name."); });
|
2011-12-16 21:08:25 -06:00
|
|
|
ret;
|
|
|
|
}
|
|
|
|
error("Found multiple packages:");
|
2012-04-06 13:01:43 -05:00
|
|
|
for ps.each {|elt|
|
2012-05-24 16:49:39 -05:00
|
|
|
let (sname,p) = elt;
|
|
|
|
info(" " + sname + "/" + p.uuid + " (" + p.name + ")");
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn install_uuid_specific(c: cargo, wd: str, src: str, uuid: str) {
|
|
|
|
alt c.sources.find(src) {
|
2012-05-18 12:40:54 -05:00
|
|
|
some(s) {
|
|
|
|
let packages = copy s.packages;
|
|
|
|
if vec::any(packages, { |p|
|
|
|
|
if p.uuid == uuid {
|
|
|
|
install_package(c, wd, p);
|
|
|
|
true
|
|
|
|
} else { false }
|
|
|
|
}) { ret; }
|
|
|
|
}
|
|
|
|
_ { }
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
2011-12-16 21:08:25 -06:00
|
|
|
error("Can't find package " + src + "/" + uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn install_named_specific(c: cargo, wd: str, src: str, name: str) {
|
|
|
|
alt c.sources.find(src) {
|
|
|
|
some(s) {
|
2012-05-18 12:40:54 -05:00
|
|
|
let packages = copy s.packages;
|
|
|
|
if vec::any(packages, { |p|
|
2011-12-16 21:08:25 -06:00
|
|
|
if p.name == name {
|
|
|
|
install_package(c, wd, p);
|
2012-03-26 06:16:29 -05:00
|
|
|
true
|
|
|
|
} else { false }
|
2011-12-16 21:08:25 -06:00
|
|
|
}) { ret; }
|
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
error("Can't find package " + src + "/" + name);
|
2011-12-15 19:27:55 -06:00
|
|
|
}
|
|
|
|
|
2012-02-05 03:30:03 -06:00
|
|
|
fn cmd_install(c: cargo) unsafe {
|
2011-11-30 17:57:46 -06:00
|
|
|
// cargo install <pkg>
|
2012-02-05 03:30:03 -06:00
|
|
|
if vec::len(c.opts.free) < 3u {
|
2011-11-30 17:57:46 -06:00
|
|
|
cmd_usage();
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
2012-02-05 03:30:03 -06:00
|
|
|
let target = c.opts.free[2];
|
2012-01-18 21:16:14 -06:00
|
|
|
|
2012-05-26 10:35:54 -05:00
|
|
|
let wd_base = c.workdir + path::path_sep();
|
|
|
|
let wd = alt tempfile::mkdtemp(wd_base, "") {
|
2011-12-08 23:39:41 -06:00
|
|
|
some(_wd) { _wd }
|
2012-05-26 10:35:54 -05:00
|
|
|
none { fail #fmt("needed temp dir: %s", wd_base); }
|
2011-12-08 23:39:41 -06:00
|
|
|
};
|
|
|
|
|
2012-01-18 21:16:14 -06:00
|
|
|
if str::starts_with(target, "uuid:") {
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut uuid = rest(target, 5u);
|
2012-02-23 10:11:21 -06:00
|
|
|
alt str::find_char(uuid, '/') {
|
2012-02-11 05:20:45 -06:00
|
|
|
option::some(idx) {
|
2012-02-23 01:46:45 -06:00
|
|
|
let source = str::slice(uuid, 0u, idx);
|
2012-02-23 03:44:04 -06:00
|
|
|
uuid = str::slice(uuid, idx + 1u, str::len(uuid));
|
2012-02-11 05:20:45 -06:00
|
|
|
install_uuid_specific(c, wd, source, uuid);
|
|
|
|
}
|
|
|
|
option::none {
|
|
|
|
install_uuid(c, wd, uuid);
|
|
|
|
}
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
2011-12-15 19:27:55 -06:00
|
|
|
} else {
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut name = target;
|
2012-02-23 10:11:21 -06:00
|
|
|
alt str::find_char(name, '/') {
|
2012-02-11 05:20:45 -06:00
|
|
|
option::some(idx) {
|
2012-02-23 01:46:45 -06:00
|
|
|
let source = str::slice(name, 0u, idx);
|
2012-02-23 03:44:04 -06:00
|
|
|
name = str::slice(name, idx + 1u, str::len(name));
|
2012-02-11 05:20:45 -06:00
|
|
|
install_named_specific(c, wd, source, name);
|
|
|
|
}
|
|
|
|
option::none {
|
|
|
|
install_named(c, wd, name);
|
|
|
|
}
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
2011-12-01 21:37:56 -06:00
|
|
|
}
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
|
2011-12-16 19:33:39 -06:00
|
|
|
fn sync_one(c: cargo, name: str, src: source) {
|
2012-03-12 22:04:27 -05:00
|
|
|
let dir = path::connect(c.sourcedir, name);
|
|
|
|
let pkgfile = path::connect(dir, "packages.json.new");
|
|
|
|
let destpkgfile = path::connect(dir, "packages.json");
|
|
|
|
let sigfile = path::connect(dir, "packages.json.sig");
|
|
|
|
let keyfile = path::connect(dir, "key.gpg");
|
2011-12-16 19:33:39 -06:00
|
|
|
let url = src.url;
|
|
|
|
need_dir(dir);
|
2011-12-16 21:08:25 -06:00
|
|
|
info(#fmt["fetching source %s...", name]);
|
2011-12-16 19:33:39 -06:00
|
|
|
let p = run::program_output("curl", ["-f", "-s", "-o", pkgfile, url]);
|
|
|
|
if p.status != 0 {
|
|
|
|
warn(#fmt["fetch for source %s (url %s) failed", name, url]);
|
|
|
|
} else {
|
|
|
|
info(#fmt["fetched source: %s", name]);
|
|
|
|
}
|
2011-12-20 18:59:37 -06:00
|
|
|
alt src.sig {
|
|
|
|
some(u) {
|
2011-12-20 20:52:50 -06:00
|
|
|
let p = run::program_output("curl", ["-f", "-s", "-o", sigfile,
|
|
|
|
u]);
|
2011-12-20 18:59:37 -06:00
|
|
|
if p.status != 0 {
|
|
|
|
warn(#fmt["fetch for source %s (sig %s) failed", name, u]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
alt src.key {
|
|
|
|
some(u) {
|
2011-12-20 20:52:50 -06:00
|
|
|
let p = run::program_output("curl", ["-f", "-s", "-o", keyfile,
|
|
|
|
u]);
|
2011-12-20 18:59:37 -06:00
|
|
|
if p.status != 0 {
|
|
|
|
warn(#fmt["fetch for source %s (key %s) failed", name, u]);
|
|
|
|
}
|
|
|
|
pgp::add(c.root, keyfile);
|
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
alt (src.sig, src.key, src.keyfp) {
|
|
|
|
(some(_), some(_), some(f)) {
|
|
|
|
let r = pgp::verify(c.root, pkgfile, sigfile, f);
|
|
|
|
if !r {
|
2011-12-20 20:52:50 -06:00
|
|
|
warn(#fmt["signature verification failed for source %s",
|
|
|
|
name]);
|
2011-12-20 18:59:37 -06:00
|
|
|
} else {
|
|
|
|
info(#fmt["signature ok for source %s", name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ {
|
|
|
|
info(#fmt["no signature for source %s", name]);
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 00:53:40 -05:00
|
|
|
copy_warn(pkgfile, destpkgfile);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
|
2012-02-05 03:30:03 -06:00
|
|
|
fn cmd_sync(c: cargo) {
|
|
|
|
if vec::len(c.opts.free) == 3u {
|
|
|
|
sync_one(c, c.opts.free[2], c.sources.get(c.opts.free[2]));
|
2011-12-16 19:33:39 -06:00
|
|
|
} else {
|
2012-01-24 10:08:58 -06:00
|
|
|
cargo_suggestion(c, true, { || } );
|
2012-04-23 06:42:15 -05:00
|
|
|
for c.sources.each { |k, v|
|
2011-12-16 19:33:39 -06:00
|
|
|
sync_one(c, k, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 20:52:50 -06:00
|
|
|
fn cmd_init(c: cargo) {
|
2011-12-20 18:59:37 -06:00
|
|
|
let srcurl = "http://www.rust-lang.org/cargo/sources.json";
|
|
|
|
let sigurl = "http://www.rust-lang.org/cargo/sources.json.sig";
|
|
|
|
|
2012-03-12 22:04:27 -05:00
|
|
|
let srcfile = path::connect(c.root, "sources.json.new");
|
|
|
|
let sigfile = path::connect(c.root, "sources.json.sig");
|
|
|
|
let destsrcfile = path::connect(c.root, "sources.json");
|
2011-12-20 18:59:37 -06:00
|
|
|
|
|
|
|
let p = run::program_output("curl", ["-f", "-s", "-o", srcfile, srcurl]);
|
|
|
|
if p.status != 0 {
|
|
|
|
warn(#fmt["fetch of sources.json failed: %s", p.out]);
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
let p = run::program_output("curl", ["-f", "-s", "-o", sigfile, sigurl]);
|
|
|
|
if p.status != 0 {
|
|
|
|
warn(#fmt["fetch of sources.json.sig failed: %s", p.out]);
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
let r = pgp::verify(c.root, srcfile, sigfile, pgp::signing_key_fp());
|
|
|
|
if !r {
|
2012-05-26 10:35:54 -05:00
|
|
|
warn(#fmt["signature verification failed for '%s'", srcfile]);
|
2012-03-10 21:33:09 -06:00
|
|
|
} else {
|
2012-05-26 10:35:54 -05:00
|
|
|
info(#fmt["signature ok for '%s'", srcfile]);
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
2012-04-03 00:53:40 -05:00
|
|
|
copy_warn(srcfile, destsrcfile);
|
2012-02-07 02:15:39 -06:00
|
|
|
|
|
|
|
info(#fmt["Initialized .cargo in %s", c.root]);
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
|
|
|
|
2011-12-20 19:41:23 -06:00
|
|
|
fn print_pkg(s: source, p: package) {
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut m = s.name + "/" + p.name + " (" + p.uuid + ")";
|
2011-12-20 19:41:23 -06:00
|
|
|
if vec::len(p.tags) > 0u {
|
|
|
|
m = m + " [" + str::connect(p.tags, ", ") + "]";
|
|
|
|
}
|
|
|
|
info(m);
|
2012-01-23 20:23:31 -06:00
|
|
|
if p.description != "" {
|
2012-01-23 21:50:32 -06:00
|
|
|
print(" >> " + p.description + "\n")
|
2012-01-23 20:23:31 -06:00
|
|
|
}
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
2012-02-05 03:30:03 -06:00
|
|
|
fn cmd_list(c: cargo) {
|
2011-12-20 19:41:23 -06:00
|
|
|
for_each_package(c, { |s, p|
|
2012-02-05 03:30:03 -06:00
|
|
|
if vec::len(c.opts.free) <= 2u || c.opts.free[2] == s.name {
|
2011-12-20 19:41:23 -06:00
|
|
|
print_pkg(s, p);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-02-05 03:30:03 -06:00
|
|
|
fn cmd_search(c: cargo) {
|
|
|
|
if vec::len(c.opts.free) < 3u {
|
2011-12-20 19:41:23 -06:00
|
|
|
cmd_usage();
|
|
|
|
ret;
|
|
|
|
}
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut n = 0;
|
2012-02-05 03:30:03 -06:00
|
|
|
let name = c.opts.free[2];
|
|
|
|
let tags = vec::slice(c.opts.free, 3u, vec::len(c.opts.free));
|
2011-12-20 19:41:23 -06:00
|
|
|
for_each_package(c, { |s, p|
|
|
|
|
if (str::contains(p.name, name) || name == "*") &&
|
2012-02-11 19:54:49 -06:00
|
|
|
vec::all(tags, { |t| vec::contains(p.tags, t) }) {
|
2011-12-20 19:41:23 -06:00
|
|
|
print_pkg(s, p);
|
|
|
|
n += 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
info(#fmt["Found %d packages.", n]);
|
|
|
|
}
|
|
|
|
|
2012-05-26 10:35:54 -05:00
|
|
|
fn install_to_dir(srcfile: str, destdir: str) {
|
|
|
|
let newfile = path::connect(destdir, path::basename(srcfile));
|
|
|
|
info(#fmt["Installing '%s'...", newfile]);
|
|
|
|
|
|
|
|
copy_warn(srcfile, newfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_warn(srcfile: str, destfile: str) {
|
|
|
|
if !os::copy_file(srcfile, destfile) {
|
|
|
|
warn(#fmt["Copying %s to %s failed", srcfile, destfile]);
|
2012-04-03 00:53:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-26 10:35:54 -05:00
|
|
|
// FIXME: decide on either [-g | -G] or [--mode=...] and remove the other
|
2011-11-30 17:57:46 -06:00
|
|
|
fn cmd_usage() {
|
2012-05-26 10:35:54 -05:00
|
|
|
print("Usage: cargo <verb> [options] [args...]\n" +
|
|
|
|
" e.g.: cargo [init | sync]\n" +
|
|
|
|
" e.g.: cargo install [-g | -G | --mode=MODE] ] [PACKAGE...]
|
|
|
|
|
|
|
|
Initialization:
|
|
|
|
init Set up the cargo system near this binary,
|
|
|
|
for example, at /usr/local/lib/cargo/
|
|
|
|
sync Sync all package sources
|
|
|
|
|
|
|
|
Querying:
|
|
|
|
list [source] List packages
|
|
|
|
search <name | '*'> [tags...] Search packages
|
|
|
|
usage Display this message
|
|
|
|
|
|
|
|
Package installation:
|
|
|
|
[options] [source/]PKGNAME Install a package by name
|
|
|
|
[options] uuid:[source/]PKGUUID Install a package by uuid
|
|
|
|
|
|
|
|
Package installation options:
|
|
|
|
--mode=MODE Install to one of the following locations:
|
|
|
|
local (./.cargo/bin/, which is the default),
|
|
|
|
user (~/.cargo/bin/), or system (/usr/local/lib/cargo/bin/)
|
|
|
|
--test Run crate tests before installing
|
|
|
|
-g Equivalent to --mode=user
|
|
|
|
-G Equivalent to --mode=system
|
|
|
|
|
|
|
|
Other:
|
|
|
|
-h, --help Display this message
|
2012-02-07 02:15:39 -06:00
|
|
|
");
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main(argv: [str]) {
|
2012-02-05 03:30:03 -06:00
|
|
|
let o = build_cargo_options(argv);
|
|
|
|
|
2012-05-26 10:35:54 -05:00
|
|
|
if vec::len(o.free) < 2u || o.help {
|
2011-11-30 17:57:46 -06:00
|
|
|
cmd_usage();
|
|
|
|
ret;
|
|
|
|
}
|
2012-02-05 03:30:03 -06:00
|
|
|
|
|
|
|
let c = configure(o);
|
|
|
|
|
|
|
|
alt o.free[1] {
|
2011-12-20 20:52:50 -06:00
|
|
|
"init" { cmd_init(c); }
|
2012-02-05 03:30:03 -06:00
|
|
|
"install" { cmd_install(c); }
|
|
|
|
"list" { cmd_list(c); }
|
|
|
|
"search" { cmd_search(c); }
|
|
|
|
"sync" { cmd_sync(c); }
|
2011-11-30 17:57:46 -06:00
|
|
|
"usage" { cmd_usage(); }
|
|
|
|
_ { cmd_usage(); }
|
|
|
|
}
|
|
|
|
}
|