]> gitweb.factorcode.org Git - factor.git/commitdiff
codebase-analyzer: fix handling of rust toml with workspaces
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 7 Jan 2024 04:02:41 +0000 (22:02 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 10 Jan 2024 19:54:21 +0000 (13:54 -0600)
extra/codebase-analyzer/codebase-analyzer.factor

index 241ce32685068ceb3437626dfd627b33b8759b64..9aec0be5ba5e6865d36e4645db23e1009aa2c274 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2022 Doug Coleman.
 ! See https://factorcode.org/license.txt for BSD license.
 USING: accessors assocs assocs.extras combinators
-combinators.short-circuit formatting io io.backend
+combinators.short-circuit formatting hashtables io io.backend
 io.directories io.encodings.binary io.files io.files.info
-io.files.types io.pathnames kernel math math.statistics prettyprint
-sequences sets sorting splitting toml tools.memory.private
-tools.wc unicode ;
+io.files.types io.pathnames kernel math math.statistics
+prettyprint sequences sets sorting splitting toml
+tools.memory.private tools.wc unicode ;
 IN: codebase-analyzer
 
 : file-sizes ( paths -- assoc )
@@ -209,15 +209,24 @@ IN: codebase-analyzer
         [ ".so" tail? ]
     } 1|| ;
 
-: analyze-rust-cargo-toml ( assoc -- )
+: print-rust-package ( assoc -- )
     {
-        [ "workspace" of "members" of length [ "  %d member projects" sprintf print ] unless-zero ]
-        [ "package" of "name" of [ "  name: %s" sprintf print ] when* ]
-        [ "package" of "version" of [ "  version: %s" sprintf print ] when* ]
-        [ "package" of "license" of [ "  license: %s" sprintf print ] when* ]
-        [ "package" of "edition" of [ "  rust edition: %s" sprintf print ] when* ]
+        [ "name" of [ "  name: %s" sprintf print ] when* ]
+        [ "version" of [ "  version: %s" sprintf print ] when* ]
+        [ "license" of [ "  license: %s" sprintf print ] when* ]
+        [ "edition" of [ "  rust edition: %s" sprintf print ] when* ]
     } cleave ;
 
+: analyze-rust-cargo-toml ( assoc -- )
+    [ print-rust-package ] keep
+    [ "workspace" of "members" of length [ "  %d member projects" sprintf print ] unless-zero ]
+    [
+        [ [ "package" of ] [ "workspace" of "package" of ] bi assoc-union ] keep
+        "workspace" of "members" of [
+            "package: " write print print-rust-package
+        ] with each
+    ] bi ;
+
 : analyze-rust-project ( path -- )
     [ "Analyzing rust project at %s" sprintf print ]
     [ path>toml analyze-rust-cargo-toml ]