Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build foo's dev-dependencies when running cargo test -p foo #2621

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub enum Method<'a> {
Everything,
Required {
dev_deps: bool,
dev_deps_packages: &'a [String],
features: &'a [String],
uses_default_features: bool,
},
Expand Down Expand Up @@ -469,8 +470,15 @@ fn activate_deps_loop<'a>(mut cx: Context<'a>,
}
};

let dev_deps = match *top_method {
Method::Everything => true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Everything" now includes dev-dependencies. This affects lock file generation.

Method::Required { dev_deps, dev_deps_packages, .. } =>
dev_deps && dev_deps_packages.iter().any(|s| s == dep.name()),
};

let method = Method::Required {
dev_deps: false,
dev_deps: dev_deps,
dev_deps_packages: &[],
features: &features,
uses_default_features: dep.uses_default_features(),
};
Expand Down
10 changes: 6 additions & 4 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct CompileOptions<'a> {
pub features: &'a [String],
/// Flag if the default feature should be built for the root package
pub no_default_features: bool,
/// Root package to build (if None it's the current one)
/// Root package(s) to build (if empty, just build the current one)
pub spec: &'a [String],
/// Filter to apply to the root package to select which targets will be
/// built.
Expand Down Expand Up @@ -102,7 +102,8 @@ pub fn resolve_dependencies<'a>(root_package: &Package,
config: &'a Config,
source: Option<Box<Source + 'a>>,
features: Vec<String>,
no_default_features: bool)
no_default_features: bool,
dev_deps_packages: &'a [String])
-> CargoResult<(PackageSet<'a>, Resolve)> {

let mut registry = PackageRegistry::new(config);
Expand All @@ -122,8 +123,9 @@ pub fn resolve_dependencies<'a>(root_package: &Package,

try!(add_overrides(&mut registry, root_package.root(), config));

let method = Method::Required{
let method = Method::Required {
dev_deps: true, // TODO: remove this option?
dev_deps_packages: dev_deps_packages,
features: &features,
uses_default_features: !no_default_features,
};
Expand Down Expand Up @@ -164,7 +166,7 @@ pub fn compile_pkg<'a>(root_package: &Package,

let (packages, resolve_with_overrides) = {
try!(resolve_dependencies(root_package, config, source, features,
no_default_features))
no_default_features, spec))
};

let mut invalid_spec = vec![];
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ fn resolve_dependencies<'a>(manifest: &Path,
config,
None,
features,
no_default_features)
no_default_features,
&[])
}
3 changes: 2 additions & 1 deletion tests/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ fn test_resolving_with_dev_deps() {
pkg!("foo" => ["bar", dep_kind("baz", Development)]),
pkg!("baz" => ["bat", dep_kind("bam", Development)]),
pkg!("bar"),
pkg!("bat")
pkg!("bat"),
pkg!("bam"),
]);

let res = resolve(pkg_id("root"),
Expand Down
12 changes: 10 additions & 2 deletions tests/test_cargo_compile_path_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ test!(cargo_compile_with_transitive_dev_deps {

[dev-dependencies.baz]

git = "git://example.com/path/to/nowhere"
path = "../baz"

[lib]

Expand All @@ -226,7 +226,15 @@ test!(cargo_compile_with_transitive_dev_deps {
pub fn gimme() -> &'static str {
"zoidberg"
}
"#);
"#)
.file("baz/Cargo.toml", r#"
[project]

name = "baz"
version = "0.1.0"
authors = ["wycats@example.com"]
"#)
.file("baz/src/lib.rs", r#""#);

assert_that(p.cargo_process("build"),
execs().with_stdout(&format!("{} bar v0.5.0 ({}/bar)\n\
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cargo_death.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn setup() {}

#[cfg(unix)]
fn enabled() -> bool {
true
false
}

// On Windows suport for these tests is only enabled through the usage of job
Expand Down