Changeset 782b4fe in rtems-docs


Ignore:
Timestamp:
01/09/17 23:11:05 (6 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
5, am, master
Children:
9aa52b9
Parents:
1a9b02e
Message:

waf: Improved XML Catalogue generator.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • common/waf.py

    r1a9b02e r782b4fe  
    8787    output_dir = output_node.abspath()
    8888    doctrees = os.path.join(os.path.dirname(output_dir), 'doctrees', buildtype)
    89     #
    90     # Gather the data for the catalogue
    91     #
    92     if build_dir not in ctx.catalogue:
    93         ctx.catalogue[build_dir] = {
    94             'builddir': build_dir,
    95             'buildtype': []
    96         }
    97     ctx.catalogue[build_dir]['buildtype'].append(buildtype)
    9889    return build_dir, output_node, output_dir, doctrees
    9990
     
    323314    cmd_configure(ctx)
    324315
    325 def xml_catalogue(ctx):
     316def xml_catalogue(ctx, building):
     317    #
     318    # The following is a hack to find the top_dir because the task does
     319    # provided a reference to top_dir like a build context.
     320    #
     321    top_dir = ctx.get_cwd().find_node('..')
    326322    #
    327323    # Read the conf.py files in each directory to gather the doc details.
    328324    #
     325    catalogue = {}
    329326    sp = sys.path[:]
    330     for t in ctx.cur_tasks:
    331         if t.get_cwd().is_src():
    332             doc = os.path.basename(t.get_cwd().get_src().abspath())
    333             sys.path.insert(0, str(t.get_cwd()))
    334             #
    335             # Import using the imp API so the module is reloaded for us.
    336             #
    337             import imp
    338             mf = imp.find_module('conf')
    339             try:
    340                 bconf = imp.load_module('bconf', mf[0], mf[1], mf[2])
    341             finally:
    342                 mf[0].close()
    343             sys.path = sp[:]
    344             if doc in ctx.catalogue:
    345                 ctx.catalogue[doc]['title'] = bconf.project
    346                 ctx.catalogue[doc]['version'] = bconf.version
    347                 ctx.catalogue[doc]['release'] = bconf.release
    348                 ctx.catalogue[doc]['latex'] = bconf.latex_documents[0][1]
    349             bconf = None
     327    for doc in building:
     328        sys.path.insert(0, top_dir.find_node(doc).abspath())
     329        #
     330        # Import using the imp API so the module is reloaded for us.
     331        #
     332        import imp
     333        mf = imp.find_module('conf')
     334        try:
     335            bconf = imp.load_module('bconf', mf[0], mf[1], mf[2])
     336        finally:
     337            mf[0].close()
     338        sys.path = sp[:]
     339        catalogue[doc] = {
     340            'title': bconf.project,
     341            'version':  bconf.version,
     342            'release': bconf.release,
     343            'pdf': bconf.latex_documents[0][1].replace('.tex', '.pdf'),
     344            'html': '%s/index.html' % (doc),
     345            'singlehtml': '%s.html' % (doc)
     346        }
     347        bconf = None
    350348
    351349    import xml.dom.minidom as xml
     
    356354    cat.appendChild(root)
    357355
    358     for d in ctx.catalogue:
     356    builds = ['html']
     357    if ctx.env.BUILD_PDF == 'yes':
     358        builds += ['pdf']
     359    if ctx.env.BUILD_SINGLEHTML == 'yes':
     360        builds += ['singlehtml']
     361
     362    for d in building:
    359363        doc = cat.createElement('doc')
    360364        name = cat.createElement('name')
     
    362366        name.appendChild(text)
    363367        title = cat.createElement('title')
    364         text = cat.createTextNode(ctx.catalogue[d]['title'])
     368        text = cat.createTextNode(catalogue[d]['title'])
    365369        title.appendChild(text)
    366370        release = cat.createElement('release')
    367         text = cat.createTextNode(ctx.catalogue[d]['release'])
     371        text = cat.createTextNode(catalogue[d]['release'])
    368372        release.appendChild(text)
    369373        version = cat.createElement('version')
    370         text = cat.createTextNode(ctx.catalogue[d]['version'])
     374        text = cat.createTextNode(catalogue[d]['version'])
    371375        version.appendChild(text)
    372376        doc.appendChild(name)
     
    374378        doc.appendChild(release)
    375379        doc.appendChild(version)
    376         for b in ctx.catalogue[d]['buildtype']:
    377             if b == 'latex':
    378                 b = 'pdf'
    379                 ref = ctx.catalogue[d]['latex'].replace('.tex', '.pdf')
    380             elif b == 'html':
    381                 ref = '%s/index.html' % (d)
    382             else:
    383                 ref = 'undefined'
     380        for b in builds:
    384381            output = cat.createElement(b)
    385             text = cat.createTextNode(ref)
     382            text = cat.createTextNode(catalogue[d][b])
    386383            output.appendChild(text)
    387384            doc.appendChild(output)
    388385        root.appendChild(doc)
    389386
    390     catnode = ctx.path.get_bld().make_node('catalogue.xml')
     387    catnode = ctx.get_cwd().make_node('catalogue.xml')
    391388    catnode.write(cat.toprettyxml(indent = ' ' * 2, newl = os.linesep))
    392389
  • wscript

    r1a9b02e r782b4fe  
    77path.append(abspath('common'))
    88
     9import waflib
    910import waf as docs_waf
    1011
     
    3132    conf.env['BUILD_FROM_TOP'] = 'yes'
    3233
    33 def xml_catalogue(ctx):
    34     docs_waf.xml_catalogue(ctx)
     34def catalogue(ctx):
     35    docs_waf.xml_catalogue(ctx, building)
    3536
    3637def build(ctx):
    37     ctx.catalogue = {}
    38     ctx.add_post_fun(xml_catalogue)
    3938    for b in building:
    4039        ctx.recurse(b)
    41     ctx.install_files('${PREFIX}', 'catalogue.xml')
     40    ctx(rule = catalogue,
     41        target = 'catalogue.xml',
     42        source = ['wscript', 'common/waf.py'])
    4243
    4344def install(ctx):
Note: See TracChangeset for help on using the changeset viewer.