Skip to content

Commit c3e67c3

Browse files
committed
gen public deps
1 parent 25bf8cc commit c3e67c3

File tree

2 files changed

+60
-32
lines changed

2 files changed

+60
-32
lines changed

src/cargo/core/dependency.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct Inner {
4040
explicit_name_in_toml: Option<InternedString>,
4141

4242
optional: bool,
43+
public: bool,
4344
default_features: bool,
4445
features: Vec<InternedString>,
4546

@@ -217,6 +218,7 @@ impl Dependency {
217218
kind: Kind::Normal,
218219
only_match_name: true,
219220
optional: false,
221+
public: false,
220222
features: Vec::new(),
221223
default_features: true,
222224
specified_req: false,
@@ -293,6 +295,16 @@ impl Dependency {
293295
self.inner.kind
294296
}
295297

298+
pub fn is_public(&self) -> bool {
299+
self.inner.public
300+
}
301+
302+
/// Sets whether the dependency is public.
303+
pub fn set_public(&mut self, public: bool) -> &mut Dependency {
304+
Rc::make_mut(&mut self.inner).public = public;
305+
self
306+
}
307+
296308
pub fn specified_req(&self) -> bool {
297309
self.inner.specified_req
298310
}

tests/testsuite/support/resolver.rs

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@ pub fn dep(name: &str) -> Dependency {
250250
pub fn dep_req(name: &str, req: &str) -> Dependency {
251251
Dependency::parse_no_deprecated(name, Some(req), registry_loc()).unwrap()
252252
}
253-
pub fn dep_req_kind(name: &str, req: &str, kind: Kind) -> Dependency {
253+
pub fn dep_req_kind(name: &str, req: &str, kind: Kind, public: bool) -> Dependency {
254254
let mut dep = dep_req(name, req);
255255
dep.set_kind(kind);
256+
dep.set_public(public);
256257
dep
257258
}
258259

@@ -297,9 +298,12 @@ impl fmt::Debug for PrettyPrintRegistry {
297298
} else {
298299
write!(f, "pkg!((\"{}\", \"{}\") => [", s.name(), s.version())?;
299300
for d in s.dependencies() {
300-
if d.kind() == Kind::Normal && &d.version_req().to_string() == "*" {
301+
if d.kind() == Kind::Normal
302+
&& &d.version_req().to_string() == "*"
303+
&& !d.is_public()
304+
{
301305
write!(f, "dep(\"{}\"),", d.name_in_toml())?;
302-
} else if d.kind() == Kind::Normal {
306+
} else if d.kind() == Kind::Normal && !d.is_public() {
303307
write!(
304308
f,
305309
"dep_req(\"{}\", \"{}\"),",
@@ -309,14 +313,15 @@ impl fmt::Debug for PrettyPrintRegistry {
309313
} else {
310314
write!(
311315
f,
312-
"dep_req_kind(\"{}\", \"{}\", {}),",
316+
"dep_req_kind(\"{}\", \"{}\", {}, {}),",
313317
d.name_in_toml(),
314318
d.version_req(),
315319
match d.kind() {
316320
Kind::Development => "Kind::Development",
317321
Kind::Build => "Kind::Build",
318322
Kind::Normal => "Kind::Normal",
319-
}
323+
},
324+
d.is_public()
320325
)?;
321326
}
322327
}
@@ -341,8 +346,10 @@ fn meta_test_deep_pretty_print_registry() {
341346
pkg!(("bar", "2.0.0") => [dep_req("baz", "=1.0.1")]),
342347
pkg!(("baz", "1.0.2") => [dep_req("other", "2")]),
343348
pkg!(("baz", "1.0.1")),
344-
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Build)]),
345-
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Development)]),
349+
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Build, false)]),
350+
pkg!(("cat", "1.0.3") => [dep_req_kind("other", "2", Kind::Development, false)]),
351+
pkg!(("cat", "1.0.4") => [dep_req_kind("other", "2", Kind::Build, true)]),
352+
pkg!(("cat", "1.0.5") => [dep_req_kind("other", "2", Kind::Development, true)]),
346353
pkg!(("dep_req", "1.0.0")),
347354
pkg!(("dep_req", "2.0.0")),
348355
])
@@ -354,8 +361,10 @@ fn meta_test_deep_pretty_print_registry() {
354361
pkg!((\"bar\", \"2.0.0\") => [dep_req(\"baz\", \"= 1.0.1\"),]),\
355362
pkg!((\"baz\", \"1.0.2\") => [dep_req(\"other\", \"^2\"),]),\
356363
pkg!((\"baz\", \"1.0.1\")),\
357-
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Build),]),\
358-
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Development),]),\
364+
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Build, false),]),\
365+
pkg!((\"cat\", \"1.0.3\") => [dep_req_kind(\"other\", \"^2\", Kind::Development, false),]),\
366+
pkg!((\"cat\", \"1.0.4\") => [dep_req_kind(\"other\", \"^2\", Kind::Build, true),]),\
367+
pkg!((\"cat\", \"1.0.5\") => [dep_req_kind(\"other\", \"^2\", Kind::Development, true),]),\
359368
pkg!((\"dep_req\", \"1.0.0\")),\
360369
pkg!((\"dep_req\", \"2.0.0\")),]"
361370
)
@@ -405,7 +414,13 @@ pub fn registry_strategy(
405414
let max_deps = max_versions * (max_crates * (max_crates - 1)) / shrinkage;
406415

407416
let raw_version_range = (any::<Index>(), any::<Index>());
408-
let raw_dependency = (any::<Index>(), any::<Index>(), raw_version_range, 0..=1);
417+
let raw_dependency = (
418+
any::<Index>(),
419+
any::<Index>(),
420+
raw_version_range,
421+
0..=1,
422+
any::<bool>(),
423+
);
409424

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

446-
dependency_by_pkgid[b].push(dep_req_kind(
447-
&dep_name,
448-
&if c == 0 && d == s_last_index {
449-
"*".to_string()
450-
} else if c == 0 {
451-
format!("<={}", s[d].0)
452-
} else if d == s_last_index {
453-
format!(">={}", s[c].0)
454-
} else if c == d {
455-
format!("={}", s[c].0)
456-
} else {
457-
format!(">={}, <={}", s[c].0, s[d].0)
458-
},
459-
match k {
460-
0 => Kind::Normal,
461-
1 => Kind::Build,
462-
// => Kind::Development, // Development has not impact so don't gen
463-
_ => panic!("bad index for Kind"),
464-
},
465-
))
466-
}
461+
dependency_by_pkgid[b].push(dep_req_kind(
462+
&dep_name,
463+
&if c == 0 && d == s_last_index {
464+
"*".to_string()
465+
} else if c == 0 {
466+
format!("<={}", s[d].0)
467+
} else if d == s_last_index {
468+
format!(">={}", s[c].0)
469+
} else if c == d {
470+
format!("={}", s[c].0)
471+
} else {
472+
format!(">={}, <={}", s[c].0, s[d].0)
473+
},
474+
match k {
475+
0 => Kind::Normal,
476+
1 => Kind::Build,
477+
// => Kind::Development, // Development has not impact so don't gen
478+
_ => panic!("bad index for Kind"),
479+
},
480+
p,
481+
))
482+
}
467483

468484
PrettyPrintRegistry(
469485
list_of_pkgid

0 commit comments

Comments
 (0)