auto merge of #939 : alexcrichton/cargo/issue-38, r=brson

This ensures that the registry understands whether dependencies are build
dependencies or dev dependencies.

Closes rust-lang/crates.io#38
This commit is contained in:
bors 2014-11-24 23:34:34 +00:00
commit ef1faa5533
6 changed files with 67 additions and 19 deletions

View File

@ -90,6 +90,8 @@ impl Dependency {
&self.source_id &self.source_id
} }
pub fn get_kind(&self) -> Kind { self.kind }
pub fn kind(mut self, kind: Kind) -> Dependency { pub fn kind(mut self, kind: Kind) -> Dependency {
self.kind = kind; self.kind = kind;
self self

View File

@ -9,6 +9,7 @@ use registry::{Registry, NewCrate, NewCrateDependency};
use core::source::Source; use core::source::Source;
use core::{Package, MultiShell, SourceId}; use core::{Package, MultiShell, SourceId};
use core::dependency::Kind;
use core::manifest::ManifestMetadata; use core::manifest::ManifestMetadata;
use ops; use ops;
use sources::{PathSource, RegistrySource}; use sources::{PathSource, RegistrySource};
@ -76,6 +77,11 @@ fn transmit(pkg: &Package, tarball: &Path, registry: &mut Registry)
features: dep.get_features().to_vec(), features: dep.get_features().to_vec(),
version_req: dep.get_version_req().to_string(), version_req: dep.get_version_req().to_string(),
target: dep.get_only_for_platform().map(|s| s.to_string()), target: dep.get_only_for_platform().map(|s| s.to_string()),
kind: match dep.get_kind() {
Kind::Normal => "normal",
Kind::Build => "build",
Kind::Development => "dev",
}.to_string(),
} }
}).collect::<Vec<NewCrateDependency>>(); }).collect::<Vec<NewCrateDependency>>();
let manifest = pkg.get_manifest(); let manifest = pkg.get_manifest();

View File

@ -171,7 +171,7 @@ use tar::Archive;
use url::Url; use url::Url;
use core::{Source, SourceId, PackageId, Package, Summary, Registry}; use core::{Source, SourceId, PackageId, Package, Summary, Registry};
use core::Dependency; use core::dependency::{Dependency, Kind};
use sources::{PathSource, git}; use sources::{PathSource, git};
use util::{CargoResult, Config, internal, ChainError, ToUrl, human}; use util::{CargoResult, Config, internal, ChainError, ToUrl, human};
use util::{hex, Require, Sha256}; use util::{hex, Require, Sha256};
@ -222,6 +222,7 @@ struct RegistryDependency {
optional: bool, optional: bool,
default_features: bool, default_features: bool,
target: Option<String>, target: Option<String>,
kind: Option<String>,
} }
impl<'a, 'b> RegistrySource<'a, 'b> { impl<'a, 'b> RegistrySource<'a, 'b> {
@ -412,16 +413,22 @@ impl<'a, 'b> RegistrySource<'a, 'b> {
fn parse_registry_dependency(&self, dep: RegistryDependency) fn parse_registry_dependency(&self, dep: RegistryDependency)
-> CargoResult<Dependency> { -> CargoResult<Dependency> {
let RegistryDependency { let RegistryDependency {
name, req, features, optional, default_features, target name, req, features, optional, default_features, target, kind
} = dep; } = dep;
let dep = try!(Dependency::parse(name.as_slice(), Some(req.as_slice()), let dep = try!(Dependency::parse(name.as_slice(), Some(req.as_slice()),
&self.source_id)); &self.source_id));
let kind = match kind.as_ref().map(|s| s.as_slice()).unwrap_or("") {
"dev" => Kind::Development,
"build" => Kind::Build,
_ => Kind::Normal,
};
Ok(dep.optional(optional) Ok(dep.optional(optional)
.default_features(default_features) .default_features(default_features)
.features(features) .features(features)
.only_for_platform(target)) .only_for_platform(target)
.kind(kind))
} }
/// Actually perform network operations to update the registry /// Actually perform network operations to update the registry

View File

@ -66,6 +66,7 @@ pub struct NewCrateDependency {
pub features: Vec<String>, pub features: Vec<String>,
pub version_req: String, pub version_req: String,
pub target: Option<String>, pub target: Option<String>,
pub kind: String,
} }
#[deriving(Decodable)] #[deriving(Decodable)]

View File

@ -34,18 +34,22 @@ pub fn init() {
.build(); .build();
} }
pub fn mock_archive(name: &str, version: &str, deps: &[(&str, &str)]) { pub fn mock_archive(name: &str, version: &str, deps: &[(&str, &str, &str)]) {
let mut manifest = format!(r#" let mut manifest = format!(r#"
[package] [package]
name = "{}" name = "{}"
version = "{}" version = "{}"
authors = [] authors = []
"#, name, version); "#, name, version);
for &(dep, req) in deps.iter() { for &(dep, req, kind) in deps.iter() {
manifest.push_str(format!(r#" manifest.push_str(format!(r#"
[dependencies.{}] [{}dependencies.{}]
version = "{}" version = "{}"
"#, dep, req).as_slice()); "#, match kind {
"build" => "build-",
"dev" => "dev-",
_ => ""
}, dep, req).as_slice());
} }
let p = project(name) let p = project(name)
.file("Cargo.toml", manifest.as_slice()) .file("Cargo.toml", manifest.as_slice())
@ -67,11 +71,11 @@ pub fn mock_archive_dst(name: &str, version: &str) -> Path {
dl_path().join(name).join(version).join("download") dl_path().join(name).join(version).join("download")
} }
pub fn mock_pkg(name: &str, version: &str, deps: &[(&str, &str)]) { pub fn mock_pkg(name: &str, version: &str, deps: &[(&str, &str, &str)]) {
mock_pkg_yank(name, version, deps, false) mock_pkg_yank(name, version, deps, false)
} }
pub fn mock_pkg_yank(name: &str, version: &str, deps: &[(&str, &str)], pub fn mock_pkg_yank(name: &str, version: &str, deps: &[(&str, &str, &str)],
yanked: bool) { yanked: bool) {
mock_archive(name, version, deps); mock_archive(name, version, deps);
let c = File::open(&mock_archive_dst(name, version)).read_to_end().unwrap(); let c = File::open(&mock_archive_dst(name, version)).read_to_end().unwrap();
@ -107,22 +111,23 @@ pub fn publish(file: &str, line: &str) {
&[&parent]).unwrap(); &[&parent]).unwrap();
} }
pub fn pkg(name: &str, vers: &str, deps: &[(&str, &str)], cksum: &str, pub fn pkg(name: &str, vers: &str, deps: &[(&str, &str, &str)], cksum: &str,
yanked: bool) -> String { yanked: bool) -> String {
let deps = deps.iter().map(|&(a, b)| dep(a, b)).collect::<Vec<String>>(); let deps = deps.iter().map(|&(a, b, c)| dep(a, b, c)).collect::<Vec<String>>();
format!("{{\"name\":\"{}\",\"vers\":\"{}\",\ format!("{{\"name\":\"{}\",\"vers\":\"{}\",\
\"deps\":{},\"cksum\":\"{}\",\"features\":{{}},\ \"deps\":{},\"cksum\":\"{}\",\"features\":{{}},\
\"yanked\":{}}}", \"yanked\":{}}}",
name, vers, deps, cksum, yanked) name, vers, deps, cksum, yanked)
} }
pub fn dep(name: &str, req: &str) -> String { pub fn dep(name: &str, req: &str, kind: &str) -> String {
format!("{{\"name\":\"{}\",\ format!("{{\"name\":\"{}\",\
\"req\":\"{}\",\ \"req\":\"{}\",\
\"features\":[],\ \"features\":[],\
\"default_features\":false,\ \"default_features\":false,\
\"target\":null,\ \"target\":null,\
\"optional\":false}}", name, req) \"optional\":false,\
\"kind\":\"{}\"}}", name, req, kind)
} }
pub fn cksum(s: &[u8]) -> String { pub fn cksum(s: &[u8]) -> String {

View File

@ -65,7 +65,7 @@ test!(deps {
.file("src/main.rs", "fn main() {}"); .file("src/main.rs", "fn main() {}");
r::mock_pkg("baz", "0.0.1", &[]); r::mock_pkg("baz", "0.0.1", &[]);
r::mock_pkg("bar", "0.0.1", &[("baz", "*")]); r::mock_pkg("bar", "0.0.1", &[("baz", "*", "normal")]);
assert_that(p.cargo_process("build"), assert_that(p.cargo_process("build"),
execs().with_status(0).with_stdout(format!("\ execs().with_status(0).with_stdout(format!("\
@ -269,7 +269,7 @@ test!(lockfile_locks_transitively {
p.build(); p.build();
r::mock_pkg("baz", "0.0.1", &[]); r::mock_pkg("baz", "0.0.1", &[]);
r::mock_pkg("bar", "0.0.1", &[("baz", "*")]); r::mock_pkg("bar", "0.0.1", &[("baz", "*", "normal")]);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"), assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(format!("\ execs().with_status(0).with_stdout(format!("\
@ -284,7 +284,7 @@ test!(lockfile_locks_transitively {
p.root().move_into_the_past().unwrap(); p.root().move_into_the_past().unwrap();
r::mock_pkg("baz", "0.0.2", &[]); r::mock_pkg("baz", "0.0.2", &[]);
r::mock_pkg("bar", "0.0.2", &[("baz", "*")]); r::mock_pkg("bar", "0.0.2", &[("baz", "*", "normal")]);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"), assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout("")); execs().with_status(0).with_stdout(""));
@ -306,8 +306,8 @@ test!(yanks_are_not_used {
r::mock_pkg("baz", "0.0.1", &[]); r::mock_pkg("baz", "0.0.1", &[]);
r::mock_pkg_yank("baz", "0.0.2", &[], true); r::mock_pkg_yank("baz", "0.0.2", &[], true);
r::mock_pkg("bar", "0.0.1", &[("baz", "*")]); r::mock_pkg("bar", "0.0.1", &[("baz", "*", "normal")]);
r::mock_pkg_yank("bar", "0.0.2", &[("baz", "*")], true); r::mock_pkg_yank("bar", "0.0.2", &[("baz", "*", "normal")], true);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"), assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(format!("\ execs().with_status(0).with_stdout(format!("\
@ -337,7 +337,7 @@ test!(relying_on_a_yank_is_bad {
r::mock_pkg("baz", "0.0.1", &[]); r::mock_pkg("baz", "0.0.1", &[]);
r::mock_pkg_yank("baz", "0.0.2", &[], true); r::mock_pkg_yank("baz", "0.0.2", &[], true);
r::mock_pkg("bar", "0.0.1", &[("baz", "=0.0.2")]); r::mock_pkg("bar", "0.0.1", &[("baz", "=0.0.2", "normal")]);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"), assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(101).with_stderr("\ execs().with_status(101).with_stderr("\
@ -442,3 +442,30 @@ test!(update_lockfile {
", downloading = DOWNLOADING, compiling = COMPILING, ", downloading = DOWNLOADING, compiling = COMPILING,
dir = p.url()).as_slice())); dir = p.url()).as_slice()));
}) })
test!(dev_dependency_not_used {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
bar = "*"
"#)
.file("src/main.rs", "fn main() {}");
p.build();
r::mock_pkg("baz", "0.0.1", &[]);
r::mock_pkg("bar", "0.0.1", &[("baz", "*", "dev")]);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(format!("\
{updating} registry `[..]`
{downloading} [..] v0.0.1 (registry file://[..])
{compiling} bar v0.0.1 (registry file://[..])
{compiling} foo v0.0.1 ({dir})
", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
dir = p.url()).as_slice()));
})