aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-10-04 10:15:26 -0700
committerJohn MacFarlane <[email protected]>2022-10-04 10:17:33 -0700
commit11ec70cfeb3c6ce34fe6f7daf6dca4d75426764f (patch)
treeab5d485b7ec5493cb76ce4b0126b4dcc4b370940
parente33d61dff99e500cb63b2a1ed63cc0041ce37a21 (diff)
Better 'make moduledeps' target.
ROOT can now be multiple modules, and the complete transitive dependencies of all of them will be printed. make moduledeps ROOT="Text.Pandoc.Class Text.Pandoc.Parsing"
-rw-r--r--Makefile19
-rw-r--r--tools/depthfirst.gvpr18
-rw-r--r--tools/moduledeps.lua73
3 files changed, 82 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 99b5bdde6..97d7928be 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ COMMIT=$(shell git rev-parse --short HEAD)
TIMESTAMP=$(shell date "+%Y%m%d_%H%M")
LATESTBENCH=$(word 1,$(shell ls -t bench_*.csv 2>/dev/null))
BASELINE?=$(LATESTBENCH)
-ROOTNODE?=T.P
+ROOT?=Text.Pandoc
ifeq ($(BASELINE),)
BASELINECMD=
else
@@ -176,19 +176,18 @@ modules.csv: $(PANDOCSOURCEFILES)
modules.dot: modules.csv
@echo "digraph G {" > $@
@echo "overlap=\"scale\"" >> $@
- @sed -e 's/\([^,]*\),\(.*\)/ "\1" -> "\2";/' $< \
- | sed -e 's/Text\.Pandoc/T.P/g' \
- >> $@
+ @sed -e 's/\([^,]*\),\(.*\)/ "\1" -> "\2";/' $< >> $@
@echo "}" >> $@
-# To get the module dependencies of T.P.Parsing:
-# make modules.pdf ROOTNODE=T.P.Parsing
+# To get the module dependencies of Text.Pandoc.Parsing:
+# make modules.pdf ROOT=Text.Pandoc.Parsing
modules.pdf: modules.dot
- gvpr -f tools/cliptree.gvpr -a '"$(ROOTNODE)"' $< | dot -Tpdf > $@
+ gvpr -f tools/cliptree.gvpr -a '"$(ROOT)"' $< | dot -Tpdf > $@
-# make moduledeps ROOTNODE=T.P.Parsing
-moduledeps: modules.dot ## Print dependencies of a module ROOTNODE
- gvpr -f tools/depthfirst.gvpr -a '"$(ROOTNODE)"' modules.dot
+# make moduledeps ROOT=Text.Pandoc.Parsing
+moduledeps: modules.csv ## Print transitive dependencies of a module ROOT
+ @echo "$(ROOT)"
+ @lua tools/moduledeps.lua transitive $(ROOT) | sort
.PHONY: moduledeps
clean: ## clean up
diff --git a/tools/depthfirst.gvpr b/tools/depthfirst.gvpr
deleted file mode 100644
index 5539be22e..000000000
--- a/tools/depthfirst.gvpr
+++ /dev/null
@@ -1,18 +0,0 @@
-BEGIN {
- int i, indent;
- int seen[string];
- void prInd (int cnt) {
- for (i = 0; i < cnt; i++) printf (" "); }
-}
-BEG_G {
- $tvtype = TV_prepostfwd; $tvroot = node($,ARGV[0]);
-} N{
- if (seen[$.name]) {
- indent--;
- if (indent == 0) exit(0);
- } else {
- prInd(indent); print ($.name);
- seen[$.name] = 1;
- indent++;
- }
-}
diff --git a/tools/moduledeps.lua b/tools/moduledeps.lua
new file mode 100644
index 000000000..f54d00857
--- /dev/null
+++ b/tools/moduledeps.lua
@@ -0,0 +1,73 @@
+-- Construct module dependency tree from modules.csv
+
+local dependencies = {}
+
+local csv = io.open("modules.csv")
+local lines = csv:lines()
+local mode = arg[1]
+local roots = {}
+local i = 2
+while i <= #arg do
+ roots[i - 1] = arg[i]
+ i = i + 1
+end
+
+if not (mode == "tree" or mode == "transitive") then
+ io.write("Usage: lua moduledeps (tree|transitive) modulename\n")
+ io.exit(1)
+end
+
+if #roots == 0 then
+ io.write("Usage: lua moduledeps modulename+\n")
+ io.exit(1)
+end
+
+for line in lines do
+ local _,_,mod,dep = string.find(line, "([^,]+),([^,]+)")
+ if not dependencies[mod] then
+ dependencies[mod] = {}
+ end
+ if not dependencies[dep] then
+ dependencies[dep] = {}
+ end
+ dependencies[mod][dep] = true
+end
+
+local transitive = {}
+
+function prind(ind, s)
+ io.write(string.rep(" ",ind) .. s .. "\n")
+end
+
+function add_transitive_deps(mod)
+ if transitive[mod] then
+ return
+ end
+ transitive[mod] = {}
+ for dep,_ in pairs(dependencies[mod]) do
+ transitive[mod][dep] = true
+ add_transitive_deps(dep)
+ for indirectdep,_ in pairs(transitive[dep]) do
+ transitive[mod][indirectdep] = true
+ end
+ end
+end
+
+function print_direct_deps(mod, ind)
+ ind = ind or 0
+ prind(ind, mod)
+ for dep,_ in pairs(dependencies[mod]) do
+ print_direct_deps(dep, ind + 2)
+ end
+end
+
+for _,root in ipairs(roots) do
+ if mode == "transitive" then
+ add_transitive_deps(root)
+ for dep,_ in pairs(transitive[root]) do
+ prind(2,dep)
+ end
+ elseif mode == "tree" then
+ print_direct_deps(root, 0)
+ end
+end