mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-23 08:46:56 +00:00
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"
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user