mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
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:
commit
ef1faa5533
@ -90,6 +90,8 @@ impl Dependency {
|
||||
&self.source_id
|
||||
}
|
||||
|
||||
pub fn get_kind(&self) -> Kind { self.kind }
|
||||
|
||||
pub fn kind(mut self, kind: Kind) -> Dependency {
|
||||
self.kind = kind;
|
||||
self
|
||||
|
@ -9,6 +9,7 @@ use registry::{Registry, NewCrate, NewCrateDependency};
|
||||
|
||||
use core::source::Source;
|
||||
use core::{Package, MultiShell, SourceId};
|
||||
use core::dependency::Kind;
|
||||
use core::manifest::ManifestMetadata;
|
||||
use ops;
|
||||
use sources::{PathSource, RegistrySource};
|
||||
@ -76,6 +77,11 @@ fn transmit(pkg: &Package, tarball: &Path, registry: &mut Registry)
|
||||
features: dep.get_features().to_vec(),
|
||||
version_req: dep.get_version_req().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>>();
|
||||
let manifest = pkg.get_manifest();
|
||||
|
@ -171,7 +171,7 @@ use tar::Archive;
|
||||
use url::Url;
|
||||
|
||||
use core::{Source, SourceId, PackageId, Package, Summary, Registry};
|
||||
use core::Dependency;
|
||||
use core::dependency::{Dependency, Kind};
|
||||
use sources::{PathSource, git};
|
||||
use util::{CargoResult, Config, internal, ChainError, ToUrl, human};
|
||||
use util::{hex, Require, Sha256};
|
||||
@ -222,6 +222,7 @@ struct RegistryDependency {
|
||||
optional: bool,
|
||||
default_features: bool,
|
||||
target: Option<String>,
|
||||
kind: Option<String>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> RegistrySource<'a, 'b> {
|
||||
@ -412,16 +413,22 @@ impl<'a, 'b> RegistrySource<'a, 'b> {
|
||||
fn parse_registry_dependency(&self, dep: RegistryDependency)
|
||||
-> CargoResult<Dependency> {
|
||||
let RegistryDependency {
|
||||
name, req, features, optional, default_features, target
|
||||
name, req, features, optional, default_features, target, kind
|
||||
} = dep;
|
||||
|
||||
let dep = try!(Dependency::parse(name.as_slice(), Some(req.as_slice()),
|
||||
&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)
|
||||
.default_features(default_features)
|
||||
.features(features)
|
||||
.only_for_platform(target))
|
||||
.only_for_platform(target)
|
||||
.kind(kind))
|
||||
}
|
||||
|
||||
/// Actually perform network operations to update the registry
|
||||
|
@ -66,6 +66,7 @@ pub struct NewCrateDependency {
|
||||
pub features: Vec<String>,
|
||||
pub version_req: String,
|
||||
pub target: Option<String>,
|
||||
pub kind: String,
|
||||
}
|
||||
|
||||
#[deriving(Decodable)]
|
||||
|
@ -34,18 +34,22 @@ pub fn init() {
|
||||
.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#"
|
||||
[package]
|
||||
name = "{}"
|
||||
version = "{}"
|
||||
authors = []
|
||||
"#, name, version);
|
||||
for &(dep, req) in deps.iter() {
|
||||
for &(dep, req, kind) in deps.iter() {
|
||||
manifest.push_str(format!(r#"
|
||||
[dependencies.{}]
|
||||
[{}dependencies.{}]
|
||||
version = "{}"
|
||||
"#, dep, req).as_slice());
|
||||
"#, match kind {
|
||||
"build" => "build-",
|
||||
"dev" => "dev-",
|
||||
_ => ""
|
||||
}, dep, req).as_slice());
|
||||
}
|
||||
let p = project(name)
|
||||
.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")
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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) {
|
||||
mock_archive(name, version, deps);
|
||||
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();
|
||||
}
|
||||
|
||||
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 {
|
||||
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\":\"{}\",\
|
||||
\"deps\":{},\"cksum\":\"{}\",\"features\":{{}},\
|
||||
\"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\":\"{}\",\
|
||||
\"req\":\"{}\",\
|
||||
\"features\":[],\
|
||||
\"default_features\":false,\
|
||||
\"target\":null,\
|
||||
\"optional\":false}}", name, req)
|
||||
\"optional\":false,\
|
||||
\"kind\":\"{}\"}}", name, req, kind)
|
||||
}
|
||||
|
||||
pub fn cksum(s: &[u8]) -> String {
|
||||
|
@ -65,7 +65,7 @@ test!(deps {
|
||||
.file("src/main.rs", "fn main() {}");
|
||||
|
||||
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"),
|
||||
execs().with_status(0).with_stdout(format!("\
|
||||
@ -269,7 +269,7 @@ test!(lockfile_locks_transitively {
|
||||
p.build();
|
||||
|
||||
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"),
|
||||
execs().with_status(0).with_stdout(format!("\
|
||||
@ -284,7 +284,7 @@ test!(lockfile_locks_transitively {
|
||||
|
||||
p.root().move_into_the_past().unwrap();
|
||||
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"),
|
||||
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_yank("baz", "0.0.2", &[], true);
|
||||
r::mock_pkg("bar", "0.0.1", &[("baz", "*")]);
|
||||
r::mock_pkg_yank("bar", "0.0.2", &[("baz", "*")], true);
|
||||
r::mock_pkg("bar", "0.0.1", &[("baz", "*", "normal")]);
|
||||
r::mock_pkg_yank("bar", "0.0.2", &[("baz", "*", "normal")], true);
|
||||
|
||||
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
|
||||
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_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"),
|
||||
execs().with_status(101).with_stderr("\
|
||||
@ -442,3 +442,30 @@ test!(update_lockfile {
|
||||
", downloading = DOWNLOADING, compiling = COMPILING,
|
||||
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()));
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user