Skip to content

Commit 3343785

Browse files
committed
Add temporary custom-implicit-stdlib-dependencies key
1 parent 2e39355 commit 3343785

File tree

3 files changed

+102
-21
lines changed

3 files changed

+102
-21
lines changed

src/cargo/util/toml/implicit_deps.rs

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::collections::HashMap;
22

3+
use util::CargoResult;
4+
use util::config::Config;
35
use util::toml::{TomlDependency, DetailedTomlDependency};
46

5-
67
fn marshall<S, I>(name_ver: I)
78
-> HashMap<String, TomlDependency>
8-
where I: Iterator<Item=(S, S)>,
9+
where I: Iterator<Item=(S, &'static str)>,
910
S: Into<String>
1011
{
1112
name_ver
@@ -18,21 +19,58 @@ fn marshall<S, I>(name_ver: I)
1819
.collect()
1920
}
2021

21-
pub fn primary() -> HashMap<String, TomlDependency> {
22-
marshall(vec![
23-
("core", "^1.0"),
24-
("std", "^1.0"),
25-
].into_iter())
22+
mod default {
23+
use std::collections::HashMap;
24+
use util::toml::TomlDependency;
25+
use super::marshall;
26+
27+
pub fn primary() -> HashMap<String, TomlDependency> {
28+
marshall(vec![
29+
("core", "^1.0"),
30+
("std", "^1.0"),
31+
].into_iter())
32+
}
33+
34+
pub fn dev() -> HashMap<String, TomlDependency> {
35+
let mut map = marshall(vec![
36+
("test", "^1.0"),
37+
].into_iter());
38+
map.extend(self::primary().into_iter());
39+
map
40+
}
41+
42+
pub fn build() -> HashMap<String, TomlDependency> {
43+
self::primary()
44+
}
2645
}
2746

28-
pub fn dev() -> HashMap<String, TomlDependency> {
29-
let mut map = marshall(vec![
30-
("test", "^1.0"),
31-
].into_iter());
32-
map.extend(self::primary().into_iter());
33-
map
47+
fn get_custom(sort: &'static str, config: &Config)
48+
-> CargoResult<Option<HashMap<String, TomlDependency>>>
49+
{
50+
let overrides = try!(config.get_list(&format!(
51+
"custom-implicit-stdlib-dependencies.{}",
52+
sort)));
53+
54+
Ok(overrides.map(|os| marshall(os.val.into_iter().map(|o| (o.0, "^1.0")))))
3455
}
3556

36-
pub fn build() -> HashMap<String, TomlDependency> {
37-
self::primary()
57+
pub fn primary(config: &Config)
58+
-> CargoResult<HashMap<String, TomlDependency>>
59+
{
60+
Ok(try!(get_custom("dependencies", config))
61+
.unwrap_or_else(|| default::primary()))
62+
}
63+
64+
pub fn dev(config: &Config)
65+
-> CargoResult<HashMap<String, TomlDependency>>
66+
{
67+
Ok(try!(get_custom("dev-dependencies", config))
68+
.unwrap_or_else(|| default::dev()))
69+
}
70+
71+
pub fn build(config: &Config)
72+
-> CargoResult<HashMap<String, TomlDependency>>
73+
{
74+
Ok(try!(get_custom("build-dependencies", config))
75+
.unwrap_or_else(|| default::build()))
3876
}

src/cargo/util/toml/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,17 +687,26 @@ impl TomlManifest {
687687
// Add implicit deps
688688
cx.platform = None;
689689

690+
if try!(config.get_table("custom-implicit-stdlib-dependencies")).is_some() {
691+
cx.warnings.push(
692+
"the `custom-implicit-stdlib-dependencies` config key is unstable"
693+
.to_string());
694+
}
695+
690696
if implicit_primary {
691-
try!(process_deps(&mut cx, Some(&implicit_deps::primary()),
692-
true, keep_stdlib_deps, None));
697+
try!(process_deps(
698+
&mut cx, Some(&try!(implicit_deps::primary(config))),
699+
true, keep_stdlib_deps, None));
693700
}
694701
if !explicit_dev {
695-
try!(process_deps(&mut cx, Some(&implicit_deps::dev()),
696-
true, keep_stdlib_deps, Some(Kind::Development)));
702+
try!(process_deps(
703+
&mut cx, Some(&try!(implicit_deps::dev(config))),
704+
true, keep_stdlib_deps, Some(Kind::Development)));
697705
}
698706
if !explicit_build {
699-
try!(process_deps(&mut cx, Some(&implicit_deps::build()),
700-
true, keep_stdlib_deps, Some(Kind::Build)));
707+
try!(process_deps(
708+
&mut cx, Some(&try!(implicit_deps::build(config))),
709+
true, keep_stdlib_deps, Some(Kind::Build)));
701710
}
702711

703712
replace = try!(self.replace(&mut cx));

tests/stdlib-deps.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,37 @@ Caused by:
314314
[..]
315315
"));
316316
}
317+
318+
319+
#[test]
320+
fn override_implicit_deps() {
321+
setup();
322+
Package::new("not-wanted", "0.0.1").local(true).publish();
323+
let foo = project("asdf")
324+
.file("Cargo.toml", r#"
325+
[package]
326+
name = "local"
327+
version = "0.0.0"
328+
authors = []
329+
"#)
330+
.file("src/lib.rs", "")
331+
.file(".cargo/config", r#"
332+
[custom-implicit-stdlib-dependencies]
333+
dependencies = [ "foo" ]
334+
dev-dependencies = [ ]
335+
build-dependencies = [ ]
336+
"#);
337+
assert_that(foo.cargo_process("build").arg("-v"),
338+
execs().with_status(101)
339+
.with_stderr_contains(
340+
"[WARNING] the \"compiler source\" is unstable [..]")
341+
.with_stderr_contains(
342+
"[WARNING] the `keep-stdlib-dependencies` config key is unstable")
343+
.with_stderr_contains(
344+
"[WARNING] the `custom-implicit-stdlib-dependencies` config key is unstable")
345+
.with_stderr_contains("\
346+
[ERROR] no matching package named `foo` found (required by `local`)
347+
location searched: registry file://[..]
348+
version required: ^1.0
349+
"));
350+
}

0 commit comments

Comments
 (0)