Skip to content

Commit

Permalink
add the -Zallow-yanked-deps unstable CLI flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Sep 4, 2018
1 parent 78bae45 commit 226eefd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ pub struct CliUnstable {
pub advanced_env: bool,
pub config_profile: bool,
pub compile_progress: bool,
pub allow_yanked_deps: bool,
}

impl CliUnstable {
Expand Down Expand Up @@ -355,6 +356,7 @@ impl CliUnstable {
"advanced-env" => self.advanced_env = true,
"config-profile" => self.config_profile = true,
"compile-progress" => self.compile_progress = true,
"allow-yanked-deps" => self.allow_yanked_deps = true,
_ => bail!("unknown `-Z` flag specified: {}", k),
}

Expand Down
5 changes: 4 additions & 1 deletion src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,15 @@ impl<'cfg> RegistryIndex<'cfg> {
load: &mut RegistryData,
f: &mut FnMut(Summary),
) -> CargoResult<()> {
let allow_yanked_deps = self.config.cli_unstable().allow_yanked_deps;
let source_id = self.source_id.clone();
let name = dep.package_name().as_str();
let summaries = self.summaries(name, load)?;
let summaries = summaries
.iter()
.filter(|&&(_, yanked)| dep.source_id().precise().is_some() || !yanked)
.filter(|&&(_, yanked)| {
dep.source_id().precise().is_some() || allow_yanked_deps || !yanked
})
.map(|s| s.0.clone());

// Handle `cargo update --precise` here. If specified, our own source
Expand Down
36 changes: 36 additions & 0 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,42 @@ required by package `bar v0.0.1`
).run();
}

#[test]
fn yanks_are_used_with_z_flag() {
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
bar = "*"
"#,
).file("src/main.rs", "fn main() {}")
.build();

Package::new("baz", "0.0.1").publish();
Package::new("baz", "0.0.2").yanked(true).publish();
Package::new("bar", "0.0.1").dep("baz", "=0.0.2").publish();

p.cargo("build -Zallow-yanked-deps")
.masquerade_as_nightly_cargo()
.with_stderr(&format!(
"\
[UPDATING] registry `[..]`
[DOWNLOADING] [..] (registry `file://[..]`)
[DOWNLOADING] [..] (registry `file://[..]`)
[COMPILING] baz v0.0.2
[COMPILING] bar v0.0.1
[COMPILING] foo v0.0.1 (CWD)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
",
)).run();
}

#[test]
fn yanks_in_lockfiles_are_ok() {
let p = project()
Expand Down

0 comments on commit 226eefd

Please sign in to comment.