2011-11-30 17:57:46 -06:00
|
|
|
// cargo.rs - Rust package manager
|
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
import syntax::{ast, codemap, parse, visit, attr};
|
|
|
|
import syntax::diagnostic::span_handler;
|
|
|
|
import codemap::span;
|
2012-05-29 22:38:46 -05:00
|
|
|
import rustc::metadata::filesearch::{get_cargo_root, get_cargo_root_nearest,
|
|
|
|
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-08-14 15:38:35 -05:00
|
|
|
import io::WriterUtil;
|
2012-06-02 01:25:56 -05:00
|
|
|
import std::{map, json, tempfile, term, sort, getopts};
|
|
|
|
import map::hashmap;
|
2012-07-11 17:00:40 -05:00
|
|
|
import to_str::to_str;
|
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 = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~str,
|
|
|
|
uuid: ~str,
|
|
|
|
url: ~str,
|
|
|
|
method: ~str,
|
|
|
|
description: ~str,
|
2012-07-31 21:25:24 -05:00
|
|
|
reference: option<~str>,
|
2012-07-14 00:57:48 -05:00
|
|
|
tags: ~[~str],
|
|
|
|
versions: ~[(~str, ~str)]
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
type local_package = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~str,
|
|
|
|
metaname: ~str,
|
|
|
|
version: ~str,
|
|
|
|
files: ~[~str]
|
2011-12-16 19:33:39 -06:00
|
|
|
};
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
type source = @{
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~str,
|
|
|
|
mut url: ~str,
|
|
|
|
mut method: ~str,
|
|
|
|
mut key: option<~str>,
|
|
|
|
mut keyfp: option<~str>,
|
2012-06-29 18:26:56 -05:00
|
|
|
mut packages: ~[mut 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,
|
2012-07-14 00:57:48 -05:00
|
|
|
root: ~str,
|
|
|
|
installdir: ~str,
|
|
|
|
bindir: ~str,
|
|
|
|
libdir: ~str,
|
|
|
|
workdir: ~str,
|
|
|
|
sourcedir: ~str,
|
|
|
|
sources: map::hashmap<~str, source>,
|
|
|
|
mut current_install: ~str,
|
|
|
|
dep_cache: map::hashmap<~str, bool>,
|
2012-02-05 03:30:03 -06:00
|
|
|
opts: options
|
2011-12-08 22:50:25 -06:00
|
|
|
};
|
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
type crate = {
|
2012-07-14 00:57:48 -05:00
|
|
|
name: ~str,
|
|
|
|
vers: ~str,
|
|
|
|
uuid: ~str,
|
|
|
|
desc: option<~str>,
|
|
|
|
sigs: option<~str>,
|
|
|
|
crate_type: option<~str>,
|
|
|
|
deps: ~[~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-07-14 00:57:48 -05: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-06-29 18:26:56 -05:00
|
|
|
fn opts() -> ~[getopts::opt] {
|
2012-07-14 00:57:48 -05:00
|
|
|
~[optflag(~"g"), optflag(~"G"), optflag(~"test"),
|
|
|
|
optflag(~"h"), optflag(~"help")]
|
2012-02-05 03:30:03 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn info(msg: ~str) {
|
2012-06-02 01:25:56 -05:00
|
|
|
let out = io::stdout();
|
|
|
|
|
|
|
|
if term::color_supported() {
|
|
|
|
term::fg(out, term::color_green);
|
2012-07-14 00:57:48 -05:00
|
|
|
out.write_str(~"info: ");
|
2012-06-02 01:25:56 -05:00
|
|
|
term::reset(out);
|
|
|
|
out.write_line(msg);
|
2012-07-14 00:57:48 -05:00
|
|
|
} else { out.write_line(~"info: " + msg); }
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn warn(msg: ~str) {
|
2012-06-02 01:25:56 -05:00
|
|
|
let out = io::stdout();
|
|
|
|
|
|
|
|
if term::color_supported() {
|
|
|
|
term::fg(out, term::color_yellow);
|
2012-07-14 00:57:48 -05:00
|
|
|
out.write_str(~"warning: ");
|
2012-06-02 01:25:56 -05:00
|
|
|
term::reset(out);
|
|
|
|
out.write_line(msg);
|
2012-07-14 00:57:48 -05:00
|
|
|
}else { out.write_line(~"warning: " + msg); }
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn error(msg: ~str) {
|
2012-06-02 01:25:56 -05:00
|
|
|
let out = io::stdout();
|
|
|
|
|
|
|
|
if term::color_supported() {
|
|
|
|
term::fg(out, term::color_red);
|
2012-07-14 00:57:48 -05:00
|
|
|
out.write_str(~"error: ");
|
2012-06-02 01:25:56 -05:00
|
|
|
term::reset(out);
|
|
|
|
out.write_line(msg);
|
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
else { out.write_line(~"error: " + msg); }
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn is_uuid(id: ~str) -> bool {
|
|
|
|
let parts = str::split_str(id, ~"-");
|
2012-06-02 01:25:56 -05:00
|
|
|
if vec::len(parts) == 5u {
|
|
|
|
let mut correct = 0u;
|
2012-06-30 18:19:07 -05:00
|
|
|
for vec::eachi(parts) |i, part| {
|
2012-06-09 19:26:02 -05:00
|
|
|
fn is_hex_digit(ch: char) -> bool {
|
|
|
|
('0' <= ch && ch <= '9') ||
|
|
|
|
('a' <= ch && ch <= 'f') ||
|
|
|
|
('A' <= ch && ch <= 'F')
|
|
|
|
}
|
2012-06-03 01:55:32 -05:00
|
|
|
|
|
|
|
if !part.all(is_hex_digit) {
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-03 01:55:32 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match i {
|
2012-08-03 21:59:04 -05:00
|
|
|
0u => {
|
2012-06-02 01:25:56 -05:00
|
|
|
if str::len(part) == 8u {
|
|
|
|
correct += 1u;
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
1u | 2u | 3u => {
|
2012-06-02 01:25:56 -05:00
|
|
|
if str::len(part) == 4u {
|
|
|
|
correct += 1u;
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
4u => {
|
2012-06-02 01:25:56 -05:00
|
|
|
if str::len(part) == 12u {
|
|
|
|
correct += 1u;
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => { }
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if correct >= 5u {
|
2012-08-01 19:30:05 -05:00
|
|
|
return true;
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
|
2012-06-03 01:30:11 -05:00
|
|
|
#[test]
|
|
|
|
fn test_is_uuid() {
|
2012-07-14 00:57:48 -05:00
|
|
|
assert is_uuid(~"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaafAF09");
|
|
|
|
assert !is_uuid(~"aaaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaaaaaa");
|
|
|
|
assert !is_uuid(~"");
|
|
|
|
assert !is_uuid(~"aaaaaaaa-aaa -aaaa-aaaa-aaaaaaaaaaaa");
|
|
|
|
assert !is_uuid(~"aaaaaaaa-aaa!-aaaa-aaaa-aaaaaaaaaaaa");
|
|
|
|
assert !is_uuid(~"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-a");
|
|
|
|
assert !is_uuid(~"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaป");
|
2012-06-03 01:30:11 -05:00
|
|
|
}
|
|
|
|
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2661): implement url/URL parsing so we don't have to resort
|
|
|
|
// to weak checks
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn has_archive_extension(p: ~str) -> bool {
|
|
|
|
str::ends_with(p, ~".tar") ||
|
|
|
|
str::ends_with(p, ~".tar.gz") ||
|
|
|
|
str::ends_with(p, ~".tar.bz2") ||
|
|
|
|
str::ends_with(p, ~".tar.Z") ||
|
|
|
|
str::ends_with(p, ~".tar.lz") ||
|
|
|
|
str::ends_with(p, ~".tar.xz") ||
|
|
|
|
str::ends_with(p, ~".tgz") ||
|
|
|
|
str::ends_with(p, ~".tbz") ||
|
|
|
|
str::ends_with(p, ~".tbz2") ||
|
|
|
|
str::ends_with(p, ~".tb2") ||
|
|
|
|
str::ends_with(p, ~".taz") ||
|
|
|
|
str::ends_with(p, ~".tlz") ||
|
|
|
|
str::ends_with(p, ~".txz")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_archive_path(u: ~str) -> bool {
|
2012-06-09 19:26:02 -05:00
|
|
|
has_archive_extension(u) && os::path_exists(u)
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn is_archive_url(u: ~str) -> bool {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2661): this requires the protocol bit - if we had proper
|
|
|
|
// url parsing, we wouldn't need it
|
2012-06-02 01:25:56 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match str::find_str(u, ~"://") {
|
2012-08-03 21:59:04 -05:00
|
|
|
option::some(i) => has_archive_extension(u),
|
|
|
|
_ => false
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn is_git_url(url: ~str) -> bool {
|
|
|
|
if str::ends_with(url, ~"/") { str::ends_with(url, ~".git/") }
|
2012-06-02 01:25:56 -05:00
|
|
|
else {
|
2012-07-14 00:57:48 -05:00
|
|
|
str::starts_with(url, ~"git://") || str::ends_with(url, ~".git")
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn assume_source_method(url: ~str) -> ~str {
|
2012-06-09 19:26:02 -05:00
|
|
|
if is_git_url(url) {
|
2012-08-01 19:30:05 -05:00
|
|
|
return ~"git";
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
if str::starts_with(url, ~"file://") || os::path_exists(url) {
|
2012-08-01 19:30:05 -05:00
|
|
|
return ~"file";
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
~"curl"
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05: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-06-30 18:19:07 -05:00
|
|
|
for mis.each |a| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match a.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
|
2012-07-18 18:18:02 -05:00
|
|
|
match v {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"name" => name = some(*s),
|
|
|
|
~"vers" => vers = some(*s),
|
|
|
|
~"uuid" => uuid = some(*s),
|
|
|
|
_ => { }
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => fail ~"load_link: meta items must be name-values"
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
(name, vers, uuid)
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn load_crate(filename: ~str) -> option<crate> {
|
2012-06-06 11:50:08 -05:00
|
|
|
let sess = parse::new_parse_sess(none);
|
2012-06-29 18:26:56 -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-06-30 18:19:07 -05:00
|
|
|
for c.node.attrs.each |a| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match a.node.value.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
|
2012-07-18 18:18:02 -05:00
|
|
|
match v {
|
|
|
|
~"desc" => desc = some(v),
|
|
|
|
~"sigs" => sigs = some(v),
|
|
|
|
~"crate_type" => crate_type = some(v),
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => { }
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::meta_list(v, mis) => {
|
2012-07-18 18:18:02 -05:00
|
|
|
if v == ~"link" {
|
2011-11-30 17:57:46 -06:00
|
|
|
let (n, v, u) = load_link(mis);
|
|
|
|
name = n;
|
|
|
|
vers = v;
|
|
|
|
uuid = u;
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
2012-07-14 00:57:48 -05:00
|
|
|
fail ~"crate attributes may not contain " +
|
|
|
|
~"meta_words";
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
type env = @{
|
2012-07-14 00:57:48 -05:00
|
|
|
mut deps: ~[~str]
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn goto_view_item(ps: syntax::parse::parse_sess, e: env,
|
|
|
|
i: @ast::view_item) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match i.node {
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::view_item_use(ident, metas, id) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
let name_items =
|
|
|
|
attr::find_meta_items_by_name(metas, ~"name");
|
2012-06-09 19:26:02 -05:00
|
|
|
let m = if name_items.is_empty() {
|
2012-07-18 18:18:02 -05:00
|
|
|
metas + ~[attr::mk_name_value_item_str(
|
|
|
|
~"name", *ps.interner.get(ident))]
|
2012-06-09 19:26:02 -05:00
|
|
|
} else {
|
|
|
|
metas
|
|
|
|
};
|
|
|
|
let mut attr_name = ident;
|
2012-07-14 00:57:48 -05:00
|
|
|
let mut attr_vers = ~"";
|
|
|
|
let mut attr_from = ~"";
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
for m.each |item| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match attr::get_meta_item_value_str(item) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(value) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
let name = attr::get_meta_item_name(item);
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
match name {
|
|
|
|
~"vers" => attr_vers = value,
|
|
|
|
~"from" => attr_from = value,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => ()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let query = if !str::is_empty(attr_from) {
|
|
|
|
attr_from
|
|
|
|
} else {
|
|
|
|
if !str::is_empty(attr_vers) {
|
2012-07-18 18:18:02 -05:00
|
|
|
ps.interner.get(attr_name) + ~"@" + attr_vers
|
|
|
|
} else { *ps.interner.get(attr_name) }
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
match *ps.interner.get(attr_name) {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"std" | ~"core" => (),
|
|
|
|
_ => vec::push(e.deps, query)
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn goto_item(_e: env, _i: @ast::item) {
|
|
|
|
}
|
|
|
|
|
|
|
|
let e = @{
|
2012-06-29 18:26:56 -05:00
|
|
|
mut deps: ~[]
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
let v = visit::mk_simple_visitor(@{
|
2012-07-18 18:18:02 -05:00
|
|
|
visit_view_item: |a| goto_view_item(sess, e, a),
|
2012-06-30 18:19:07 -05:00
|
|
|
visit_item: |a| goto_item(e, a),
|
2012-06-09 19:26:02 -05:00
|
|
|
with *visit::default_simple_visitor()
|
|
|
|
});
|
|
|
|
|
|
|
|
visit::visit_crate(*c, (), v);
|
|
|
|
|
|
|
|
let deps = copy e.deps;
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match (name, vers, uuid) {
|
2012-08-03 21:59:04 -05:00
|
|
|
(some(name0), some(vers0), some(uuid0)) => {
|
2011-11-30 17:57:46 -06:00
|
|
|
some({
|
2012-06-09 23:01:11 -05:00
|
|
|
name: name0,
|
|
|
|
vers: vers0,
|
|
|
|
uuid: uuid0,
|
|
|
|
desc: desc,
|
|
|
|
sigs: sigs,
|
|
|
|
crate_type: crate_type,
|
|
|
|
deps: deps })
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => return none
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn print(s: ~str) {
|
2011-11-30 17:57:46 -06:00
|
|
|
io::stdout().write_line(s);
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn rest(s: ~str, start: uint) -> ~str {
|
2012-02-23 03:44:04 -06:00
|
|
|
if (start >= str::len(s)) {
|
2012-07-14 00:57:48 -05:00
|
|
|
~""
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn need_dir(s: ~str) {
|
2012-08-01 19:30:05 -05:00
|
|
|
if os::path_is_dir(s) { return; }
|
2012-05-26 10:35:54 -05:00
|
|
|
if !os::make_dir(s, 493_i32 /* oct: 755 */) {
|
2012-08-22 19:24:52 -05:00
|
|
|
fail fmt!("can't make_dir %s", s);
|
2011-12-08 22:41:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn valid_pkg_name(s: ~str) -> bool {
|
2012-06-09 19:26:02 -05:00
|
|
|
fn is_valid_digit(c: char) -> bool {
|
|
|
|
('0' <= c && c <= '9') ||
|
|
|
|
('a' <= c && c <= 'z') ||
|
|
|
|
('A' <= c && c <= 'Z') ||
|
|
|
|
c == '-' ||
|
|
|
|
c == '_'
|
|
|
|
}
|
|
|
|
|
|
|
|
s.all(is_valid_digit)
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_source(name: ~str, j: json::json) -> source {
|
2012-06-09 19:26:02 -05:00
|
|
|
if !valid_pkg_name(name) {
|
2012-08-22 19:24:52 -05:00
|
|
|
fail fmt!("'%s' is an invalid source name", name);
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match j {
|
2012-08-03 21:59:04 -05:00
|
|
|
json::dict(j) => {
|
2012-08-06 14:34:08 -05:00
|
|
|
let mut url = match j.find(~"url") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(u)) => *u,
|
|
|
|
_ => fail ~"needed 'url' field in source"
|
2011-12-16 19:33:39 -06:00
|
|
|
};
|
2012-08-06 14:34:08 -05:00
|
|
|
let method = match j.find(~"method") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(u)) => *u,
|
|
|
|
_ => assume_source_method(url)
|
2011-12-20 18:59:37 -06:00
|
|
|
};
|
2012-08-06 14:34:08 -05:00
|
|
|
let key = match j.find(~"key") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(u)) => some(*u),
|
|
|
|
_ => none
|
2011-12-20 18:59:37 -06:00
|
|
|
};
|
2012-08-06 14:34:08 -05:00
|
|
|
let keyfp = match j.find(~"keyfp") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(u)) => some(*u),
|
|
|
|
_ => none
|
2011-12-20 18:59:37 -06:00
|
|
|
};
|
2012-07-14 00:57:48 -05:00
|
|
|
if method == ~"file" {
|
2012-06-09 19:26:02 -05:00
|
|
|
url = os::make_absolute(url);
|
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return @{
|
2012-06-09 23:01:11 -05:00
|
|
|
name: name,
|
|
|
|
mut url: url,
|
|
|
|
mut method: method,
|
|
|
|
mut key: key,
|
|
|
|
mut keyfp: keyfp,
|
2012-06-29 18:26:56 -05:00
|
|
|
mut packages: ~[mut] };
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => fail ~"needed dict value in source"
|
2011-12-16 19:33:39 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) {
|
2012-08-01 19:30:05 -05:00
|
|
|
if !os::path_exists(filename) { return; }
|
2011-12-16 19:33:39 -06:00
|
|
|
let c = io::read_whole_file_str(filename);
|
2012-08-06 14:34:08 -05:00
|
|
|
match json::from_str(result::get(c)) {
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(json::dict(j)) => {
|
2012-06-30 18:19:07 -05:00
|
|
|
for j.each |k, v| {
|
2011-12-16 19:33:39 -06:00
|
|
|
sources.insert(k, parse_source(k, v));
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("source: %s", k);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(_) => fail ~"malformed sources.json",
|
2012-08-22 19:24:52 -05:00
|
|
|
err(e) => fail fmt!("%s:%s", filename, e.to_str())
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
|
2012-08-06 14:34:08 -05:00
|
|
|
let name = match p.find(~"name") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(n)) => {
|
2012-06-12 19:20:51 -05:00
|
|
|
if !valid_pkg_name(*n) {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source json: "
|
|
|
|
+ src.name + ~", '" + *n + ~"'"+
|
|
|
|
~" is an invalid name (alphanumeric, underscores and" +
|
|
|
|
~" dashes only)");
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-06-12 19:20:51 -05:00
|
|
|
*n
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source json: " + src.name + ~" (missing name)");
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let uuid = match p.find(~"uuid") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(n)) => {
|
2012-06-12 19:20:51 -05:00
|
|
|
if !is_uuid(*n) {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source json: "
|
|
|
|
+ src.name + ~", '" + *n + ~"'"+
|
|
|
|
~" is an invalid uuid");
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-06-12 19:20:51 -05:00
|
|
|
*n
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source json: " + src.name + ~" (missing uuid)");
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let url = match p.find(~"url") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(n)) => *n,
|
|
|
|
_ => {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source json: " + src.name + ~" (missing url)");
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let method = match p.find(~"method") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(n)) => *n,
|
|
|
|
_ => {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source json: "
|
|
|
|
+ src.name + ~" (missing method)");
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let reference = match p.find(~"ref") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(n)) => some(*n),
|
|
|
|
_ => none
|
2011-12-20 22:41:22 -06:00
|
|
|
};
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut tags = ~[];
|
2012-08-06 14:34:08 -05:00
|
|
|
match p.find(~"tags") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::list(js)) => {
|
2012-06-30 18:19:07 -05:00
|
|
|
for (*js).each |j| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match j {
|
2012-08-03 21:59:04 -05:00
|
|
|
json::string(j) => vec::grow(tags, 1u, *j),
|
|
|
|
_ => ()
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
2012-01-23 21:42:29 -06:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let description = match p.find(~"description") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(json::string(n)) => *n,
|
|
|
|
_ => {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source json: " + src.name
|
|
|
|
+ ~" (missing description)");
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-01-23 21:42:29 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
let newpkg = {
|
2012-06-09 23:01:11 -05:00
|
|
|
name: name,
|
|
|
|
uuid: uuid,
|
|
|
|
url: url,
|
|
|
|
method: method,
|
|
|
|
description: description,
|
2012-07-31 21:25:24 -05:00
|
|
|
reference: reference,
|
2012-06-09 23:01:11 -05:00
|
|
|
tags: tags,
|
2012-06-29 18:26:56 -05:00
|
|
|
versions: ~[]
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match vec::position(src.packages, |pkg| pkg.uuid == uuid) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(idx) => {
|
2012-06-09 23:01:11 -05:00
|
|
|
src.packages[idx] = newpkg;
|
2012-07-14 00:57:48 -05:00
|
|
|
log(debug, ~" updated package: " + src.name + ~"/" + name);
|
2012-06-09 23:01:11 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-06-09 23:01:11 -05:00
|
|
|
vec::grow(src.packages, 1u, newpkg);
|
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
log(debug, ~" loaded package: " + src.name + ~"/" + name);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn load_source_info(c: cargo, src: source) {
|
2012-06-09 19:26:02 -05:00
|
|
|
let dir = path::connect(c.sourcedir, src.name);
|
2012-07-14 00:57:48 -05:00
|
|
|
let srcfile = path::connect(dir, ~"source.json");
|
2012-08-01 19:30:05 -05:00
|
|
|
if !os::path_exists(srcfile) { return; }
|
2012-06-09 19:26:02 -05:00
|
|
|
let srcstr = io::read_whole_file_str(srcfile);
|
2012-08-06 14:34:08 -05:00
|
|
|
match json::from_str(result::get(srcstr)) {
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(json::dict(s)) => {
|
2012-06-13 11:34:43 -05:00
|
|
|
let o = parse_source(src.name, json::dict(s));
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
src.key = o.key;
|
|
|
|
src.keyfp = o.keyfp;
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(_) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source.json: " + src.name +
|
|
|
|
~"(source info is not a dict)");
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
err(e) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
warn(fmt!("%s:%s", src.name, e.to_str()));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2012-06-09 23:01:11 -05:00
|
|
|
fn load_source_packages(c: cargo, src: source) {
|
2012-07-14 00:57:48 -05:00
|
|
|
log(debug, ~"loading source: " + src.name);
|
2012-03-12 22:04:27 -05:00
|
|
|
let dir = path::connect(c.sourcedir, src.name);
|
2012-07-14 00:57:48 -05:00
|
|
|
let pkgfile = path::connect(dir, ~"packages.json");
|
2012-08-01 19:30:05 -05:00
|
|
|
if !os::path_exists(pkgfile) { return; }
|
2011-12-16 19:33:39 -06:00
|
|
|
let pkgstr = io::read_whole_file_str(pkgfile);
|
2012-08-06 14:34:08 -05:00
|
|
|
match json::from_str(result::get(pkgstr)) {
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(json::list(js)) => {
|
2012-06-30 18:19:07 -05:00
|
|
|
for (*js).each |j| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match j {
|
2012-08-03 21:59:04 -05:00
|
|
|
json::dict(p) => {
|
2012-06-11 10:19:49 -05:00
|
|
|
load_one_source_package(src, p);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed source json: " + src.name +
|
|
|
|
~" (non-dict pkg)");
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(_) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"malformed packages.json: " + src.name +
|
|
|
|
~"(packages is not a list)");
|
2012-02-25 18:39:32 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
err(e) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
warn(fmt!("%s:%s", src.name, e.to_str()));
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn build_cargo_options(argv: ~[~str]) -> options {
|
2012-08-06 14:34:08 -05:00
|
|
|
let matches = match getopts::getopts(argv, opts()) {
|
2012-08-03 21:59:04 -05:00
|
|
|
result::ok(m) => m,
|
|
|
|
result::err(f) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
fail fmt!("%s", getopts::fail_str(f));
|
2012-02-05 03:30:03 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-31 18:38:41 -05:00
|
|
|
let test = opt_present(matches, ~"test");
|
|
|
|
let G = opt_present(matches, ~"G");
|
|
|
|
let g = opt_present(matches, ~"g");
|
|
|
|
let help = opt_present(matches, ~"h") || opt_present(matches, ~"help");
|
|
|
|
let len = vec::len(matches.free);
|
2012-05-26 10:35:54 -05:00
|
|
|
|
2012-07-31 18:38:41 -05:00
|
|
|
let is_install = len > 1u && matches.free[1] == ~"install";
|
|
|
|
let is_uninstall = len > 1u && matches.free[1] == ~"uninstall";
|
2012-02-20 02:08:58 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
if G && g { fail ~"-G and -g both provided"; }
|
2012-02-20 02:08:58 -06:00
|
|
|
|
2012-06-02 01:25:56 -05:00
|
|
|
if !is_install && !is_uninstall && (g || G) {
|
2012-07-14 00:57:48 -05:00
|
|
|
fail ~"-g and -G are only valid for `install` and `uninstall|rm`";
|
2012-05-26 10:35:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let mode =
|
2012-06-02 01:25:56 -05:00
|
|
|
if (!is_install && !is_uninstall) || g { user_mode }
|
|
|
|
else if G { system_mode }
|
|
|
|
else { local_mode };
|
2012-02-09 15:42:59 -06:00
|
|
|
|
2012-07-31 18:38:41 -05:00
|
|
|
{test: test, mode: mode, free: matches.free, help: help}
|
2012-02-05 03:30:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn configure(opts: options) -> cargo {
|
2012-08-06 14:34:08 -05:00
|
|
|
let home = match get_cargo_root() {
|
2012-08-03 21:59:04 -05:00
|
|
|
ok(home) => home,
|
|
|
|
err(_err) => result::get(get_cargo_sysroot())
|
2012-06-02 01:25:56 -05:00
|
|
|
};
|
2012-05-26 10:35:54 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let get_cargo_dir = match opts.mode {
|
2012-08-03 21:59:04 -05:00
|
|
|
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-06-13 11:34:43 -05:00
|
|
|
let sources = map::str_hash();
|
2012-07-14 00:57:48 -05:00
|
|
|
try_parse_sources(path::connect(home, ~"sources.json"), sources);
|
|
|
|
try_parse_sources(path::connect(home, ~"local-sources.json"), sources);
|
2012-05-26 10:35:54 -05:00
|
|
|
|
2012-06-13 11:34:43 -05:00
|
|
|
let dep_cache = map::str_hash();
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut c = {
|
2011-12-20 18:59:37 -06:00
|
|
|
pgp: pgp::supported(),
|
2012-06-02 01:25:56 -05:00
|
|
|
root: home,
|
|
|
|
installdir: p,
|
2012-07-14 00:57:48 -05:00
|
|
|
bindir: path::connect(p, ~"bin"),
|
|
|
|
libdir: path::connect(p, ~"lib"),
|
|
|
|
workdir: path::connect(p, ~"work"),
|
|
|
|
sourcedir: path::connect(home, ~"sources"),
|
2012-01-18 21:16:14 -06:00
|
|
|
sources: sources,
|
2012-07-14 00:57:48 -05:00
|
|
|
mut current_install: ~"",
|
2012-06-09 19:26:02 -05:00
|
|
|
dep_cache: dep_cache,
|
2012-02-05 03:30:03 -06:00
|
|
|
opts: opts
|
2011-12-08 22:50:25 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
need_dir(c.root);
|
2012-06-13 11:35:10 -05:00
|
|
|
need_dir(c.installdir);
|
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-06-30 18:19:07 -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 {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"command `gpg` was 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-06-09 23:01:11 -05:00
|
|
|
fn for_each_package(c: cargo, b: fn(source, package)) {
|
2012-06-30 18:19:07 -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;
|
2012-06-30 18:19:07 -05:00
|
|
|
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>
|
2012-07-14 00:57:48 -05:00
|
|
|
fn run_programs(buildpath: ~str) {
|
2012-04-01 10:39:17 -05:00
|
|
|
let newv = os::list_dir_path(buildpath);
|
2012-06-30 18:19:07 -05:00
|
|
|
for newv.each |ct| {
|
2012-06-29 18:26:56 -05: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>
|
2012-07-14 00:57:48 -05:00
|
|
|
fn run_in_buildpath(what: ~str, path: ~str, subdir: ~str, cf: ~str,
|
|
|
|
extra_flags: ~[~str]) -> option<~str> {
|
2012-03-15 16:03:30 -05:00
|
|
|
let buildpath = path::connect(path, subdir);
|
2012-01-18 21:16:14 -06:00
|
|
|
need_dir(buildpath);
|
2012-08-22 19:24:52 -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-07-14 00:57:48 -05:00
|
|
|
~[~"--out-dir", buildpath, cf] + extra_flags);
|
2012-01-18 21:16:14 -06:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("rustc failed: %d\n%s\n%s", p.status, p.err, p.out));
|
2012-08-01 19:30:05 -05:00
|
|
|
return none;
|
2012-01-18 21:16:14 -06:00
|
|
|
}
|
2012-03-15 16:03:30 -05:00
|
|
|
some(buildpath)
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
|
2012-08-06 14:34:08 -05:00
|
|
|
let buildpath = match run_in_buildpath(~"testing", path, ~"/test", cf,
|
2012-07-14 00:57:48 -05:00
|
|
|
~[ ~"--test"]) {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => return,
|
|
|
|
some(bp) => bp
|
2012-03-15 16:03:30 -05:00
|
|
|
};
|
|
|
|
run_programs(buildpath);
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
|
2012-08-06 14:34:08 -05:00
|
|
|
let buildpath = match run_in_buildpath(~"installing", path,
|
2012-07-14 00:57:48 -05:00
|
|
|
~"/build", cf, ~[]) {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => return,
|
|
|
|
some(bp) => bp
|
2012-03-15 16:03:30 -05:00
|
|
|
};
|
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-06-30 18:19:07 -05:00
|
|
|
for newv.each |ct| {
|
2012-07-14 00:57:48 -05:00
|
|
|
if (exec_suffix != ~"" && str::ends_with(ct, exec_suffix)) ||
|
|
|
|
(exec_suffix == ~"" && !str::starts_with(path::basename(ct),
|
|
|
|
~"lib")) {
|
2012-08-22 19:24:52 -05: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 {
|
2012-07-05 16:17:16 -05:00
|
|
|
// FIXME (#2662): Put this file in PATH / symlink it so it can
|
|
|
|
// be used as a generic executable
|
2012-06-02 01:25:56 -05:00
|
|
|
// `cargo install -G rustray` and `rustray file.obj`
|
2012-02-20 02:33:50 -06:00
|
|
|
}
|
2011-12-08 22:41:29 -06:00
|
|
|
} else {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!(" lib: %s", ct);
|
2012-05-28 19:54:47 -05:00
|
|
|
install_to_dir(ct, c.libdir);
|
2012-02-20 02:33:50 -06:00
|
|
|
}
|
2012-07-06 11:35:43 -05:00
|
|
|
}
|
2012-02-20 02:33:50 -06:00
|
|
|
}
|
|
|
|
|
2011-12-08 22:41:29 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn rustc_sysroot() -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match os::self_exe_path() {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(path) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
let path = ~[path, ~"..", ~"bin", ~"rustc"];
|
2012-03-12 22:04:27 -05:00
|
|
|
let rustc = path::normalize(path::connect_many(path));
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!(" rustc: %s", rustc);
|
2012-02-13 18:33:59 -06:00
|
|
|
rustc
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => ~"rustc"
|
2012-02-13 18:33:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_source(c: cargo, path: ~str) {
|
2012-08-22 19:24:52 -05: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-06-29 18:26:56 -05:00
|
|
|
let mut cratefiles = ~[];
|
2012-07-14 00:57:48 -05:00
|
|
|
for os::walk_dir(~".") |p| {
|
|
|
|
if str::ends_with(p, ~".rc") {
|
2012-06-15 20:16:42 -05:00
|
|
|
vec::push(cratefiles, p);
|
2012-04-21 17:46:05 -05:00
|
|
|
}
|
|
|
|
}
|
2011-12-01 21:37:56 -06:00
|
|
|
|
2011-12-08 22:41:29 -06:00
|
|
|
if vec::is_empty(cratefiles) {
|
2012-07-14 00:57:48 -05:00
|
|
|
fail ~"this doesn't look like a rust package (no .rc files)";
|
2011-12-01 21:37:56 -06:00
|
|
|
}
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
for cratefiles.each |cf| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match load_crate(cf) {
|
2012-08-03 21:59:04 -05:00
|
|
|
none => again,
|
|
|
|
some(crate) => {
|
2012-06-30 18:19:07 -05:00
|
|
|
for crate.deps.each |query| {
|
2012-07-05 16:17:16 -05:00
|
|
|
// FIXME (#1356): handle cyclic dependencies
|
|
|
|
// (n.b. #1356 says "Cyclic dependency is an error
|
|
|
|
// condition")
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
let wd_base = c.workdir + path::path_sep();
|
2012-08-06 14:34:08 -05:00
|
|
|
let wd = match tempfile::mkdtemp(wd_base, ~"") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(wd) => wd,
|
2012-08-22 19:24:52 -05:00
|
|
|
none => fail fmt!("needed temp dir: %s", wd_base)
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
install_query(c, wd, query);
|
2012-07-06 11:35:43 -05:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
os::change_dir(path);
|
|
|
|
|
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-07-31 21:25:24 -05:00
|
|
|
fn install_git(c: cargo, wd: ~str, url: ~str, reference: option<~str>) {
|
2012-07-14 00:57:48 -05:00
|
|
|
run::program_output(~"git", ~[~"clone", url, wd]);
|
2012-07-31 21:25:24 -05:00
|
|
|
if option::is_some(reference) {
|
|
|
|
let r = option::get(reference);
|
2012-03-12 22:04:27 -05:00
|
|
|
os::change_dir(wd);
|
2012-07-14 00:57:48 -05:00
|
|
|
run::run_program(~"git", ~[~"checkout", r]);
|
2011-12-20 22:41:22 -06:00
|
|
|
}
|
|
|
|
|
2011-12-08 23:39:41 -06:00
|
|
|
install_source(c, wd);
|
2011-12-08 23:34:06 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_curl(c: cargo, wd: ~str, url: ~str) {
|
|
|
|
let tarpath = path::connect(wd, ~"pkg.tar");
|
|
|
|
let p = run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o",
|
2012-06-29 18:26:56 -05:00
|
|
|
tarpath, url]);
|
2011-12-16 21:08:25 -06:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
fail fmt!("fetch of %s failed: %s", url, p.err);
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
run::run_program(~"tar", ~[~"-x", ~"--strip-components=1",
|
|
|
|
~"-C", wd, ~"-f", tarpath]);
|
2011-12-16 21:27:04 -06:00
|
|
|
install_source(c, wd);
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_file(c: cargo, wd: ~str, path: ~str) {
|
|
|
|
run::program_output(~"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
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
|
2012-06-09 19:26:02 -05:00
|
|
|
let url = copy pkg.url;
|
2012-08-06 14:34:08 -05:00
|
|
|
let method = match pkg.method {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"git" => ~"git",
|
|
|
|
~"file" => ~"file",
|
|
|
|
_ => ~"curl"
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("installing %s/%s via %s...", src, pkg.name, method));
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match method {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"git" => install_git(c, wd, url, copy pkg.reference),
|
|
|
|
~"file" => install_file(c, wd, url),
|
|
|
|
~"curl" => install_curl(c, wd, copy url),
|
|
|
|
_ => ()
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn cargo_suggestion(c: cargo, fallback: fn())
|
2012-01-24 10:08:58 -06:00
|
|
|
{
|
|
|
|
if c.sources.size() == 0u {
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"no sources defined - you may wish to run " +
|
|
|
|
~"`cargo init`");
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-01-24 10:08:58 -06:00
|
|
|
}
|
|
|
|
fallback();
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_uuid(c: cargo, wd: ~str, uuid: ~str) {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut ps = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for_each_package(c, |s, p| {
|
2011-12-16 19:33:39 -06:00
|
|
|
if p.uuid == uuid {
|
2012-06-09 19:26:02 -05:00
|
|
|
vec::grow(ps, 1u, (s.name, copy p));
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
});
|
2011-12-16 21:08:25 -06:00
|
|
|
if vec::len(ps) == 1u {
|
2012-06-09 19:26:02 -05:00
|
|
|
let (sname, p) = copy ps[0];
|
|
|
|
install_package(c, sname, wd, p);
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-16 21:08:25 -06:00
|
|
|
} else if vec::len(ps) == 0u {
|
2012-06-30 18:19:07 -05:00
|
|
|
cargo_suggestion(c, || {
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"can't find package: " + uuid);
|
2012-06-02 03:11:31 -05:00
|
|
|
});
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"found multiple packages:");
|
2012-06-30 18:19:07 -05:00
|
|
|
for ps.each |elt| {
|
2012-06-09 19:26:02 -05:00
|
|
|
let (sname,p) = copy elt;
|
2012-07-14 00:57:48 -05:00
|
|
|
info(~" " + sname + ~"/" + p.uuid + ~" (" + p.name + ~")");
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
2011-12-15 19:27:55 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_named(c: cargo, wd: ~str, name: ~str) {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut ps = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for_each_package(c, |s, p| {
|
2011-12-16 19:33:39 -06:00
|
|
|
if p.name == name {
|
2012-06-09 19:26:02 -05:00
|
|
|
vec::grow(ps, 1u, (s.name, copy p));
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
});
|
2011-12-16 21:08:25 -06:00
|
|
|
if vec::len(ps) == 1u {
|
2012-06-09 19:26:02 -05:00
|
|
|
let (sname, p) = copy ps[0];
|
|
|
|
install_package(c, sname, wd, p);
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-16 21:08:25 -06:00
|
|
|
} else if vec::len(ps) == 0u {
|
2012-06-30 18:19:07 -05:00
|
|
|
cargo_suggestion(c, || {
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"can't find package: " + name);
|
2012-06-02 03:11:31 -05:00
|
|
|
});
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"found multiple packages:");
|
2012-06-30 18:19:07 -05:00
|
|
|
for ps.each |elt| {
|
2012-06-09 19:26:02 -05:00
|
|
|
let (sname,p) = copy elt;
|
2012-07-14 00:57:48 -05:00
|
|
|
info(~" " + sname + ~"/" + p.uuid + ~" (" + p.name + ~")");
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.sources.find(src) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(s) => {
|
2012-05-18 12:40:54 -05:00
|
|
|
let packages = copy s.packages;
|
2012-06-30 18:19:07 -05:00
|
|
|
if vec::any(packages, |p| {
|
2012-05-18 12:40:54 -05:00
|
|
|
if p.uuid == uuid {
|
2012-06-09 19:26:02 -05:00
|
|
|
install_package(c, src, wd, p);
|
2012-05-18 12:40:54 -05:00
|
|
|
true
|
|
|
|
} else { false }
|
2012-08-01 19:30:05 -05:00
|
|
|
}) { return; }
|
2012-05-18 12:40:54 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"can't find package: " + src + ~"/" + uuid);
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.sources.find(src) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(s) => {
|
2012-05-18 12:40:54 -05:00
|
|
|
let packages = copy s.packages;
|
2012-06-30 18:19:07 -05:00
|
|
|
if vec::any(packages, |p| {
|
2011-12-16 21:08:25 -06:00
|
|
|
if p.name == name {
|
2012-06-09 19:26:02 -05:00
|
|
|
install_package(c, src, wd, p);
|
2012-03-26 06:16:29 -05:00
|
|
|
true
|
|
|
|
} else { false }
|
2012-08-01 19:30:05 -05:00
|
|
|
}) { return; }
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"can't find package: " + src + ~"/" + name);
|
2011-12-15 19:27:55 -06:00
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn cmd_uninstall(c: cargo) {
|
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();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
|
2012-06-02 03:46:08 -05:00
|
|
|
let lib = c.libdir;
|
|
|
|
let bin = c.bindir;
|
2012-06-02 01:25:56 -05:00
|
|
|
let target = c.opts.free[2u];
|
|
|
|
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2662): needs stronger pattern matching
|
|
|
|
// FIXME (#2662): needs to uninstall from a specified location in a
|
|
|
|
// cache instead of looking for it (binaries can be uninstalled by
|
|
|
|
// name only)
|
2012-06-02 01:25:56 -05:00
|
|
|
if is_uuid(target) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for os::list_dir(lib).each |file| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match str::find_str(file, ~"-" + target + ~"-") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(idx) => {
|
2012-06-02 03:46:08 -05:00
|
|
|
let full = path::normalize(path::connect(lib, file));
|
2012-06-02 01:25:56 -05:00
|
|
|
if os::remove_file(full) {
|
2012-07-14 00:57:48 -05:00
|
|
|
info(~"uninstalled: '" + full + ~"'");
|
2012-06-02 01:25:56 -05:00
|
|
|
} else {
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"could not uninstall: '" + full + ~"'");
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => again
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"can't find package with uuid: " + target);
|
2012-06-02 01:25:56 -05:00
|
|
|
} else {
|
2012-06-30 18:19:07 -05:00
|
|
|
for os::list_dir(lib).each |file| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match str::find_str(file, ~"lib" + target + ~"-") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(idx) => {
|
2012-06-02 03:46:08 -05:00
|
|
|
let full = path::normalize(path::connect(lib,
|
|
|
|
file));
|
|
|
|
if os::remove_file(full) {
|
2012-07-14 00:57:48 -05:00
|
|
|
info(~"uninstalled: '" + full + ~"'");
|
2012-06-02 03:46:08 -05:00
|
|
|
} else {
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"could not uninstall: '" + full + ~"'");
|
2012-06-02 03:46:08 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-02 03:46:08 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => again
|
2012-06-02 03:46:08 -05:00
|
|
|
}
|
|
|
|
}
|
2012-06-30 18:19:07 -05:00
|
|
|
for os::list_dir(bin).each |file| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match str::find_str(file, target) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(idx) => {
|
2012-06-02 03:46:08 -05:00
|
|
|
let full = path::normalize(path::connect(bin, file));
|
2012-06-02 01:25:56 -05:00
|
|
|
if os::remove_file(full) {
|
2012-07-14 00:57:48 -05:00
|
|
|
info(~"uninstalled: '" + full + ~"'");
|
2012-06-02 01:25:56 -05:00
|
|
|
} else {
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"could not uninstall: '" + full + ~"'");
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => again
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"can't find package with name: " + target);
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_query(c: cargo, wd: ~str, target: ~str) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.dep_cache.find(target) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(inst) => {
|
2012-06-13 11:34:43 -05:00
|
|
|
if inst {
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-06-09 21:20:22 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => ()
|
2012-06-09 21:20:22 -05:00
|
|
|
}
|
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
c.dep_cache.insert(target, true);
|
2012-06-09 21:20:22 -05:00
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
if is_archive_path(target) {
|
|
|
|
install_file(c, wd, target);
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-02 01:25:56 -05:00
|
|
|
} else if is_git_url(target) {
|
2012-07-31 21:25:24 -05:00
|
|
|
let reference = if c.opts.free.len() >= 4u {
|
2012-05-28 20:58:01 -05:00
|
|
|
some(c.opts.free[3u])
|
|
|
|
} else {
|
|
|
|
none
|
|
|
|
};
|
2012-07-31 21:25:24 -05:00
|
|
|
install_git(c, wd, target, reference);
|
2012-06-09 19:26:02 -05:00
|
|
|
} else if !valid_pkg_name(target) && has_archive_extension(target) {
|
|
|
|
install_curl(c, wd, target);
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-15 19:27:55 -06:00
|
|
|
} else {
|
2012-06-02 01:25:56 -05:00
|
|
|
let mut ps = copy target;
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match str::find_char(ps, '/') {
|
2012-08-03 21:59:04 -05:00
|
|
|
option::some(idx) => {
|
2012-06-02 01:25:56 -05:00
|
|
|
let source = str::slice(ps, 0u, idx);
|
|
|
|
ps = str::slice(ps, idx + 1u, str::len(ps));
|
|
|
|
if is_uuid(ps) {
|
|
|
|
install_uuid_specific(c, wd, source, ps);
|
|
|
|
} else {
|
|
|
|
install_named_specific(c, wd, source, ps);
|
|
|
|
}
|
2012-02-11 05:20:45 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
option::none => {
|
2012-06-02 01:25:56 -05:00
|
|
|
if is_uuid(ps) {
|
|
|
|
install_uuid(c, wd, ps);
|
|
|
|
} else {
|
|
|
|
install_named(c, wd, ps);
|
|
|
|
}
|
2012-02-11 05:20:45 -06:00
|
|
|
}
|
2011-12-16 21:08:25 -06:00
|
|
|
}
|
2011-12-01 21:37:56 -06:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2662): This whole dep_cache and current_install thing is
|
|
|
|
// a bit of a hack. It should be cleaned up in the future.
|
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
if target == c.current_install {
|
2012-06-30 18:19:07 -05:00
|
|
|
for c.dep_cache.each |k, _v| {
|
2012-06-09 19:26:02 -05:00
|
|
|
c.dep_cache.remove(k);
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
c.current_install = ~"";
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn cmd_install(c: cargo) unsafe {
|
2012-06-09 19:26:02 -05:00
|
|
|
let wd_base = c.workdir + path::path_sep();
|
2012-08-06 14:34:08 -05:00
|
|
|
let wd = match tempfile::mkdtemp(wd_base, ~"") {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(wd) => wd,
|
2012-08-22 19:24:52 -05:00
|
|
|
none => fail fmt!("needed temp dir: %s", wd_base)
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if vec::len(c.opts.free) == 2u {
|
|
|
|
let cwd = os::getcwd();
|
2012-07-14 00:57:48 -05:00
|
|
|
let status = run::run_program(~"cp", ~[~"-R", cwd, wd]);
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
if status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
fail fmt!("could not copy directory: %s", cwd);
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
install_source(c, wd);
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sync(c);
|
|
|
|
|
|
|
|
let query = c.opts.free[2];
|
|
|
|
c.current_install = copy query;
|
|
|
|
|
|
|
|
install_query(c, wd, copy query);
|
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn sync(c: cargo) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for c.sources.each_key |k| {
|
2012-06-09 19:26:02 -05:00
|
|
|
let mut s = c.sources.get(k);
|
|
|
|
sync_one(c, s);
|
|
|
|
c.sources.insert(k, s);
|
|
|
|
}
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
|
2012-06-09 19:26:02 -05:00
|
|
|
let name = src.name;
|
2012-07-14 00:57:48 -05:00
|
|
|
let srcfile = path::connect(dir, ~"source.json.new");
|
|
|
|
let destsrcfile = path::connect(dir, ~"source.json");
|
|
|
|
let pkgfile = path::connect(dir, ~"packages.json.new");
|
|
|
|
let destpkgfile = path::connect(dir, ~"packages.json");
|
|
|
|
let keyfile = path::connect(dir, ~"key.gpg");
|
|
|
|
let srcsigfile = path::connect(dir, ~"source.json.sig");
|
|
|
|
let sigfile = path::connect(dir, ~"packages.json.sig");
|
2011-12-16 19:33:39 -06:00
|
|
|
let url = src.url;
|
2012-06-09 19:26:02 -05:00
|
|
|
let mut has_src_file = false;
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
if !os::copy_file(path::connect(url, ~"packages.json"), pkgfile) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (url %s) failed", name, url));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
if os::copy_file(path::connect(url, ~"source.json"), srcfile) {
|
2012-06-09 19:26:02 -05:00
|
|
|
has_src_file = false;
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
os::copy_file(path::connect(url, ~"source.json.sig"), srcsigfile);
|
|
|
|
os::copy_file(path::connect(url, ~"packages.json.sig"), sigfile);
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match copy src.key {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(u) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
let p = run::program_output(~"curl",
|
|
|
|
~[~"-f", ~"-s", ~"-o", keyfile, u]);
|
2011-12-20 18:59:37 -06:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (key %s) failed", name, u));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
pgp::add(c.root, keyfile);
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match (src.key, src.keyfp) {
|
2012-08-03 21:59:04 -05:00
|
|
|
(some(_), some(f)) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
let r = pgp::verify(c.root, pkgfile, sigfile, f);
|
|
|
|
|
|
|
|
if !r {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("signature verification failed for source %s",
|
|
|
|
name));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if has_src_file {
|
|
|
|
let e = pgp::verify(c.root, srcfile, srcsigfile, f);
|
|
|
|
|
|
|
|
if !e {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("signature verification failed for source %s",
|
|
|
|
name));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
copy_warn(pkgfile, destpkgfile);
|
|
|
|
|
|
|
|
if has_src_file {
|
|
|
|
copy_warn(srcfile, destsrcfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
os::remove_file(keyfile);
|
|
|
|
os::remove_file(srcfile);
|
|
|
|
os::remove_file(srcsigfile);
|
|
|
|
os::remove_file(pkgfile);
|
|
|
|
os::remove_file(sigfile);
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("synced source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return true;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
|
2012-06-09 19:26:02 -05:00
|
|
|
let name = src.name;
|
2012-07-14 00:57:48 -05:00
|
|
|
let srcfile = path::connect(dir, ~"source.json");
|
|
|
|
let pkgfile = path::connect(dir, ~"packages.json");
|
|
|
|
let keyfile = path::connect(dir, ~"key.gpg");
|
|
|
|
let srcsigfile = path::connect(dir, ~"source.json.sig");
|
|
|
|
let sigfile = path::connect(dir, ~"packages.json.sig");
|
2012-06-09 19:26:02 -05:00
|
|
|
let url = src.url;
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn rollback(name: ~str, dir: ~str, insecure: bool) {
|
|
|
|
fn msg(name: ~str, insecure: bool) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("could not rollback source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
if insecure {
|
2012-07-14 00:57:48 -05:00
|
|
|
warn(~"a past security check failed on source " +
|
|
|
|
name + ~" and rolling back the source failed -"
|
|
|
|
+ ~" this source may be compromised");
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !os::change_dir(dir) {
|
|
|
|
msg(name, insecure);
|
|
|
|
}
|
|
|
|
else {
|
2012-07-14 00:57:48 -05:00
|
|
|
let p = run::program_output(~"git", ~[~"reset", ~"--hard",
|
|
|
|
~"HEAD@{1}"]);
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
if p.status != 0 {
|
|
|
|
msg(name, insecure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
if !os::path_exists(path::connect(dir, ~".git")) {
|
|
|
|
let p = run::program_output(~"git", ~[~"clone", url, dir]);
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (url %s) failed", name, url));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if !os::change_dir(dir) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (url %s) failed", name, url));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let p = run::program_output(~"git", ~[~"pull"]);
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (url %s) failed", name, url));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let has_src_file = os::path_exists(srcfile);
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match copy src.key {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(u) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
let p = run::program_output(~"curl",
|
|
|
|
~[~"-f", ~"-s", ~"-o", keyfile, u]);
|
2011-12-20 18:59:37 -06:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (key %s) failed", name, u));
|
2012-06-09 19:26:02 -05:00
|
|
|
rollback(name, dir, false);
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
|
|
|
pgp::add(c.root, keyfile);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match (src.key, src.keyfp) {
|
2012-08-03 21:59:04 -05:00
|
|
|
(some(_), some(f)) => {
|
2011-12-20 18:59:37 -06:00
|
|
|
let r = pgp::verify(c.root, pkgfile, sigfile, f);
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2011-12-20 18:59:37 -06:00
|
|
|
if !r {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("signature verification failed for source %s",
|
|
|
|
name));
|
2012-06-09 19:26:02 -05:00
|
|
|
rollback(name, dir, false);
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if has_src_file {
|
|
|
|
let e = pgp::verify(c.root, srcfile, srcsigfile, f);
|
|
|
|
|
|
|
|
if !e {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("signature verification failed for source %s",
|
|
|
|
name));
|
2012-06-09 19:26:02 -05:00
|
|
|
rollback(name, dir, false);
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-06-06 03:55:44 -05:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
os::remove_file(keyfile);
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("synced source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return true;
|
2012-06-09 21:20:22 -05:00
|
|
|
}
|
2012-06-06 03:55:44 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
|
2012-06-09 19:26:02 -05:00
|
|
|
let name = src.name;
|
2012-07-14 00:57:48 -05:00
|
|
|
let srcfile = path::connect(dir, ~"source.json.new");
|
|
|
|
let destsrcfile = path::connect(dir, ~"source.json");
|
|
|
|
let pkgfile = path::connect(dir, ~"packages.json.new");
|
|
|
|
let destpkgfile = path::connect(dir, ~"packages.json");
|
|
|
|
let keyfile = path::connect(dir, ~"key.gpg");
|
|
|
|
let srcsigfile = path::connect(dir, ~"source.json.sig");
|
|
|
|
let sigfile = path::connect(dir, ~"packages.json.sig");
|
2012-06-09 19:26:02 -05:00
|
|
|
let mut url = src.url;
|
2012-07-14 00:57:48 -05:00
|
|
|
let smart = !str::ends_with(src.url, ~"packages.json");
|
2012-06-09 19:26:02 -05:00
|
|
|
let mut has_src_file = false;
|
|
|
|
|
|
|
|
if smart {
|
2012-07-14 00:57:48 -05:00
|
|
|
url += ~"/packages.json";
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let p = run::program_output(~"curl",
|
|
|
|
~[~"-f", ~"-s", ~"-o", pkgfile, url]);
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (url %s) failed", name, url));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
if smart {
|
2012-07-14 00:57:48 -05:00
|
|
|
url = src.url + ~"/source.json";
|
2012-06-25 22:00:46 -05:00
|
|
|
let p =
|
2012-07-14 00:57:48 -05:00
|
|
|
run::program_output(~"curl",
|
|
|
|
~[~"-f", ~"-s", ~"-o", srcfile, url]);
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
if p.status == 0 {
|
|
|
|
has_src_file = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match copy src.key {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(u) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
let p = run::program_output(~"curl",
|
|
|
|
~[~"-f", ~"-s", ~"-o", keyfile, u]);
|
2012-06-09 19:26:02 -05:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (key %s) failed", name, u));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
pgp::add(c.root, keyfile);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match (src.key, src.keyfp) {
|
2012-08-03 21:59:04 -05:00
|
|
|
(some(_), some(f)) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
if smart {
|
2012-07-14 00:57:48 -05:00
|
|
|
url = src.url + ~"/packages.json.sig";
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
else {
|
2012-07-14 00:57:48 -05:00
|
|
|
url = src.url + ~".sig";
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let mut p = run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o",
|
2012-06-29 18:26:56 -05:00
|
|
|
sigfile, url]);
|
2012-06-09 19:26:02 -05:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (sig %s) failed", name, url));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let r = pgp::verify(c.root, pkgfile, sigfile, f);
|
|
|
|
|
|
|
|
if !r {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("signature verification failed for source %s",
|
|
|
|
name));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if smart && has_src_file {
|
2012-07-14 00:57:48 -05:00
|
|
|
url = src.url + ~"/source.json.sig";
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
p = run::program_output(~"curl",
|
|
|
|
~[~"-f", ~"-s", ~"-o",
|
|
|
|
srcsigfile, url]);
|
2012-06-09 19:26:02 -05:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch for source %s (sig %s) failed",
|
|
|
|
name, url));
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
let e = pgp::verify(c.root, srcfile, srcsigfile, f);
|
|
|
|
|
|
|
|
if !e {
|
2012-07-14 00:57:48 -05:00
|
|
|
error(~"signature verification failed for " +
|
|
|
|
~"source " + name);
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
copy_warn(pkgfile, destpkgfile);
|
|
|
|
|
|
|
|
if smart && has_src_file {
|
|
|
|
copy_warn(srcfile, destsrcfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
os::remove_file(keyfile);
|
|
|
|
os::remove_file(srcfile);
|
|
|
|
os::remove_file(srcsigfile);
|
|
|
|
os::remove_file(pkgfile);
|
|
|
|
os::remove_file(sigfile);
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("synced source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
return true;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn sync_one(c: cargo, src: source) {
|
2012-06-09 19:26:02 -05:00
|
|
|
let name = src.name;
|
|
|
|
let dir = path::connect(c.sourcedir, name);
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("syncing source: %s...", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
need_dir(dir);
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
let result = match src.method {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"git" => sync_one_git(c, dir, src),
|
|
|
|
~"file" => sync_one_file(c, dir, src),
|
|
|
|
_ => sync_one_curl(c, dir, src)
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if result {
|
|
|
|
load_source_info(c, src);
|
|
|
|
load_source_packages(c, src);
|
2011-12-16 19:33:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn cmd_init(c: cargo) {
|
2012-07-14 00:57:48 -05:00
|
|
|
let srcurl = ~"http://www.rust-lang.org/cargo/sources.json";
|
|
|
|
let sigurl = ~"http://www.rust-lang.org/cargo/sources.json.sig";
|
2011-12-20 18:59:37 -06:00
|
|
|
|
2012-07-14 00:57:48 -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
|
|
|
|
2012-06-25 22:00:46 -05:00
|
|
|
let p =
|
2012-07-14 00:57:48 -05:00
|
|
|
run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", srcfile, srcurl]);
|
2011-12-20 18:59:37 -06:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch of sources.json failed: %s", p.out));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
|
|
|
|
2012-06-25 22:00:46 -05:00
|
|
|
let p =
|
2012-07-14 00:57:48 -05:00
|
|
|
run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", sigfile, sigurl]);
|
2011-12-20 18:59:37 -06:00
|
|
|
if p.status != 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("fetch of sources.json.sig failed: %s", p.out));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let r = pgp::verify(c.root, srcfile, sigfile, pgp::signing_key_fp());
|
|
|
|
if !r {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("signature verification failed for '%s'", srcfile));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-20 18:59:37 -06:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-04-03 00:53:40 -05:00
|
|
|
copy_warn(srcfile, destsrcfile);
|
2012-06-09 19:26:02 -05:00
|
|
|
os::remove_file(srcfile);
|
|
|
|
os::remove_file(sigfile);
|
2012-02-07 02:15:39 -06:00
|
|
|
|
2012-08-22 19:24:52 -05: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-07-14 00:57:48 -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 {
|
2012-07-14 00:57:48 -05:00
|
|
|
m = m + ~" [" + str::connect(p.tags, ~", ") + ~"]";
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
|
|
|
info(m);
|
2012-07-14 00:57:48 -05:00
|
|
|
if p.description != ~"" {
|
|
|
|
print(~" >> " + p.description + ~"\n")
|
2012-01-23 20:23:31 -06:00
|
|
|
}
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
2012-06-02 01:25:56 -05:00
|
|
|
|
|
|
|
fn print_source(s: source) {
|
2012-07-14 00:57:48 -05:00
|
|
|
info(s.name + ~" (" + s.url + ~")");
|
2012-06-02 01:25:56 -05:00
|
|
|
|
2012-08-02 17:42:56 -05:00
|
|
|
let pks = sort::merge_sort(sys::shape_lt, copy s.packages);
|
2012-06-02 01:25:56 -05:00
|
|
|
let l = vec::len(pks);
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
print(io::with_str_writer(|writer| {
|
2012-07-14 00:57:48 -05:00
|
|
|
let mut list = ~" >> ";
|
2012-06-02 01:25:56 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do vec::iteri(pks) |i, pk| {
|
2012-06-02 01:25:56 -05:00
|
|
|
if str::len(list) > 78u {
|
|
|
|
writer.write_line(list);
|
2012-07-14 00:57:48 -05:00
|
|
|
list = ~" >> ";
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
list += pk.name + (if l - 1u == i { ~"" } else { ~", " });
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
2012-06-02 01:25:56 -05:00
|
|
|
|
|
|
|
writer.write_line(list);
|
2012-06-26 15:55:56 -05:00
|
|
|
}));
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn cmd_list(c: cargo) {
|
2012-06-09 19:26:02 -05:00
|
|
|
sync(c);
|
|
|
|
|
2012-06-02 01:25:56 -05:00
|
|
|
if vec::len(c.opts.free) >= 3u {
|
2012-06-30 18:19:07 -05:00
|
|
|
do vec::iter_between(c.opts.free, 2u, vec::len(c.opts.free)) |name| {
|
2012-06-09 19:26:02 -05:00
|
|
|
if !valid_pkg_name(name) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("'%s' is an invalid source name", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
} else {
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.sources.find(name) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(source) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
print_source(source);
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("no such source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-06-30 18:19:07 -05:00
|
|
|
for c.sources.each_value |v| {
|
2012-06-02 01:25:56 -05:00
|
|
|
print_source(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn cmd_search(c: cargo) {
|
2012-02-05 03:30:03 -06:00
|
|
|
if vec::len(c.opts.free) < 3u {
|
2011-12-20 19:41:23 -06:00
|
|
|
cmd_usage();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
sync(c);
|
|
|
|
|
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));
|
2012-06-30 18:19:07 -05:00
|
|
|
for_each_package(c, |s, p| {
|
2012-07-14 00:57:48 -05:00
|
|
|
if (str::contains(p.name, name) || name == ~"*") &&
|
2012-06-30 18:19:07 -05:00
|
|
|
vec::all(tags, |t| vec::contains(p.tags, t) ) {
|
2011-12-20 19:41:23 -06:00
|
|
|
print_pkg(s, p);
|
|
|
|
n += 1;
|
|
|
|
}
|
|
|
|
});
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("found %d packages", n));
|
2011-12-20 19:41:23 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn install_to_dir(srcfile: ~str, destdir: ~str) {
|
2012-05-26 10:35:54 -05:00
|
|
|
let newfile = path::connect(destdir, path::basename(srcfile));
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let status = run::run_program(~"cp", ~[~"-r", srcfile, newfile]);
|
2012-06-02 01:25:56 -05:00
|
|
|
if status == 0 {
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("installed: '%s'", newfile));
|
2012-06-02 01:25:56 -05:00
|
|
|
} else {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("could not install: '%s'", newfile));
|
2012-06-02 01:25:56 -05:00
|
|
|
}
|
2012-05-26 10:35:54 -05:00
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn dump_cache(c: cargo) {
|
2012-06-09 19:26:02 -05:00
|
|
|
need_dir(c.root);
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let out = path::connect(c.root, ~"cache.json");
|
2012-06-09 19:26:02 -05:00
|
|
|
let _root = json::dict(map::str_hash());
|
|
|
|
|
|
|
|
if os::path_exists(out) {
|
2012-07-14 00:57:48 -05:00
|
|
|
copy_warn(out, path::connect(c.root, ~"cache.json.old"));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
2012-06-09 23:01:11 -05:00
|
|
|
fn dump_sources(c: cargo) {
|
2012-06-09 19:26:02 -05:00
|
|
|
if c.sources.size() < 1u {
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
need_dir(c.root);
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
let out = path::connect(c.root, ~"sources.json");
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
if os::path_exists(out) {
|
2012-07-14 00:57:48 -05:00
|
|
|
copy_warn(out, path::connect(c.root, ~"sources.json.old"));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match io::buffered_file_writer(out) {
|
2012-08-03 21:59:04 -05:00
|
|
|
result::ok(writer) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
let hash = map::str_hash();
|
|
|
|
let root = json::dict(hash);
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
for c.sources.each |k, v| {
|
2012-06-09 19:26:02 -05:00
|
|
|
let chash = map::str_hash();
|
|
|
|
let child = json::dict(chash);
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
chash.insert(~"url", json::string(@v.url));
|
|
|
|
chash.insert(~"method", json::string(@v.method));
|
2012-06-09 19:26:02 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match copy v.key {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(key) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
chash.insert(~"key", json::string(@key));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-06 14:34:08 -05:00
|
|
|
match copy v.keyfp {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(keyfp) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
chash.insert(~"keyfp", json::string(@keyfp));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => ()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
hash.insert(k, child);
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.write_str(json::to_str(root));
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
result::err(e) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("could not dump sources: %s", e));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn copy_warn(srcfile: ~str, destfile: ~str) {
|
2012-06-09 19:26:02 -05:00
|
|
|
if !os::copy_file(srcfile, destfile) {
|
2012-08-22 19:24:52 -05:00
|
|
|
warn(fmt!("copying %s to %s failed", srcfile, destfile));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-09 23:01:11 -05:00
|
|
|
fn cmd_sources(c: cargo) {
|
2012-06-09 19:26:02 -05:00
|
|
|
if vec::len(c.opts.free) < 3u {
|
2012-06-30 18:19:07 -05:00
|
|
|
for c.sources.each_value |v| {
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("%s (%s) via %s",
|
|
|
|
v.name, v.url, v.method));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let action = c.opts.free[2u];
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match action {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"clear" => {
|
2012-06-30 18:19:07 -05:00
|
|
|
for c.sources.each_key |k| {
|
2012-06-09 19:26:02 -05:00
|
|
|
c.sources.remove(k);
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
info(~"cleared sources");
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
~"add" => {
|
2012-06-09 19:26:02 -05:00
|
|
|
if vec::len(c.opts.free) < 5u {
|
|
|
|
cmd_usage();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let name = c.opts.free[3u];
|
|
|
|
let url = c.opts.free[4u];
|
|
|
|
|
|
|
|
if !valid_pkg_name(name) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("'%s' is an invalid source name", name));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.sources.find(name) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(source) => {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("source already exists: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-06-09 23:01:11 -05:00
|
|
|
c.sources.insert(name, @{
|
|
|
|
name: name,
|
2012-06-09 19:26:02 -05:00
|
|
|
mut url: url,
|
|
|
|
mut method: assume_source_method(url),
|
|
|
|
mut key: none,
|
|
|
|
mut keyfp: none,
|
2012-06-29 18:26:56 -05:00
|
|
|
mut packages: ~[mut]
|
2012-06-09 19:26:02 -05:00
|
|
|
});
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("added source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
~"remove" => {
|
2012-06-09 19:26:02 -05:00
|
|
|
if vec::len(c.opts.free) < 4u {
|
|
|
|
cmd_usage();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let name = c.opts.free[3u];
|
|
|
|
|
|
|
|
if !valid_pkg_name(name) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("'%s' is an invalid source name", name));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.sources.find(name) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(source) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
c.sources.remove(name);
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("removed source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("no such source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
~"set-url" => {
|
2012-06-09 19:26:02 -05:00
|
|
|
if vec::len(c.opts.free) < 5u {
|
|
|
|
cmd_usage();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let name = c.opts.free[3u];
|
|
|
|
let url = c.opts.free[4u];
|
|
|
|
|
|
|
|
if !valid_pkg_name(name) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("'%s' is an invalid source name", name));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.sources.find(name) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(source) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
let old = copy source.url;
|
|
|
|
let method = assume_source_method(url);
|
|
|
|
|
|
|
|
source.url = url;
|
|
|
|
source.method = method;
|
|
|
|
|
|
|
|
c.sources.insert(name, source);
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("changed source url: '%s' to '%s'", old, url));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("no such source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
~"set-method" => {
|
2012-06-09 19:26:02 -05:00
|
|
|
if vec::len(c.opts.free) < 5u {
|
|
|
|
cmd_usage();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let name = c.opts.free[3u];
|
|
|
|
let method = c.opts.free[4u];
|
|
|
|
|
|
|
|
if !valid_pkg_name(name) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("'%s' is an invalid source name", name));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.sources.find(name) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(source) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
let old = copy source.method;
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
source.method = match method {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"git" => ~"git",
|
|
|
|
~"file" => ~"file",
|
|
|
|
_ => ~"curl"
|
2012-06-09 19:26:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
c.sources.insert(name, source);
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("changed source method: '%s' to '%s'", old,
|
|
|
|
method));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("no such source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
~"rename" => {
|
2012-06-09 19:26:02 -05:00
|
|
|
if vec::len(c.opts.free) < 5u {
|
|
|
|
cmd_usage();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let name = c.opts.free[3u];
|
|
|
|
let newn = c.opts.free[4u];
|
|
|
|
|
|
|
|
if !valid_pkg_name(name) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("'%s' is an invalid source name", name));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
if !valid_pkg_name(newn) {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("'%s' is an invalid source name", newn));
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match c.sources.find(name) {
|
2012-08-03 21:59:04 -05:00
|
|
|
some(source) => {
|
2012-06-09 19:26:02 -05:00
|
|
|
c.sources.remove(name);
|
|
|
|
c.sources.insert(newn, source);
|
2012-08-22 19:24:52 -05:00
|
|
|
info(fmt!("renamed source: %s to %s", name, newn));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
none => {
|
2012-08-22 19:24:52 -05:00
|
|
|
error(fmt!("no such source: %s", name));
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => cmd_usage()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-04-03 00:53:40 -05:00
|
|
|
}
|
|
|
|
|
2011-11-30 17:57:46 -06:00
|
|
|
fn cmd_usage() {
|
2012-07-14 00:57:48 -05:00
|
|
|
print(~"Usage: cargo <cmd> [options] [args..]
|
2012-06-09 19:26:02 -05:00
|
|
|
e.g. cargo install <name>
|
|
|
|
|
|
|
|
Where <cmd> is one of:
|
|
|
|
init, install, list, search, sources,
|
|
|
|
uninstall, usage
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
-h, --help Display this message
|
|
|
|
<cmd> -h, <cmd> --help Display help for <cmd>
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cmd_usage_init() {
|
2012-07-14 00:57:48 -05:00
|
|
|
print(~"cargo init
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
Re-initialize cargo in ~/.cargo. Clears all sources and then adds the
|
|
|
|
default sources from <www.rust-lang.org/sources.json>.");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cmd_usage_install() {
|
2012-07-14 00:57:48 -05:00
|
|
|
print(~"cargo install
|
2012-06-09 19:26:02 -05:00
|
|
|
cargo install [source/]<name>[@version]
|
|
|
|
cargo install [source/]<uuid>[@version]
|
|
|
|
cargo install <git url> [ref]
|
|
|
|
cargo install <tarball url>
|
|
|
|
cargo install <tarball file>
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--test Run crate tests before installing
|
|
|
|
-g Install to the user level (~/.cargo/bin/ instead of
|
|
|
|
locally in ./.cargo/bin/ by default)
|
|
|
|
-G Install to the system level (/usr/local/lib/cargo/bin/)
|
|
|
|
|
|
|
|
Install a crate. If no arguments are supplied, it installs from
|
|
|
|
the current working directory. If a source is provided, only install
|
|
|
|
from that source, otherwise it installs from any source.");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cmd_usage_uninstall() {
|
2012-07-14 00:57:48 -05:00
|
|
|
print(~"cargo uninstall [source/]<name>[@version]
|
2012-06-09 19:26:02 -05:00
|
|
|
cargo uninstall [source/]<uuid>[@version]
|
|
|
|
cargo uninstall <meta-name>[@version]
|
|
|
|
cargo uninstall <meta-uuid>[@version]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-g Remove from the user level (~/.cargo/bin/ instead of
|
|
|
|
locally in ./.cargo/bin/ by default)
|
|
|
|
-G Remove from the system level (/usr/local/lib/cargo/bin/)
|
|
|
|
|
|
|
|
Remove a crate. If a source is provided, only remove
|
|
|
|
from that source, otherwise it removes from any source.
|
|
|
|
If a crate was installed directly (git, tarball, etc.), you can remove
|
|
|
|
it by metadata.");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cmd_usage_list() {
|
2012-07-14 00:57:48 -05:00
|
|
|
print(~"cargo list [sources..]
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
If no arguments are provided, list all sources and their packages.
|
|
|
|
If source names are provided, list those sources and their packages.
|
2012-02-07 02:15:39 -06:00
|
|
|
");
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
fn cmd_usage_search() {
|
2012-07-14 00:57:48 -05:00
|
|
|
print(~"cargo search <query | '*'> [tags..]
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
Search packages.");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cmd_usage_sources() {
|
2012-07-14 00:57:48 -05:00
|
|
|
print(~"cargo sources
|
2012-06-09 19:26:02 -05:00
|
|
|
cargo sources add <name> <url>
|
|
|
|
cargo sources remove <name>
|
|
|
|
cargo sources rename <name> <new>
|
|
|
|
cargo sources set-url <name> <url>
|
|
|
|
cargo sources set-method <name> <method>
|
|
|
|
|
|
|
|
If no arguments are supplied, list all sources (but not their packages).
|
|
|
|
|
|
|
|
Commands:
|
|
|
|
add Add a source. The source method will be guessed
|
|
|
|
from the URL.
|
|
|
|
remove Remove a source.
|
|
|
|
rename Rename a source.
|
|
|
|
set-url Change the URL for a source.
|
|
|
|
set-method Change the method for a source.");
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn main(argv: ~[~str]) {
|
2012-02-05 03:30:03 -06:00
|
|
|
let o = build_cargo_options(argv);
|
|
|
|
|
2012-06-09 19:26:02 -05:00
|
|
|
if vec::len(o.free) < 2u {
|
|
|
|
cmd_usage();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
|
|
|
if o.help {
|
2012-08-06 14:34:08 -05:00
|
|
|
match o.free[1] {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"init" => cmd_usage_init(),
|
|
|
|
~"install" => cmd_usage_install(),
|
|
|
|
~"uninstall" => cmd_usage_uninstall(),
|
|
|
|
~"list" => cmd_usage_list(),
|
|
|
|
~"search" => cmd_usage_search(),
|
|
|
|
~"sources" => cmd_usage_sources(),
|
|
|
|
_ => cmd_usage()
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2012-06-09 19:26:02 -05:00
|
|
|
}
|
2012-07-14 00:57:48 -05:00
|
|
|
if o.free[1] == ~"usage" {
|
2011-11-30 17:57:46 -06:00
|
|
|
cmd_usage();
|
2012-08-01 19:30:05 -05:00
|
|
|
return;
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
2012-02-05 03:30:03 -06:00
|
|
|
|
2012-06-02 01:25:56 -05:00
|
|
|
let mut c = configure(o);
|
|
|
|
let home = c.root;
|
2012-07-14 00:57:48 -05:00
|
|
|
let first_time = os::path_exists(path::connect(home, ~"sources.json"));
|
2012-06-02 01:25:56 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
if !first_time && o.free[1] != ~"init" {
|
2012-06-02 01:25:56 -05:00
|
|
|
cmd_init(c);
|
|
|
|
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2662): shouldn't need to reconfigure
|
2012-06-02 01:25:56 -05:00
|
|
|
c = configure(o);
|
|
|
|
}
|
2012-02-05 03:30:03 -06:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match o.free[1] {
|
2012-08-03 21:59:04 -05:00
|
|
|
~"init" => cmd_init(c),
|
|
|
|
~"install" => cmd_install(c),
|
|
|
|
~"uninstall" => cmd_uninstall(c),
|
|
|
|
~"list" => cmd_list(c),
|
|
|
|
~"search" => cmd_search(c),
|
|
|
|
~"sources" => cmd_sources(c),
|
|
|
|
_ => cmd_usage()
|
2011-11-30 17:57:46 -06:00
|
|
|
}
|
2012-06-09 19:26:02 -05:00
|
|
|
|
|
|
|
dump_cache(c);
|
|
|
|
dump_sources(c);
|
2012-06-04 16:31:25 -05:00
|
|
|
}
|