@@ -15,14 +15,16 @@ use indexmap::{IndexMap, IndexSet};
1515use petgraph:: {
1616 acyclic:: Acyclic ,
1717 graph:: { DiGraph , NodeIndex } ,
18+ Direction ,
1819} ;
1920use semver:: { Comparator , Op , Version , VersionReq } ;
2021use tokio:: io:: { AsyncRead , AsyncReadExt } ;
22+ use tracing:: Level ;
2123use wasm_pkg_client:: {
2224 caching:: { CachingClient , FileCache } ,
2325 Client , Config , ContentDigest , Error as WasmPkgError , PackageRef , Release , VersionInfo ,
2426} ;
25- use wasm_pkg_common:: registry :: { DependencyGraph , DependencyOf } ;
27+ use wasm_pkg_common:: { package :: PackageSpec , registry :: DependencyGraph } ;
2628use wit_component:: DecodedWasm ;
2729use wit_parser:: { PackageId , PackageName , Resolve , UnresolvedPackageGroup , WorldId } ;
2830
@@ -171,32 +173,6 @@ pub struct LocalResolution {
171173 pub path : PathBuf ,
172174}
173175
174- pub struct LocalDependencies {
175- pub packages : HashMap < PackageRef , LocalResolution > ,
176- pub graph : DiGraph < PackageRef , DependencyOf > ,
177- }
178-
179- impl LocalDependencies {
180- pub fn sort ( & self ) -> Result < Vec < PackageRef > > {
181- // sort our packages topologically
182- let acyclic_graph = Acyclic :: try_from ( self . graph . clone ( ) ) . map_err ( |e| {
183- anyhow:: anyhow!(
184- "detected cyclical dependencies with package: {}" ,
185- self . graph[ e. node_id( ) ]
186- )
187- } ) ?;
188-
189- Ok ( acyclic_graph
190- . nodes_iter ( )
191- . map ( |id| self . graph [ id] . clone ( ) )
192- . collect ( ) )
193- }
194-
195- pub fn has_no_dependencies ( & self ) -> bool {
196- self . graph . raw_edges ( ) . is_empty ( )
197- }
198- }
199-
200176/// Represents a resolution of a dependency.
201177#[ derive( Debug , Clone ) ]
202178#[ allow( clippy:: large_enum_variant) ]
@@ -872,11 +848,11 @@ fn visit<'a>(
872848/// State for tracking dependencies during upload.
873849pub struct PublishPlan {
874850 /// Graph of publishable packages where the edges are `(dependency -DependencyOf->) dependent)`
875- dependents : DependencyGraph < PackageRef > ,
851+ dependents : DependencyGraph < PackageSpec > ,
876852 /// Mapping [`PackageRef`]s to the respective index inside the dependency graph.
877853 // TODO look at using cargo's `InternedString` type for `PackageRef`:
878854 // https://docs.rs/cargo/latest/cargo/util/interning/struct.InternedString.html
879- indices : HashMap < PackageRef , NodeIndex > ,
855+ indices : HashMap < PackageRef , ( NodeIndex , PathBuf ) > ,
880856}
881857
882858impl PublishPlan {
@@ -894,8 +870,32 @@ impl PublishPlan {
894870 } )
895871 }
896872
897- pub fn iter < ' a > ( & ' a self ) -> impl Iterator < Item = & ' a PackageRef > + ' a {
898- self . indices . iter ( ) . map ( |( pkg, _) | pkg)
873+ pub fn iter < ' a > ( & ' a self ) -> impl Iterator < Item = & ' a PackageSpec > + ' a {
874+ self . dependents . nodes_iter ( ) . map ( |id| & self . dependents [ id] )
875+ }
876+
877+ pub fn iter_edges < ' a > ( & ' a self ) -> impl Iterator < Item = & ' a PackageSpec > + ' a {
878+ use petgraph:: visit:: IntoNeighborsDirected ;
879+ self . dependents . nodes_iter ( ) . map ( |id| {
880+ let dep = & self . dependents [ id] ;
881+ tracing:: warn!( "ITER {dep}" ) ;
882+ let mut neighbors = self
883+ . dependents
884+ . neighbors_directed ( id, Direction :: Outgoing )
885+ . peekable ( ) ;
886+ if neighbors. peek ( ) . is_none ( ) {
887+ tracing:: debug!( "{dep} has no dependents" ) ;
888+ }
889+
890+ if tracing:: enabled!( Level :: DEBUG ) {
891+ while let Some ( id) = neighbors. next ( ) {
892+ let pkg = & self . dependents [ id] ;
893+ tracing:: debug!( "{dep} -(DependencyOF)-> {pkg}" ) ;
894+ }
895+ }
896+
897+ dep
898+ } )
899899 }
900900
901901 pub fn is_empty ( & self ) -> bool {
@@ -909,30 +909,35 @@ impl PublishPlan {
909909 /// Returns the set of packages that are ready for publishing (i.e. have no outstanding dependencies).
910910 ///
911911 /// These will not be returned in future calls.
912- pub fn take_ready ( & mut self ) -> BTreeSet < PackageRef > {
912+ pub fn take_ready ( & mut self ) -> BTreeSet < PackageSpec > {
913913 self . dependents
914914 . nodes_iter ( )
915915 // there are no dependents on `self.dendents[id]`
916916 . filter ( |id| self . dependents . neighbors ( * id) . count ( ) == 0 )
917917 . map ( |id| {
918918 let pkg = & self . dependents [ id] ;
919- self . indices . remove ( & pkg) ;
919+ self . indices . remove ( & pkg. package ) ;
920920 pkg. clone ( )
921921 } )
922922 . collect ( )
923923 }
924924
925+ ///
926+ pub fn get_path ( & self , pkg : & PackageRef ) -> Option < & Path > {
927+ self . indices . get ( pkg) . map ( |( _, p) | p. as_ref ( ) )
928+ }
929+
925930 /// Packages confirmed to be available in the registry, potentially allowing additional
926931 /// packages to be "ready".
927932 pub fn mark_confirmed ( & mut self , published : impl IntoIterator < Item = PackageRef > ) {
928933 for pkg in published {
929- let id = self
934+ let ( id , _ ) = self
930935 . indices
931936 . remove ( & pkg)
932- . expect ( "PackageRef has no associated index" ) ;
937+ . expect ( "PackageSpec has no associated index" ) ;
933938 self . dependents
934939 . remove_node ( id)
935- . expect ( "index has no associated PackageRef " ) ;
940+ . expect ( "index has no associated PackageSpec " ) ;
936941 }
937942 }
938943}
@@ -942,7 +947,7 @@ impl PublishPlan {
942947/// e.g. "foo:a@0.1.0, bar:b@0.2.0, and baz:c@0.3.0".
943948///
944949/// Note: the final separator (e.g. "and" in the previous example) can be chosen.
945- pub fn package_list ( pkgs : impl IntoIterator < Item = PackageRef > , final_sep : & str ) -> String {
950+ pub fn package_list ( pkgs : impl IntoIterator < Item = PackageSpec > , final_sep : & str ) -> String {
946951 let mut names: Vec < _ > = pkgs. into_iter ( ) . map ( |pkg| pkg. to_string ( ) ) . collect ( ) ;
947952 names. sort ( ) ;
948953
0 commit comments