diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-12 02:05:36 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-12 02:05:36 -0400 |
commit | fc1ec14951cf3ebfc5a37df1f1b06fa3adac29bc (patch) | |
tree | f83556404a16a8c23a463cbfd20eb9903ddc4d09 /tools | |
parent | b3818c47a4561989cea9b4cbe61d61c27cab459f (diff) |
dependency tracking for manpages
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/make-directive-index.py | 2 | ||||
-rwxr-xr-x | tools/make-man-index.py | 2 | ||||
-rwxr-xr-x | tools/make-man-rules.py | 54 | ||||
-rw-r--r-- | tools/xml_helper.py | 25 |
4 files changed, 52 insertions, 31 deletions
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') |