summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-05-12 02:05:36 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-05-12 02:05:36 -0400
commitfc1ec14951cf3ebfc5a37df1f1b06fa3adac29bc (patch)
treef83556404a16a8c23a463cbfd20eb9903ddc4d09
parentb3818c47a4561989cea9b4cbe61d61c27cab459f (diff)
dependency tracking for manpages
-rw-r--r--build-aux/Makefile.each.tail/70-sdman.mk18
-rw-r--r--build-aux/Makefile.once.head/20-sdman.mk38
-rwxr-xr-xtools/make-directive-index.py2
-rwxr-xr-xtools/make-man-index.py2
-rwxr-xr-xtools/make-man-rules.py54
-rw-r--r--tools/xml_helper.py25
6 files changed, 64 insertions, 75 deletions
diff --git a/build-aux/Makefile.each.tail/70-sdman.mk b/build-aux/Makefile.each.tail/70-sdman.mk
index fa490a8677..d86f61e2e4 100644
--- a/build-aux/Makefile.each.tail/70-sdman.mk
+++ b/build-aux/Makefile.each.tail/70-sdman.mk
@@ -52,22 +52,4 @@ endif # ENABLE_MANPAGES
at.subdirs += $(abspath $(topoutdir)/man)
-$(outdir)/%.1: $(srcdir)/%.xml $(topsrcdir)/man/custom-man.xsl $(topoutdir)/man/custom-entities.ent
- $(_sdman.XSLTPROC_PROCESS_MAN)
-
-$(outdir)/%.3: $(srcdir)/%.xml $(topsrcdir)/man/custom-man.xsl $(topoutdir)/man/custom-entities.ent
- $(_sdman.XSLTPROC_PROCESS_MAN)
-
-$(outdir)/%.5: $(srcdir)/%.xml $(topsrcdir)/man/custom-man.xsl $(topoutdir)/man/custom-entities.ent
- $(_sdman.XSLTPROC_PROCESS_MAN)
-
-$(outdir)/%.7: $(srcdir)/%.xml $(topsrcdir)/man/custom-man.xsl $(topoutdir)/man/custom-entities.ent
- $(_sdman.XSLTPROC_PROCESS_MAN)
-
-$(outdir)/%.8: $(srcdir)/%.xml $(topsrcdir)/man/custom-man.xsl $(topoutdir)/man/custom-entities.ent
- $(_sdman.XSLTPROC_PROCESS_MAN)
-
-$(outdir)/%.html: $(srcdir)/%.xml $(topsrcdir)/man/custom-html.xsl $(topoutdir)/man/custom-entities.ent
- $(_sdman.XSLTPROC_PROCESS_HTML)
-
endif # _sdman.man_xml
diff --git a/build-aux/Makefile.once.head/20-sdman.mk b/build-aux/Makefile.once.head/20-sdman.mk
index bef7717511..c959f12545 100644
--- a/build-aux/Makefile.once.head/20-sdman.mk
+++ b/build-aux/Makefile.once.head/20-sdman.mk
@@ -40,18 +40,16 @@ define mod.sdman.doc
# - Directory variable : `files.src.gen`
# - Directory variable : `man_MANS`
# - Directory variable : `noinst_DATA` (HTML)
-# - Target : `$(outdir)/%.1`
-# - Target : `$(outdir)/%.3`
-# - Target : `$(outdir)/%.5`
-# - Target : `$(outdir)/%.7`
-# - Target : `$(outdir)/%.8`
-# - Target : `$(outdir)/%.html`
#
# sdman -> Makefile-man.mk:
+# - Global variable : `sdman.man-xslt`
+# - Global variable : `sdman.man-alias`
+# - Global variable : `sdman.html-xslt`
# - Global variable : `sdman.html-alias`
# Makefile-man.mk -> sdman:
# - Directory variable : `sdman.MANPAGES`
# - Directory variable : `sdman.MANPAGES_ALIAS`
+# - Targets : ...
#
# The `sdman.*` variables are the interface by which the module
# communicates with the genrated Makefile-man.mk file. They should not
@@ -67,10 +65,10 @@ AM_V_LN_ ?= $(AM_V_LN_$(AM_DEFAULT_VERBOSITY))
AM_V_LN_0 ?= @echo " LN " $@;
AM_V_LN_1 ?=
-AM_V_SOELIM ?= $(AM_V_SOELIM_$(V))
-AM_V_SOELIM_ ?= $(AM_V_SOELIM_$(AM_DEFAULT_VERBOSITY))
-AM_V_SOELIM_0 ?= @echo " SOELIM " $@;
-AM_V_SOELIM_1 ?=
+AM_V_SOALIAS ?= $(AM_V_SOALIAS_$(V))
+AM_V_SOALIAS_ ?= $(AM_V_SOALIAS_$(AM_DEFAULT_VERBOSITY))
+AM_V_SOALIAS_0 ?= @echo " SOALIAS " $@;
+AM_V_SOALIAS_1 ?=
AM_V_XSLT ?= $(AM_V_XSLT_$(V))
AM_V_XSLT_ ?= $(AM_V_XSLT_$(AM_DEFAULT_VERBOSITY))
@@ -88,20 +86,8 @@ _sdman.XSLTPROC_FLAGS = \
--path '$(outdir):$(srcdir):$(topoutdir)/man:$(topsrcdir)/man'
_sdman.XSLT = $(if $(XSLTPROC), $(XSLTPROC), xsltproc)
-_sdman.XSLTPROC_PROCESS_MAN = \
- $(AM_V_XSLT)$(_sdman.XSLT) -o $@ $(_sdman.XSLTPROC_FLAGS) $(srcdir)/man/custom-man.xsl $<
-_sdman.XSLTPROC_PROCESS_HTML = \
- $(AM_V_XSLT)$(_sdman.XSLT) -o $@ $(_sdman.XSLTPROC_FLAGS) $(srcdir)/man/custom-html.xsl $<
-
-# Because the docbooc-xsl authors are assholes, they ignore everything but the
-# directory of '-o' and instead choose filenames in it based on <refname>
-# elements, with no option to override that from the command line. This is a
-# nice feature, until we have to rectify it with Make's poor support for
-# commands with multiple outputs. So, we'll let it do its thing, but have a
-# rule for manually re-creating an alias without re-running xsltproc in case it
-# gets removed.
-sdman.man-alias = \
- $(AM_V_LN)$(PRINTF) '.so %s\n' $(<F) > $@
-sdman.html-alias = \
- $(AM_V_LN)$(LN_S) -f $(<F) $@
+sdman.man-xslt = $(AM_V_XSLT)$(_sdman.XSLT) -o $@ $(_sdman.XSLTPROC_FLAGS) $(srcdir)/man/custom-man.xsl $<
+sdman.man-alias = $(AM_V_SOALIAS)$(PRINTF) '.so %s\n' $(<F) > $@
+sdman.html-xslt = $(AM_V_XSLT)$(_sdman.XSLT) -o $@ $(_sdman.XSLTPROC_FLAGS) $(srcdir)/man/custom-html.xsl $<
+sdman.html-alias = $(AM_V_LN)$(LN_S) -f $(<F) $@
diff --git a/tools/make-directive-index.py b/tools/make-directive-index.py
index 1b287997fa..bbb328a8b7 100755
--- a/tools/make-directive-index.py
+++ b/tools/make-directive-index.py
@@ -180,7 +180,7 @@ referring to {pages} individual manual pages.
'''
def _extract_directives(directive_groups, formatting, page):
- t = xml_parse(page)
+ t, _ = xml_parse(page)
section = t.find('./refmeta/manvolnum').text
pagename = t.find('./refmeta/refentrytitle').text
diff --git a/tools/make-man-index.py b/tools/make-man-index.py
index abc33e7394..7d11083b0b 100755
--- a/tools/make-man-index.py
+++ b/tools/make-man-index.py
@@ -78,7 +78,7 @@ def check_id(page, t):
def make_index(pages):
index = collections.defaultdict(list)
for p in pages:
- t = xml_parse(p)
+ t, _ = xml_parse(p)
check_id(p, t)
section = t.find('./refmeta/manvolnum').text
refname = t.find('./refnamediv/refname').text
diff --git a/tools/make-man-rules.py b/tools/make-man-rules.py
index 1913d44c65..582e0f1132 100755
--- a/tools/make-man-rules.py
+++ b/tools/make-man-rules.py
@@ -30,7 +30,6 @@ sdman.MANPAGES += \\
sdman.MANPAGES_ALIAS += \\
{aliases}
{rules}
-{htmlrules}
'''
CONDITIONAL = '''\
@@ -53,22 +52,23 @@ HEADER = '''\
# to <refentry> element.
'''
-MAN_ALIAS_RULE = '''\
-$(outdir)/{}: $(outdir)/{}
- $(sdman.man-alias)
+RULE_XSLT = '''
+$(outdir)/{refname}.{section}: $(srcdir)/{refname}.xml $(topsrcdir)/man/custom-man.xsl {deps}
+ $(sdman.man-xslt)
+$(outdir)/{refname}.html: $(srcdir)/{refname}.xml $(topsrcdir)/man/custom-html.xsl {deps}
+ $(sdman.html-xslt)
'''
-HTML_ALIAS_RULE = '''\
-$(outdir)/{}.html: $(outdir)/{}.html
+RULE_ALIAS = '''\
+$(outdir)/{refname}.{section}: $(outdir)/{srcrefname}.{srcsection}
+ $(sdman.man-alias)
+$(outdir)/{refname}.html: $(outdir)/{srcrefname}.html
$(sdman.html-alias)
'''
FOOTER = '''\
# Really, do not edit this file.
-
-EXTRA_DIST += \\
- {dist_files}
'''
def man(page, number):
@@ -78,7 +78,7 @@ def xml(file):
return '{}'.format(os.path.basename(file))
def add_rules(rules, name):
- xml = xml_parse(name)
+ xml, deps = xml_parse(name)
# print('parsing {}'.format(name), file=sys.stderr)
if xml.getroot().tag != 'refentry':
return
@@ -95,11 +95,17 @@ def add_rules(rules, name):
assert all(refname not in group
for group in rules.values()), "duplicate page name"
alias = man(refname.text, number)
- rulegroup[alias] = target
+ if alias == target:
+ rulegroup[alias] = deps
+ else:
+ rulegroup[alias] = target
# print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr)
def create_rules(xml_files):
- " {conditional => {alias-name => source-name}} "
+ """
+ {conditional => {alias-name => source-name,
+ page-name => [sources...]}}
+ """
rules = collections.defaultdict(dict)
for name in xml_files:
try:
@@ -112,17 +118,25 @@ def create_rules(xml_files):
def mjoin(files):
return ' \\\n\t'.join(sorted(files) or '#')
+def make_makefile_rule(k, v):
+ if isinstance(v, str):
+ return RULE_ALIAS.format(
+ refname=k[:-2],
+ section=k[-1:],
+ srcrefname=v[:-2],
+ srcsection=v[-1:])
+ else:
+ return RULE_XSLT.format(
+ refname=k[:-2],
+ section=k[-1:],
+ deps=' '.join(v))
+
def make_makefile(rules, dist_files):
return HEADER + '\n'.join(
(CONDITIONAL if conditional else SECTION).format(
- manpages=mjoin(set(rulegroup.values())),
- aliases=mjoin(k for k,v in rulegroup.items() if k != v),
- rules='\n'.join(MAN_ALIAS_RULE.format(k,v)
- for k,v in sorted(rulegroup.items())
- if k != v),
- htmlrules='\n'.join(HTML_ALIAS_RULE.format(k[:-2],v[:-2])
- for k,v in sorted(rulegroup.items())
- if k != v),
+ manpages=mjoin(k for k,v in rulegroup.items() if not isinstance(v, str)),
+ aliases=mjoin(k for k,v in rulegroup.items() if isinstance(v, str)),
+ rules='\n'.join(make_makefile_rule(k, v) for k,v in sorted(rulegroup.items())),
conditional=conditional)
for conditional,rulegroup in sorted(rules.items())
) + FOOTER.format(dist_files=mjoin(sorted(dist_files)))
diff --git a/tools/xml_helper.py b/tools/xml_helper.py
index eb07121d59..b9267b4a2e 100644
--- a/tools/xml_helper.py
+++ b/tools/xml_helper.py
@@ -20,23 +20,30 @@
from lxml import etree as tree
import os.path
+shared = { 'custom-entities.ent',
+ 'less-variables.xml',
+ 'standard-conf.xml',
+ 'standard-options.xml',
+ 'user-system-options.xml' }
+
class CustomResolver(tree.Resolver):
def resolve(self, url, id, context):
- if ':' in url:
+ basename = os.path.basename(url)
+ if not basename in shared:
return None
- if not os.path.exists(url):
- srcdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- basename = os.path.basename(url)
- if basename == 'custom-entities.ent':
- basename = 'custom-entities.ent.in'
- url = os.path.join(srcdir, 'man', basename)
- return self.resolve_filename(url, context)
+ if basename == 'custom-entities.ent':
+ basename += '.in'
+ topsrcdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ _deps.add(os.path.join('$(topsrcdir)', 'man', basename))
+ return self.resolve_filename(os.path.join(topsrcdir, 'man', basename), context)
_parser = tree.XMLParser()
_parser.resolvers.add(CustomResolver())
+_deps = set()
def xml_parse(page):
+ _deps.clear()
doc = tree.parse(page, _parser)
doc.xinclude()
- return doc
+ return doc, _deps
def xml_print(xml):
return tree.tostring(xml, pretty_print=True, encoding='utf-8')