mirror of
https://git.rtems.org/rtems-docs/
synced 2025-06-06 02:40:19 +08:00
waf: Improved XML Catalogue generator.
This commit is contained in:
parent
1a9b02e20d
commit
782b4fec71
@ -86,15 +86,6 @@ def build_dir_setup(ctx, buildtype):
|
|||||||
output_node = ctx.path.get_bld().make_node(buildtype)
|
output_node = ctx.path.get_bld().make_node(buildtype)
|
||||||
output_dir = output_node.abspath()
|
output_dir = output_node.abspath()
|
||||||
doctrees = os.path.join(os.path.dirname(output_dir), 'doctrees', buildtype)
|
doctrees = os.path.join(os.path.dirname(output_dir), 'doctrees', buildtype)
|
||||||
#
|
|
||||||
# Gather the data for the catalogue
|
|
||||||
#
|
|
||||||
if build_dir not in ctx.catalogue:
|
|
||||||
ctx.catalogue[build_dir] = {
|
|
||||||
'builddir': build_dir,
|
|
||||||
'buildtype': []
|
|
||||||
}
|
|
||||||
ctx.catalogue[build_dir]['buildtype'].append(buildtype)
|
|
||||||
return build_dir, output_node, output_dir, doctrees
|
return build_dir, output_node, output_dir, doctrees
|
||||||
|
|
||||||
def pdf_resources(ctx, buildtype):
|
def pdf_resources(ctx, buildtype):
|
||||||
@ -322,31 +313,38 @@ def cmd_configure_path(ctx):
|
|||||||
|
|
||||||
cmd_configure(ctx)
|
cmd_configure(ctx)
|
||||||
|
|
||||||
def xml_catalogue(ctx):
|
def xml_catalogue(ctx, building):
|
||||||
|
#
|
||||||
|
# The following is a hack to find the top_dir because the task does
|
||||||
|
# provided a reference to top_dir like a build context.
|
||||||
|
#
|
||||||
|
top_dir = ctx.get_cwd().find_node('..')
|
||||||
#
|
#
|
||||||
# Read the conf.py files in each directory to gather the doc details.
|
# Read the conf.py files in each directory to gather the doc details.
|
||||||
#
|
#
|
||||||
|
catalogue = {}
|
||||||
sp = sys.path[:]
|
sp = sys.path[:]
|
||||||
for t in ctx.cur_tasks:
|
for doc in building:
|
||||||
if t.get_cwd().is_src():
|
sys.path.insert(0, top_dir.find_node(doc).abspath())
|
||||||
doc = os.path.basename(t.get_cwd().get_src().abspath())
|
#
|
||||||
sys.path.insert(0, str(t.get_cwd()))
|
# Import using the imp API so the module is reloaded for us.
|
||||||
#
|
#
|
||||||
# Import using the imp API so the module is reloaded for us.
|
import imp
|
||||||
#
|
mf = imp.find_module('conf')
|
||||||
import imp
|
try:
|
||||||
mf = imp.find_module('conf')
|
bconf = imp.load_module('bconf', mf[0], mf[1], mf[2])
|
||||||
try:
|
finally:
|
||||||
bconf = imp.load_module('bconf', mf[0], mf[1], mf[2])
|
mf[0].close()
|
||||||
finally:
|
sys.path = sp[:]
|
||||||
mf[0].close()
|
catalogue[doc] = {
|
||||||
sys.path = sp[:]
|
'title': bconf.project,
|
||||||
if doc in ctx.catalogue:
|
'version': bconf.version,
|
||||||
ctx.catalogue[doc]['title'] = bconf.project
|
'release': bconf.release,
|
||||||
ctx.catalogue[doc]['version'] = bconf.version
|
'pdf': bconf.latex_documents[0][1].replace('.tex', '.pdf'),
|
||||||
ctx.catalogue[doc]['release'] = bconf.release
|
'html': '%s/index.html' % (doc),
|
||||||
ctx.catalogue[doc]['latex'] = bconf.latex_documents[0][1]
|
'singlehtml': '%s.html' % (doc)
|
||||||
bconf = None
|
}
|
||||||
|
bconf = None
|
||||||
|
|
||||||
import xml.dom.minidom as xml
|
import xml.dom.minidom as xml
|
||||||
cat = xml.Document()
|
cat = xml.Document()
|
||||||
@ -355,39 +353,38 @@ def xml_catalogue(ctx):
|
|||||||
root.setAttribute('date', 'today')
|
root.setAttribute('date', 'today')
|
||||||
cat.appendChild(root)
|
cat.appendChild(root)
|
||||||
|
|
||||||
for d in ctx.catalogue:
|
builds = ['html']
|
||||||
|
if ctx.env.BUILD_PDF == 'yes':
|
||||||
|
builds += ['pdf']
|
||||||
|
if ctx.env.BUILD_SINGLEHTML == 'yes':
|
||||||
|
builds += ['singlehtml']
|
||||||
|
|
||||||
|
for d in building:
|
||||||
doc = cat.createElement('doc')
|
doc = cat.createElement('doc')
|
||||||
name = cat.createElement('name')
|
name = cat.createElement('name')
|
||||||
text = cat.createTextNode(d)
|
text = cat.createTextNode(d)
|
||||||
name.appendChild(text)
|
name.appendChild(text)
|
||||||
title = cat.createElement('title')
|
title = cat.createElement('title')
|
||||||
text = cat.createTextNode(ctx.catalogue[d]['title'])
|
text = cat.createTextNode(catalogue[d]['title'])
|
||||||
title.appendChild(text)
|
title.appendChild(text)
|
||||||
release = cat.createElement('release')
|
release = cat.createElement('release')
|
||||||
text = cat.createTextNode(ctx.catalogue[d]['release'])
|
text = cat.createTextNode(catalogue[d]['release'])
|
||||||
release.appendChild(text)
|
release.appendChild(text)
|
||||||
version = cat.createElement('version')
|
version = cat.createElement('version')
|
||||||
text = cat.createTextNode(ctx.catalogue[d]['version'])
|
text = cat.createTextNode(catalogue[d]['version'])
|
||||||
version.appendChild(text)
|
version.appendChild(text)
|
||||||
doc.appendChild(name)
|
doc.appendChild(name)
|
||||||
doc.appendChild(title)
|
doc.appendChild(title)
|
||||||
doc.appendChild(release)
|
doc.appendChild(release)
|
||||||
doc.appendChild(version)
|
doc.appendChild(version)
|
||||||
for b in ctx.catalogue[d]['buildtype']:
|
for b in builds:
|
||||||
if b == 'latex':
|
|
||||||
b = 'pdf'
|
|
||||||
ref = ctx.catalogue[d]['latex'].replace('.tex', '.pdf')
|
|
||||||
elif b == 'html':
|
|
||||||
ref = '%s/index.html' % (d)
|
|
||||||
else:
|
|
||||||
ref = 'undefined'
|
|
||||||
output = cat.createElement(b)
|
output = cat.createElement(b)
|
||||||
text = cat.createTextNode(ref)
|
text = cat.createTextNode(catalogue[d][b])
|
||||||
output.appendChild(text)
|
output.appendChild(text)
|
||||||
doc.appendChild(output)
|
doc.appendChild(output)
|
||||||
root.appendChild(doc)
|
root.appendChild(doc)
|
||||||
|
|
||||||
catnode = ctx.path.get_bld().make_node('catalogue.xml')
|
catnode = ctx.get_cwd().make_node('catalogue.xml')
|
||||||
catnode.write(cat.toprettyxml(indent = ' ' * 2, newl = os.linesep))
|
catnode.write(cat.toprettyxml(indent = ' ' * 2, newl = os.linesep))
|
||||||
|
|
||||||
cat.unlink()
|
cat.unlink()
|
||||||
|
11
wscript
11
wscript
@ -6,6 +6,7 @@ from sys import path
|
|||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
path.append(abspath('common'))
|
path.append(abspath('common'))
|
||||||
|
|
||||||
|
import waflib
|
||||||
import waf as docs_waf
|
import waf as docs_waf
|
||||||
|
|
||||||
build_all = ['bsp-howto',
|
build_all = ['bsp-howto',
|
||||||
@ -30,15 +31,15 @@ def configure(conf):
|
|||||||
conf.recurse(b)
|
conf.recurse(b)
|
||||||
conf.env['BUILD_FROM_TOP'] = 'yes'
|
conf.env['BUILD_FROM_TOP'] = 'yes'
|
||||||
|
|
||||||
def xml_catalogue(ctx):
|
def catalogue(ctx):
|
||||||
docs_waf.xml_catalogue(ctx)
|
docs_waf.xml_catalogue(ctx, building)
|
||||||
|
|
||||||
def build(ctx):
|
def build(ctx):
|
||||||
ctx.catalogue = {}
|
|
||||||
ctx.add_post_fun(xml_catalogue)
|
|
||||||
for b in building:
|
for b in building:
|
||||||
ctx.recurse(b)
|
ctx.recurse(b)
|
||||||
ctx.install_files('${PREFIX}', 'catalogue.xml')
|
ctx(rule = catalogue,
|
||||||
|
target = 'catalogue.xml',
|
||||||
|
source = ['wscript', 'common/waf.py'])
|
||||||
|
|
||||||
def install(ctx):
|
def install(ctx):
|
||||||
for b in building:
|
for b in building:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user