Skip to content

Commit 99d3fed

Browse files
committed
feat(tree): Add unstable support for --edges public
1 parent b89128d commit 99d3fed

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/bin/cargo/commands/tree.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
157157
};
158158
let target = tree::Target::from_cli(targets);
159159

160-
let (edge_kinds, no_proc_macro) = parse_edge_kinds(gctx, args)?;
160+
let (edge_kinds, no_proc_macro, public) = parse_edge_kinds(gctx, args)?;
161161
let graph_features = edge_kinds.contains(&EdgeKind::Feature);
162162

163163
let pkgs_to_prune = args._values_of("prune");
@@ -230,6 +230,7 @@ subtree of the package given to -p.\n\
230230
graph_features,
231231
display_depth,
232232
no_proc_macro,
233+
public,
233234
};
234235

235236
if opts.graph_features && opts.duplicates {
@@ -246,9 +247,10 @@ subtree of the package given to -p.\n\
246247
fn parse_edge_kinds(
247248
gctx: &GlobalContext,
248249
args: &ArgMatches,
249-
) -> CargoResult<(HashSet<EdgeKind>, bool)> {
250-
let (kinds, no_proc_macro) = {
250+
) -> CargoResult<(HashSet<EdgeKind>, bool, bool)> {
251+
let (kinds, no_proc_macro, public) = {
251252
let mut no_proc_macro = false;
253+
let mut public = false;
252254
let mut kinds = args.get_many::<String>("edges").map_or_else(
253255
|| Vec::new(),
254256
|es| {
@@ -257,6 +259,9 @@ fn parse_edge_kinds(
257259
if *e == "no-proc-macro" {
258260
no_proc_macro = true;
259261
false
262+
} else if *e == "public" {
263+
public = true;
264+
false
260265
} else {
261266
true
262267
}
@@ -275,7 +280,11 @@ fn parse_edge_kinds(
275280
kinds.extend(&["normal", "build", "dev"]);
276281
}
277282

278-
(kinds, no_proc_macro)
283+
if public && !gctx.cli_unstable().unstable_options {
284+
anyhow::bail!("`--edges public` requires `-Zunstable-options`");
285+
}
286+
287+
(kinds, no_proc_macro, public)
279288
};
280289

281290
let mut result = HashSet::new();
@@ -312,7 +321,7 @@ fn parse_edge_kinds(
312321
k => return unknown(k),
313322
};
314323
}
315-
return Ok((result, no_proc_macro));
324+
return Ok((result, no_proc_macro, public));
316325
}
317326
for kind in &kinds {
318327
match *kind {
@@ -338,5 +347,5 @@ fn parse_edge_kinds(
338347
if kinds.len() == 1 && kinds[0] == "features" {
339348
insert_defaults(&mut result);
340349
}
341-
Ok((result, no_proc_macro))
350+
Ok((result, no_proc_macro, public))
342351
}

src/cargo/ops/tree/graph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ fn add_pkg(
457457
if opts.no_proc_macro && graph.package_for_id(dep_id).proc_macro() {
458458
return false;
459459
}
460+
// Filter out private dependencies if requested.
461+
if opts.public && !dep.is_public() {
462+
return false;
463+
}
460464
if dep.is_optional() {
461465
// If the new feature resolver does not enable this
462466
// optional dep, then don't use it.

src/cargo/ops/tree/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ pub struct TreeOptions {
5050
pub display_depth: DisplayDepth,
5151
/// Excludes proc-macro dependencies.
5252
pub no_proc_macro: bool,
53+
/// Include only public dependencies.
54+
pub public: bool,
5355
}
5456

5557
#[derive(PartialEq)]

0 commit comments

Comments
 (0)