@@ -63,7 +63,7 @@ enum Command {
6363 PrepareRelease {
6464 /// Crates to release. Will traverse that crate an it's dependents. If not specified checks all crates.
6565 /// Crates specified in this list must be diseparate in the dependency tree
66- #[ arg( value_name = "CRATE " ) ]
66+ #[ arg( value_name = "CRATES " ) ]
6767 crate_names : Vec < String > ,
6868 } ,
6969}
@@ -156,6 +156,24 @@ fn discover_crates(dir: &PathBuf, crates: &mut BTreeMap<CrateId, Crate>) -> Resu
156156 }
157157 }
158158
159+ let mut dev_dependencies = Vec :: new ( ) ;
160+ if let Some ( deps) = parsed. dev_dependencies {
161+ for ( k, _) in deps {
162+ if k. starts_with ( "embassy-" ) {
163+ dev_dependencies. push ( k) ;
164+ }
165+ }
166+ }
167+
168+ let mut build_dependencies = Vec :: new ( ) ;
169+ if let Some ( deps) = parsed. build_dependencies {
170+ for ( k, _) in deps {
171+ if k. starts_with ( "embassy-" ) {
172+ build_dependencies. push ( k) ;
173+ }
174+ }
175+ }
176+
159177 let mut configs = metadata. build . clone ( ) ;
160178 if configs. is_empty ( ) {
161179 configs. push ( BuildConfig {
@@ -172,6 +190,8 @@ fn discover_crates(dir: &PathBuf, crates: &mut BTreeMap<CrateId, Crate>) -> Resu
172190 version : parsed. package . version ,
173191 path,
174192 dependencies,
193+ dev_dependencies,
194+ build_dependencies,
175195 configs,
176196 publish : parsed. package . publish ,
177197 } ,
@@ -192,7 +212,8 @@ fn discover_crates(dir: &PathBuf, crates: &mut BTreeMap<CrateId, Crate>) -> Resu
192212
193213fn build_graph (
194214 crates : & BTreeMap < CrateId , Crate > ,
195- ) -> ( Graph < CrateId , ( ) > , HashMap < CrateId , NodeIndex > ) {
215+ select_deps : impl Fn ( & Crate ) -> & Vec < CrateId > ,
216+ ) -> GraphContext {
196217 let mut graph = Graph :: < CrateId , ( ) , Directed > :: new ( ) ;
197218 let mut node_indices: HashMap < CrateId , NodeIndex > = HashMap :: new ( ) ;
198219
@@ -217,20 +238,30 @@ fn build_graph(
217238 let crate_idx = get_or_insert_node ( krate. name . clone ( ) , & mut graph, & mut node_indices) ;
218239
219240 // Insert dependencies and connect edges
220- for dep in krate. dependencies . iter ( ) {
241+ for dep in select_deps ( krate) . iter ( ) {
221242 let dep_idx = get_or_insert_node ( dep. clone ( ) , & mut graph, & mut node_indices) ;
222243 graph. add_edge ( crate_idx, dep_idx, ( ) ) ;
223244 }
224245 }
225246
226- ( graph, node_indices)
247+ graph. reverse ( ) ;
248+ GraphContext {
249+ g : graph,
250+ i : node_indices,
251+ }
227252}
228253
229254struct Context {
230255 root : PathBuf ,
231256 crates : BTreeMap < String , Crate > ,
232- graph : Graph < String , ( ) > ,
233- indices : HashMap < String , NodeIndex > ,
257+ graph : GraphContext ,
258+ dev_graph : GraphContext ,
259+ build_graph : GraphContext ,
260+ }
261+
262+ struct GraphContext {
263+ g : Graph < String , ( ) > ,
264+ i : HashMap < String , NodeIndex > ,
234265}
235266
236267fn find_repo_root ( ) -> Result < PathBuf > {
@@ -257,13 +288,16 @@ fn find_repo_root() -> Result<PathBuf> {
257288fn load_context ( ) -> Result < Context > {
258289 let root = find_repo_root ( ) ?;
259290 let crates = list_crates ( & root) ?;
260- let ( graph, indices) = build_graph ( & crates) ;
291+ let graph = build_graph ( & crates, |c| & c. dependencies ) ;
292+ let dev_graph = build_graph ( & crates, |c| & c. dev_dependencies ) ;
293+ let build_graph = build_graph ( & crates, |c| & c. build_dependencies ) ;
261294
262295 let ctx = Context {
263296 root,
264297 crates,
265298 graph,
266- indices,
299+ dev_graph,
300+ build_graph,
267301 } ;
268302
269303 // Check for publish dependency conflicts
@@ -287,12 +321,12 @@ fn main() -> Result<()> {
287321
288322 match args. command {
289323 Command :: List => {
290- let ordered = petgraph:: algo:: toposort ( & ctx. graph , None ) . unwrap ( ) ;
324+ let ordered = petgraph:: algo:: toposort ( & ctx. graph . g , None ) . unwrap ( ) ;
291325 for node in ordered. iter ( ) {
292- let start = ctx. graph . node_weight ( * node) . unwrap ( ) ;
293- let mut bfs = Bfs :: new ( & ctx. graph , * node) ;
294- while let Some ( node) = bfs. next ( & ctx. graph ) {
295- let weight = ctx. graph . node_weight ( node) . unwrap ( ) ;
326+ let start = ctx. graph . g . node_weight ( * node) . unwrap ( ) ;
327+ let mut bfs = Bfs :: new ( & ctx. graph . g , * node) ;
328+ while let Some ( node) = bfs. next ( & ctx. graph . g ) {
329+ let weight = ctx. graph . g . node_weight ( node) . unwrap ( ) ;
296330 let c = ctx. crates . get ( weight) . unwrap ( ) ;
297331 if weight == start {
298332 println ! ( "+ {}-{}" , weight, c. version) ;
@@ -305,12 +339,13 @@ fn main() -> Result<()> {
305339 }
306340 Command :: Dependencies { crate_name } => {
307341 let idx = ctx
308- . indices
342+ . graph
343+ . i
309344 . get ( & crate_name)
310345 . expect ( "unable to find crate in tree" ) ;
311- let mut bfs = Bfs :: new ( & ctx. graph , * idx) ;
312- while let Some ( node) = bfs. next ( & ctx. graph ) {
313- let weight = ctx. graph . node_weight ( node) . unwrap ( ) ;
346+ let mut bfs = Bfs :: new ( & ctx. graph . g , * idx) ;
347+ while let Some ( node) = bfs. next ( & ctx. graph . g ) {
348+ let weight = ctx. graph . g . node_weight ( node) . unwrap ( ) ;
314349 let crt = ctx. crates . get ( weight) . unwrap ( ) ;
315350 if * weight == crate_name {
316351 println ! ( "+ {}-{}" , weight, crt. version) ;
@@ -321,14 +356,15 @@ fn main() -> Result<()> {
321356 }
322357 Command :: Dependents { crate_name } => {
323358 let idx = ctx
324- . indices
359+ . graph
360+ . i
325361 . get ( & crate_name)
326362 . expect ( "unable to find crate in tree" ) ;
327- let weight = ctx. graph . node_weight ( * idx) . unwrap ( ) ;
363+ let weight = ctx. graph . g . node_weight ( * idx) . unwrap ( ) ;
328364 let crt = ctx. crates . get ( weight) . unwrap ( ) ;
329365 println ! ( "+ {}-{}" , weight, crt. version) ;
330- for parent in ctx. graph . neighbors_directed ( * idx, Direction :: Incoming ) {
331- let weight = ctx. graph . node_weight ( parent) . unwrap ( ) ;
366+ for parent in ctx. graph . g . neighbors_directed ( * idx, Direction :: Incoming ) {
367+ let weight = ctx. graph . g . node_weight ( parent) . unwrap ( ) ;
332368 let crt = ctx. crates . get ( weight) . unwrap ( ) ;
333369 println ! ( "|- {}-{}" , weight, crt. version) ;
334370 }
@@ -350,10 +386,11 @@ fn main() -> Result<()> {
350386 // Check if the target crates are publishable
351387 for crate_name in & crate_names {
352388 let start = ctx
353- . indices
389+ . graph
390+ . i
354391 . get ( crate_name)
355392 . expect ( "unable to find crate in tree" ) ;
356- let start_weight = ctx. graph . node_weight ( * start) . unwrap ( ) ;
393+ let start_weight = ctx. graph . g . node_weight ( * start) . unwrap ( ) ;
357394 let start_crate = ctx. crates . get ( start_weight) . unwrap ( ) ;
358395 if !start_crate. publish {
359396 bail ! (
@@ -363,21 +400,19 @@ fn main() -> Result<()> {
363400 }
364401 }
365402
366- let mut rgraph = ctx. graph . clone ( ) ;
367- rgraph. reverse ( ) ;
368-
369403 let mut to_bump = HashMap :: new ( ) ;
370404 // Do semver checks to figure out which versions to bump
371405 for crate_name in & crate_names {
372406 if !to_bump. contains_key ( crate_name) {
373407 let start = ctx
374- . indices
408+ . graph
409+ . i
375410 . get ( crate_name)
376411 . expect ( "unable to find crate in tree" ) ;
377412
378- let mut bfs = Bfs :: new ( & rgraph , * start) ;
379- while let Some ( node) = bfs. next ( & rgraph ) {
380- let weight = rgraph . node_weight ( node) . unwrap ( ) ;
413+ let mut bfs = Bfs :: new ( & ctx . graph . g , * start) ;
414+ while let Some ( node) = bfs. next ( & ctx . graph . g ) {
415+ let weight = ctx . graph . g . node_weight ( node) . unwrap ( ) ;
381416 println ! ( "Preparing {weight}" ) ;
382417 let c = ctx. crates . get ( weight) . unwrap ( ) ;
383418 if c. publish {
@@ -424,17 +459,9 @@ fn main() -> Result<()> {
424459 let c = ctx. crates . get ( name) . unwrap ( ) ;
425460
426461 // Update all nodes further down the tree
427- let node = ctx. indices . get ( name) . expect ( "unable to find crate in tree" ) ;
428- let mut bfs = Bfs :: new ( & rgraph, * node) ;
429- while let Some ( dep_node) = bfs. next ( & rgraph) {
430- let dep_weight = rgraph. node_weight ( dep_node) . unwrap ( ) ;
431- println ! (
432- "Updating {}-{} -> {} for {}" ,
433- c. name, oldver, newver, dep_weight
434- ) ;
435- let dep = ctx. crates . get ( dep_weight) . unwrap ( ) ;
436- update_versions ( dep, & c. name , & newver) ?;
437- }
462+ update_graph_deps ( & ctx, & ctx. graph , name, & oldver, & newver) ?;
463+ update_graph_deps ( & ctx, & ctx. build_graph , name, & oldver, & newver) ?;
464+ update_graph_deps ( & ctx, & ctx. dev_graph , name, & oldver, & newver) ?;
438465
439466 // Update changelog
440467 update_changelog ( & ctx. root , c) ?;
@@ -443,19 +470,20 @@ fn main() -> Result<()> {
443470 let mut processed = HashSet :: new ( ) ;
444471 for crate_name in & crate_names {
445472 let start = ctx
446- . indices
473+ . graph
474+ . i
447475 . get ( crate_name)
448476 . expect ( "unable to find crate in tree" ) ;
449- let weight = rgraph . node_weight ( * start) . unwrap ( ) ;
477+ let weight = ctx . graph . g . node_weight ( * start) . unwrap ( ) ;
450478 let c = ctx. crates . get ( weight) . unwrap ( ) ;
451479 publish_release ( & ctx. root , c, false ) ?;
452480
453481 println ! ( "# Please inspect changes and run the following commands when happy:" ) ;
454482
455483 println ! ( "git commit -a -m 'chore: prepare crate releases'" ) ;
456- let mut bfs = Bfs :: new ( & rgraph , * start) ;
457- while let Some ( node) = bfs. next ( & rgraph ) {
458- let weight = rgraph . node_weight ( node) . unwrap ( ) ;
484+ let mut bfs = Bfs :: new ( & ctx . graph . g , * start) ;
485+ while let Some ( node) = bfs. next ( & ctx . graph . g ) {
486+ let weight = ctx . graph . g . node_weight ( node) . unwrap ( ) ;
459487 let c = ctx. crates . get ( weight) . unwrap ( ) ;
460488 if c. publish && !processed. contains ( weight) {
461489 println ! ( "git tag {}-v{}" , weight, c. version) ;
@@ -465,9 +493,9 @@ fn main() -> Result<()> {
465493 println ! ( ) ;
466494 println ! ( "# Run these commands to publish the crate and dependents:" ) ;
467495
468- let mut bfs = Bfs :: new ( & rgraph , * start) ;
469- while let Some ( node) = bfs. next ( & rgraph ) {
470- let weight = rgraph . node_weight ( node) . unwrap ( ) ;
496+ let mut bfs = Bfs :: new ( & ctx . graph . g , * start) ;
497+ while let Some ( node) = bfs. next ( & ctx . graph . g ) {
498+ let weight = ctx . graph . g . node_weight ( node) . unwrap ( ) ;
471499
472500 if !processed. contains ( weight) {
473501 processed. insert ( weight. clone ( ) ) ;
@@ -517,6 +545,27 @@ fn check_semver(root: PathBuf, c: &Crate) -> Result<ReleaseType> {
517545 Ok ( min_version)
518546}
519547
548+ fn update_graph_deps (
549+ ctx : & Context ,
550+ graph : & GraphContext ,
551+ name : & CrateId ,
552+ oldver : & str ,
553+ newver : & str ,
554+ ) -> Result < ( ) , anyhow:: Error > {
555+ let node = graph. i . get ( name) . expect ( "unable to find crate in tree" ) ;
556+ let mut bfs = Bfs :: new ( & graph. g , * node) ;
557+ while let Some ( dep_node) = bfs. next ( & graph. g ) {
558+ let dep_weight = graph. g . node_weight ( dep_node) . unwrap ( ) ;
559+ println ! (
560+ "Updating {}-{} -> {} for {}" ,
561+ name, oldver, newver, dep_weight
562+ ) ;
563+ let dep = ctx. crates . get ( dep_weight) . unwrap ( ) ;
564+ update_versions ( dep, name, newver) ?;
565+ }
566+ Ok ( ( ) )
567+ }
568+
520569fn update_changelog ( repo : & Path , c : & Crate ) -> Result < ( ) > {
521570 let args: Vec < String > = vec ! [
522571 "release" . to_string( ) ,
0 commit comments