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

part of the infrastructure for public & private dependencies in the resolver #6653

Merged
merged 13 commits into from
Mar 6, 2019
12 changes: 12 additions & 0 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ struct Inner {
explicit_name_in_toml: Option<InternedString>,

optional: bool,
public: bool,
default_features: bool,
features: Vec<InternedString>,

@@ -217,6 +218,7 @@ impl Dependency {
kind: Kind::Normal,
only_match_name: true,
optional: false,
public: false,
features: Vec::new(),
default_features: true,
specified_req: false,
@@ -293,6 +295,16 @@ impl Dependency {
self.inner.kind
}

pub fn is_public(&self) -> bool {
self.inner.public
}

/// Sets whether the dependency is public.
pub fn set_public(&mut self, public: bool) -> &mut Dependency {
Rc::make_mut(&mut self.inner).public = public;
self
}

pub fn specified_req(&self) -> bool {
self.inner.specified_req
}
80 changes: 48 additions & 32 deletions tests/testsuite/support/resolver.rs
Original file line number Diff line number Diff line change
@@ -250,9 +250,10 @@ pub fn dep(name: &str) -> Dependency {
pub fn dep_req(name: &str, req: &str) -> Dependency {
Dependency::parse_no_deprecated(name, Some(req), registry_loc()).unwrap()
}
pub fn dep_req_kind(name: &str, req: &str, kind: Kind) -> Dependency {
pub fn dep_req_kind(name: &str, req: &str, kind: Kind, public: bool) -> Dependency {
let mut dep = dep_req(name, req);
dep.set_kind(kind);
dep.set_public(public);
dep
}

@@ -297,9 +298,12 @@ impl fmt::Debug for PrettyPrintRegistry {
} else {
write!(f, "pkg!((\"{}\", \"{}\") => [", s.name(), s.version())?;
for d in s.dependencies() {
if d.kind() == Kind::Normal && &d.version_req().to_string() == "*" {
if d.kind() == Kind::Normal
&& &d.version_req().to_string() == "*"
&& !d.is_public()
{
write!(f, "dep(\"{}\"),", d.name_in_toml())?;
} else if d.kind() == Kind::Normal {
} else if d.kind() == Kind::Normal && !d.is_public() {
write!(
f,
"dep_req(\"{}\", \"{}\"),",
@@ -309,14 +313,15 @@ impl fmt::Debug for PrettyPrintRegistry {
} else {
write!(
f,
"dep_req_kind(\"{}\", \"{}\", {}),",
"dep_req_kind(\"{}\", \"{}\", {}, {}),",
d.name_in_toml(),
d.version_req(),
match d.kind() {
Kind::Development => "Kind::Development",
Kind::Build => "Kind::Build",
Kind::Normal => "Kind::Normal",
}
},
d.is_public()
)?;
}
}
@@ -341,8 +346,10 @@ fn meta_test_deep_pretty_print_registry() {
pkg!(("bar", "2.0.0") => [dep_req("baz", "=1.0.1")]),
pkg!(("baz", "1.0.2") => [dep_req("other", "2")]),
pkg!(("baz", "1.0.1")),
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Build)]),
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Development)]),
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Build, false)]),
pkg!(("cat", "1.0.3") => [dep_req_kind("other", "2", Kind::Development, false)]),
pkg!(("cat", "1.0.4") => [dep_req_kind("other", "2", Kind::Build, true)]),
pkg!(("cat", "1.0.5") => [dep_req_kind("other", "2", Kind::Development, true)]),
pkg!(("dep_req", "1.0.0")),
pkg!(("dep_req", "2.0.0")),
])
@@ -354,8 +361,10 @@ fn meta_test_deep_pretty_print_registry() {
pkg!((\"bar\", \"2.0.0\") => [dep_req(\"baz\", \"= 1.0.1\"),]),\
pkg!((\"baz\", \"1.0.2\") => [dep_req(\"other\", \"^2\"),]),\
pkg!((\"baz\", \"1.0.1\")),\
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Build),]),\
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Development),]),\
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Build, false),]),\
pkg!((\"cat\", \"1.0.3\") => [dep_req_kind(\"other\", \"^2\", Kind::Development, false),]),\
pkg!((\"cat\", \"1.0.4\") => [dep_req_kind(\"other\", \"^2\", Kind::Build, true),]),\
pkg!((\"cat\", \"1.0.5\") => [dep_req_kind(\"other\", \"^2\", Kind::Development, true),]),\
pkg!((\"dep_req\", \"1.0.0\")),\
pkg!((\"dep_req\", \"2.0.0\")),]"
)
@@ -405,7 +414,13 @@ pub fn registry_strategy(
let max_deps = max_versions * (max_crates * (max_crates - 1)) / shrinkage;

let raw_version_range = (any::<Index>(), any::<Index>());
let raw_dependency = (any::<Index>(), any::<Index>(), raw_version_range, 0..=1);
let raw_dependency = (
any::<Index>(),
any::<Index>(),
raw_version_range,
0..=1,
any::<bool>(),
);

fn order_index(a: Index, b: Index, size: usize) -> (usize, usize) {
let (a, b) = (a.index(size), b.index(size));
@@ -432,7 +447,7 @@ pub fn registry_strategy(
.collect();
let len_all_pkgid = list_of_pkgid.len();
let mut dependency_by_pkgid = vec![vec![]; len_all_pkgid];
for (a, b, (c, d), k) in raw_dependencies {
for (a, b, (c, d), k, p) in raw_dependencies {
let (a, b) = order_index(a, b, len_all_pkgid);
let (a, b) = if reverse_alphabetical { (b, a) } else { (a, b) };
let ((dep_name, _), _) = list_of_pkgid[a];
@@ -443,27 +458,28 @@ pub fn registry_strategy(
let s_last_index = s.len() - 1;
let (c, d) = order_index(c, d, s.len());

dependency_by_pkgid[b].push(dep_req_kind(
&dep_name,
&if c == 0 && d == s_last_index {
"*".to_string()
} else if c == 0 {
format!("<={}", s[d].0)
} else if d == s_last_index {
format!(">={}", s[c].0)
} else if c == d {
format!("={}", s[c].0)
} else {
format!(">={}, <={}", s[c].0, s[d].0)
},
match k {
0 => Kind::Normal,
1 => Kind::Build,
// => Kind::Development, // Development has not impact so don't gen
_ => panic!("bad index for Kind"),
},
))
}
dependency_by_pkgid[b].push(dep_req_kind(
&dep_name,
&if c == 0 && d == s_last_index {
"*".to_string()
} else if c == 0 {
format!("<={}", s[d].0)
} else if d == s_last_index {
format!(">={}", s[c].0)
} else if c == d {
format!("={}", s[c].0)
} else {
format!(">={}, <={}", s[c].0, s[d].0)
},
match k {
0 => Kind::Normal,
1 => Kind::Build,
// => Kind::Development, // Development has not impact so don't gen
_ => panic!("bad index for Kind"),
},
p,
))
}

PrettyPrintRegistry(
list_of_pkgid