Skip to content

Commit

Permalink
Add implicit-dependencies = <bool> package key, add warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Oct 10, 2016
1 parent 43ecceb commit 2e39355
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ pub struct TomlProject {
include: Option<Vec<String>>,
publish: Option<bool>,
workspace: Option<String>,
implicit_dependencies: Option<bool>,

// package metadata
description: Option<String>,
Expand Down Expand Up @@ -659,10 +660,34 @@ impl TomlManifest {
cx.warnings.push("explicit dependencies are unstable".to_string());
}

if project.implicit_dependencies.is_some() {
cx.warnings.push(
"the implicit-dependencies flag is unstable \
(and furthermore is not currently planned on being stabilized)."
.to_string());
}

// Based on "implicit_dependencies" flag and actual usage of
// explicit stdlib dependencies
let implicit_primary = match (explicit_primary,
project.implicit_dependencies)
{
(true, Some(true)) => bail!(
"cannot use explicit stdlib deps when implicit deps \
were explicitly enabled."),
// With explicit deps, and flag not "yes", resolve "no"
(true, _) => false,
// With no explcit deps and no flag, resolve "yes" for
// backwards-compat
(false, None) => true,
// With no explcit deps and the flag, obey the flag
(false, Some(x)) => x,
};

// Add implicit deps
cx.platform = None;

if !explicit_primary {
if implicit_primary {
try!(process_deps(&mut cx, Some(&implicit_deps::primary()),
true, keep_stdlib_deps, None));
}
Expand Down
101 changes: 101 additions & 0 deletions tests/stdlib-deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,107 @@ version required: ^1.0
"));
}


#[test]
fn explicit_stdlib_deps_with_flag() {
setup();
Package::new("core", "1.0.0").local(true).publish();
Package::new("std", "1.0.0").local(true).file("src/lib.rs", STD).publish();
Package::new("test", "1.0.0").local(true).publish();

let p = project("local")
.file("Cargo.toml", r#"
[package]
name = "local"
version = "0.0.1"
authors = []
implicit-dependencies = false
[dependencies]
core = { version = "1", stdlib = true }
std = { version = "1", stdlib = true }
test = { version = "1", stdlib = true }
"#)
.file("src/lib.rs", "");

assert_that(p.cargo_process("build").arg("--verbose"),
execs().with_status(0)
.with_stderr_contains(
"[WARNING] the \"compiler source\" is unstable [..]")
.with_stderr_contains(
"[WARNING] explicit dependencies are unstable"));
}

#[test]
fn implicit_stdlib_dep_with_flag() {
setup();
Package::new("core", "1.0.0").local(true).publish();
Package::new("std", "1.0.0").local(true).file("src/lib.rs", STD).publish();
Package::new("test", "1.0.0").local(true).publish();

let p = project("local")
.file("Cargo.toml", r#"
[package]
name = "local"
version = "0.0.1"
authors = []
implicit-dependencies = true
"#)
.file("src/lib.rs", "");

assert_that(p.cargo_process("build").arg("--verbose"),
execs().with_status(0)
.with_stderr_contains(
"[WARNING] the \"compiler source\" is unstable [..]"));
}

#[test]
fn no_primary_stdlib_deps_at_all() {
setup();
// For dev & build
Package::new("core", "1.0.0")
.file("src/lib.rs", "I AM INVALID SYNTAX CANNOT COMPILE")
.local(true).publish();
Package::new("std", "1.0.0").local(true).publish();
Package::new("test", "1.0.0").local(true).publish();

let foo = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.0"
authors = []
implicit-dependencies = false
"#)
.file("src/lib.rs", "");
assert_that(foo.cargo_process("build").arg("-v"),
execs().with_status(0));
}

#[test]
fn mixed_expicit_and_implicit_stdlib_deps() {
setup();
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.0"
authors = []
implicit-dependencies = true
[dependencies]
foo = { stdlib = true }
"#)
.file("src/lib.rs", "");
assert_that(foo.cargo_process("build").arg("-v"),
execs().with_status(101).with_stderr("\
[ERROR] failed to parse manifest at `[..]`
Caused by:
cannot use explicit stdlib deps when implicit deps were explicitly enabled.
"));
}

#[test]
fn stdlib_replacement() {
setup();
Expand Down

0 comments on commit 2e39355

Please sign in to comment.