Authentication-Results: mail-b.sr.ht; dkim=pass header.d=ireas.org header.i=@ireas.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by mail-b.sr.ht (Postfix) with ESMTPS id E043A11F060 for <~ireas/public-inbox@lists.sr.ht>; Wed, 21 Sep 2022 07:17:23 +0000 (UTC) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4MXV9F09vtz9snK; Wed, 21 Sep 2022 09:17:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ireas.org; s=MBO0001; t=1663744641; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XfdhMyIjTJ8V0Mr3X9N/yR/hTdBdLz67+vTBoMfR9pk=; b=m/Bcj6/2GlhLJ/qUB2FBJIzLhHSF8RetvJ3oAGw1HkCQnXrRw5fbh0DvuSattchxBd0iXN OQYg1k72c9qRVipvp7f3cq2a7bV/a9OVK8lL8zXWLKqlq/RXqbjdM3HkijMpeTzr69yDXO 1i/m682ccYQrZ/UBNusujFtKwha88DFEHg1GCwjSvgtOWatGdlA/PP19RjotQF3B2ZHWnM j/vEQuSEJ15WhEHeQER3eQD3h/cTLgW/dUJPhGmQG3yRm3G0i/sintHA3VyzTiwCMDZL6z Rx7mvpiXZMiCqvv17bRPkeiCtHz6MCxTJUPoz5aWYCC+naOYfwSXTGoNIBt/Jg== Date: Wed, 21 Sep 2022 09:17:16 +0200 From: Robin Krahl To: Nathan Wilcox , Jonas Platte Cc: ~ireas/public-inbox@lists.sr.ht Subject: Re: [PATCH cargo-depgraph] Message-ID: <20220921071716.GA1221@ireas.org> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="AqsLC8rIMeq19msA" Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4MXV9F09vtz9snK --AqsLC8rIMeq19msA Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Nathan, I=E2=80=99m not affiliated with the cargo-depgraph project. You should pro= bably send the patch directly to Jonas. Best, Robin On 2022-09-20 15:03:29, Nathan Wilcox wrote: > This patch adds a `--workspace-only` option which constrains the graph > to only workspace crates. This is useful for understanding > intra-workspace dependencies. >=20 > --- > src/cli.rs | 8 ++++++++ > src/graph.rs | 20 ++++++++++++++++++++ > src/main.rs | 6 +++++- > 3 files changed, 33 insertions(+), 1 deletion(-) >=20 > diff --git a/src/cli.rs b/src/cli.rs > index e9f2aa1..72b3fff 100644 > --- a/src/cli.rs > +++ b/src/cli.rs > @@ -7,6 +7,7 @@ pub struct Config { > pub dedup_transitive_deps: bool, > pub hide: Vec, > pub exclude: Vec, > + pub workspace_only: bool, > pub focus: Vec, >=20 > pub features: Vec, > @@ -76,6 +77,11 @@ pub fn parse_options() -> Config { > dependency kind resolution", > ), > ) > + .arg( > + Arg::new("workspace_only") > + .long("workspace-only") > + .help("Exclude all packages outside of the works= pace"), > + ) > .arg( > Arg::new("focus") > .long("focus") > @@ -155,6 +161,7 @@ pub fn parse_options() -> Config { > let dedup_transitive_deps =3D matches.is_present("dedup_transitive_d= eps"); > let hide =3D matches.values_of("hide").map_or_else(Vec::new, collect= _owned); > let exclude =3D matches.values_of("exclude").map_or_else(Vec::new, > collect_owned); > + let workspace_only =3D matches.is_present("workspace_only"); > let focus =3D matches.values_of("focus").map_or_else(Vec::new, > collect_owned); >=20 > let features =3D > matches.values_of("features").map_or_else(Vec::new, collect_owned); > @@ -174,6 +181,7 @@ pub fn parse_options() -> Config { > dedup_transitive_deps, > hide, > exclude, > + workspace_only, > focus, > features, > all_features, > diff --git a/src/graph.rs b/src/graph.rs > index d41c0d3..d4f329c 100644 > --- a/src/graph.rs > +++ b/src/graph.rs > @@ -80,6 +80,26 @@ fn update_node(graph: &mut DepGraph, idx: NodeIndex) { > } > } >=20 > +pub fn remove_non_workspace_deps(graph: &mut DepGraph) { > + let mut visit_queue: VecDeque<_> =3D > graph.externals(Direction::Outgoing).collect(); > + while let Some(idx) =3D visit_queue.pop_front() { > + // A node can end up being in the list multiple times. If it > was already removed by a > + // previous iteration of this loop, skip it. > + if !graph.contains_node(idx) { > + continue; > + } > + > + let pkg =3D &graph[idx]; > + if !pkg.is_ws_member { > + // The package node at `idx` should be removed. > + // =3D> First add its dependencies to the visit queue > + visit_queue.extend(graph.neighbors_directed(idx, > Direction::Incoming)); > + // =3D> Then actually remove it > + graph.remove_node(idx); > + } > + } > +} > + > pub fn remove_irrelevant_deps(graph: &mut DepGraph, focus: &[String]) { > let mut visit_queue: VecDeque<_> =3D > graph.externals(Direction::Outgoing).collect(); > while let Some(idx) =3D visit_queue.pop_front() { > diff --git a/src/main.rs b/src/main.rs > index c86af4f..25c7ee3 100644 > --- a/src/main.rs > +++ b/src/main.rs > @@ -20,7 +20,8 @@ mod output; > use self::{ > cli::parse_options, > graph::{ > - dedup_transitive_deps, get_dep_graph, remove_deps, > remove_irrelevant_deps, update_dep_info, > + dedup_transitive_deps, get_dep_graph, remove_deps, > remove_irrelevant_deps, > + remove_non_workspace_deps, update_dep_info, > }, > output::dot, > util::set_name_stats, > @@ -59,6 +60,9 @@ fn main() -> anyhow::Result<()> { >=20 > let mut graph =3D get_dep_graph(metadata, &config)?; > update_dep_info(&mut graph); > + if config.workspace_only { > + remove_non_workspace_deps(&mut graph); > + } > if !config.focus.is_empty() { > remove_irrelevant_deps(&mut graph, &config.focus); > } > --=20 > 2.30.2 --AqsLC8rIMeq19msA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEXP0gHdh2xl8puuMojpsIcFJPadgFAmMqunYACgkQjpsIcFJP adjcVw/+Jomxe1RAHkWB/TH/CEFH+zzZI+q1Vg5sIHzd/VyF2R34SVhhMCVloxmc hpcglmm7rDQQEiUnmsD2betRYvuZ5KTpCSjHkF/nhFeU/ww8azX0RXFa1otqNp6d qt6Z/1iXLn6TZFr+KkvA0Zhz+iP2KBpgJU8rB09a8Y8wo9fk9/JszV5TP3ARaJbj h4g1zT5+zBcAmnBXevRTDJjCjiiUc1kF8xKdXzgDWAqmKW7hft9kR2P2KmBI0wGp yyiU+FCnXaJctKQKzqmBPiMQHSAAx/mmYPxhlIDivOPNTNWa0gi6z6vORKg4CvZ3 iBDLWicZ8dXAKeUKNY9XM23yzxna3i1nsGk29rQCZLC3Y4Uv6ruWs1pVv9Ap1Xmw Lfnud5zDBir1XX4rURusOI75GEM9FfEPeTxvREu4OcRQjWMau5l6IJhMIdMtcNRS H0Gk6j6LDi+qm09KWoOfbNh3XSK8/ZlJvLon/5Qk9XbrunDKDhbsdxnUO/3Uo4BZ hSPrMDpU95tNHfsdeE/GLp7JGqv37triM4G4hHthtFNjVsqNq7TkGs7DgVNFc/85 RWL6UH+zan1yDFatAFxkhy8xh33GOYKpbpT6iiiamh6Bx5ltFC8RbPU/o9QPgUQf ZHy5b1UF26l0TbyDd4fnJEp8O6bSW/AjTBssref62BCtEF3/mHA= =FF3v -----END PGP SIGNATURE----- --AqsLC8rIMeq19msA--