Skip to content

Commit

Permalink
Add temporary custom-implicit-stdlib-dependencies key
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Oct 10, 2016
1 parent 2e39355 commit 3343785
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 21 deletions.
68 changes: 53 additions & 15 deletions src/cargo/util/toml/implicit_deps.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::HashMap;

use util::CargoResult;
use util::config::Config;
use util::toml::{TomlDependency, DetailedTomlDependency};


fn marshall<S, I>(name_ver: I)
-> HashMap<String, TomlDependency>
where I: Iterator<Item=(S, S)>,
where I: Iterator<Item=(S, &'static str)>,
S: Into<String>
{
name_ver
Expand All @@ -18,21 +19,58 @@ fn marshall<S, I>(name_ver: I)
.collect()
}

pub fn primary() -> HashMap<String, TomlDependency> {
marshall(vec![
("core", "^1.0"),
("std", "^1.0"),
].into_iter())
mod default {
use std::collections::HashMap;
use util::toml::TomlDependency;
use super::marshall;

pub fn primary() -> HashMap<String, TomlDependency> {
marshall(vec![
("core", "^1.0"),
("std", "^1.0"),
].into_iter())
}

pub fn dev() -> HashMap<String, TomlDependency> {
let mut map = marshall(vec![
("test", "^1.0"),
].into_iter());
map.extend(self::primary().into_iter());
map
}

pub fn build() -> HashMap<String, TomlDependency> {
self::primary()
}
}

pub fn dev() -> HashMap<String, TomlDependency> {
let mut map = marshall(vec![
("test", "^1.0"),
].into_iter());
map.extend(self::primary().into_iter());
map
fn get_custom(sort: &'static str, config: &Config)
-> CargoResult<Option<HashMap<String, TomlDependency>>>
{
let overrides = try!(config.get_list(&format!(
"custom-implicit-stdlib-dependencies.{}",
sort)));

Ok(overrides.map(|os| marshall(os.val.into_iter().map(|o| (o.0, "^1.0")))))
}

pub fn build() -> HashMap<String, TomlDependency> {
self::primary()
pub fn primary(config: &Config)
-> CargoResult<HashMap<String, TomlDependency>>
{
Ok(try!(get_custom("dependencies", config))
.unwrap_or_else(|| default::primary()))
}

pub fn dev(config: &Config)
-> CargoResult<HashMap<String, TomlDependency>>
{
Ok(try!(get_custom("dev-dependencies", config))
.unwrap_or_else(|| default::dev()))
}

pub fn build(config: &Config)
-> CargoResult<HashMap<String, TomlDependency>>
{
Ok(try!(get_custom("build-dependencies", config))
.unwrap_or_else(|| default::build()))
}
21 changes: 15 additions & 6 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,17 +687,26 @@ impl TomlManifest {
// Add implicit deps
cx.platform = None;

if try!(config.get_table("custom-implicit-stdlib-dependencies")).is_some() {
cx.warnings.push(
"the `custom-implicit-stdlib-dependencies` config key is unstable"
.to_string());
}

if implicit_primary {
try!(process_deps(&mut cx, Some(&implicit_deps::primary()),
true, keep_stdlib_deps, None));
try!(process_deps(
&mut cx, Some(&try!(implicit_deps::primary(config))),
true, keep_stdlib_deps, None));
}
if !explicit_dev {
try!(process_deps(&mut cx, Some(&implicit_deps::dev()),
true, keep_stdlib_deps, Some(Kind::Development)));
try!(process_deps(
&mut cx, Some(&try!(implicit_deps::dev(config))),
true, keep_stdlib_deps, Some(Kind::Development)));
}
if !explicit_build {
try!(process_deps(&mut cx, Some(&implicit_deps::build()),
true, keep_stdlib_deps, Some(Kind::Build)));
try!(process_deps(
&mut cx, Some(&try!(implicit_deps::build(config))),
true, keep_stdlib_deps, Some(Kind::Build)));
}

replace = try!(self.replace(&mut cx));
Expand Down
34 changes: 34 additions & 0 deletions tests/stdlib-deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,37 @@ Caused by:
[..]
"));
}


#[test]
fn override_implicit_deps() {
setup();
Package::new("not-wanted", "0.0.1").local(true).publish();
let foo = project("asdf")
.file("Cargo.toml", r#"
[package]
name = "local"
version = "0.0.0"
authors = []
"#)
.file("src/lib.rs", "")
.file(".cargo/config", r#"
[custom-implicit-stdlib-dependencies]
dependencies = [ "foo" ]
dev-dependencies = [ ]
build-dependencies = [ ]
"#);
assert_that(foo.cargo_process("build").arg("-v"),
execs().with_status(101)
.with_stderr_contains(
"[WARNING] the \"compiler source\" is unstable [..]")
.with_stderr_contains(
"[WARNING] the `keep-stdlib-dependencies` config key is unstable")
.with_stderr_contains(
"[WARNING] the `custom-implicit-stdlib-dependencies` config key is unstable")
.with_stderr_contains("\
[ERROR] no matching package named `foo` found (required by `local`)
location searched: registry file://[..]
version required: ^1.0
"));
}

0 comments on commit 3343785

Please sign in to comment.