From ce9fbf751778512dd179cea4d491bd541894a1f5 Mon Sep 17 00:00:00 2001 From: Elly Jones Date: Thu, 15 Dec 2011 20:27:55 -0500 Subject: [PATCH 1/2] cargo: support uuid: and shortname package forms. 'cargo install rustcrypto' now works. --- src/cargo/cargo.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 49a5367860efb..03cde273f4c12 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -6,6 +6,7 @@ import rustc::syntax::parse::parser; import std::fs; import std::generic_os; import std::io; +import std::json; import option; import option::{none, some}; import std::os; @@ -206,6 +207,36 @@ fn install_file(c: cargo, wd: str, _path: str) { install_source(c, wd); } +fn install_resolved(c: cargo, wd: str, key: str) { + fs::remove_dir(wd); + let u = "https://rust-package-index.appspot.com/pkg/" + key; + let p = run::program_output("curl", [u]); + if p.status != 0 { + fail #fmt["Fetch of %s failed: %s", u, p.err]; + } + let j = json::from_str(p.out); + alt j { + some (json::dict(_j)) { + alt _j.find("install") { + some (json::string(g)) { + log #fmt["Resolved: %s -> %s", key, g]; + cmd_install(c, ["cargo", "install", g]); + } + _ { fail #fmt["Bogus install: '%s'", p.out]; } + } + } + _ { fail #fmt["Bad json: '%s'", p.out]; } + } +} + +fn install_uuid(c: cargo, wd: str, uuid: str) { + install_resolved(c, wd, uuid); +} + +fn install_named(c: cargo, wd: str, name: str) { + install_resolved(c, wd, name); +} + fn cmd_install(c: cargo, argv: [str]) { // cargo install if vec::len(argv) < 3u { @@ -226,6 +257,11 @@ fn cmd_install(c: cargo, argv: [str]) { } else if str::starts_with(argv[2], "file:") { let path = rest(argv[2], 5u); install_file(c, wd, path); + } else if str::starts_with(argv[2], "uuid:") { + let uuid = rest(argv[2], 5u); + install_uuid(c, wd, uuid); + } else { + install_named(c, wd, argv[2]); } } From 7953a5dcfcb779a4a127b34e9cc85b0359c45d1a Mon Sep 17 00:00:00 2001 From: Elly Jones Date: Thu, 15 Dec 2011 21:22:42 -0500 Subject: [PATCH 2/2] cargo: update to new rust-pkg-index API. --- src/cargo/cargo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 03cde273f4c12..757fa31d4e0d4 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -230,11 +230,11 @@ fn install_resolved(c: cargo, wd: str, key: str) { } fn install_uuid(c: cargo, wd: str, uuid: str) { - install_resolved(c, wd, uuid); + install_resolved(c, wd, "by-uuid/" + uuid); } fn install_named(c: cargo, wd: str, name: str) { - install_resolved(c, wd, name); + install_resolved(c, wd, "by-name/" + name); } fn cmd_install(c: cargo, argv: [str]) {