Issue 1342 Tools.tex, run 'makeglossaries' if 'glossaries' is used

Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
This commit is contained in:
Joe Steeve 2013-08-21 01:05:42 +05:30 committed by Thomas Nagy
parent a67c8c9017
commit 4cbee2c4ed
1 changed files with 29 additions and 1 deletions

View File

@ -74,6 +74,9 @@ re_tex = re.compile(r'\\(?P<type>usepackage|RequirePackage|include|bibliography(
g_bibtex_re = re.compile('bibdata', re.M)
"""Regexp for bibtex files"""
g_glossaries_re = re.compile('\\@newglossary', re.M)
"""Regexp for expressions that create glossaries"""
class tex(Task.Task):
"""
Compile a tex/latex file.
@ -91,6 +94,11 @@ class tex(Task.Task):
Execute the program **makeindex**
"""
makeglossaries_fun, _ = Task.compile_fun('${MAKEGLOSSARIES} ${SRCFILE}', shell=False)
makeglossaries_fun.__doc__ = """
Execute the program **makeglossaries**
"""
def exec_command(self, cmd, **kw):
"""
Override :py:meth:`waflib.Task.Task.exec_command` to execute the command without buffering (latex may prompt for inputs)
@ -287,6 +295,25 @@ class tex(Task.Task):
if os.path.exists(os.path.join(p.abspath(), 'btaux.aux')):
self.aux_nodes += p.ant_glob('*[0-9].aux')
def makeglossaries(self):
src_file = self.inputs[0].abspath()
base_file = os.path.basename(src_file)
base, _ = os.path.splitext(base_file)
for aux_node in self.aux_nodes:
try:
ct = aux_node.read()
except (OSError, IOError):
Logs.error('Error reading %s: %r' % aux_node.abspath())
continue
if g_glossaries_re.findall(ct):
if not self.env['MAKEGLOSSARIES']:
raise Errors.WafError ("No 'makeglossaries'")
Logs.warn('calling makeglossaries')
self.env.SRCFILE = base
self.check_status('error when calling makeglossaries %s' % base, self.makeglossaries_fun())
return
def run(self):
"""
Runs the TeX build process.
@ -330,6 +357,7 @@ class tex(Task.Task):
self.bibfile()
self.bibunits()
self.makeindex()
self.makeglossaries()
hash = ''
for i in range(10):
@ -449,7 +477,7 @@ def configure(self):
are not found.
"""
v = self.env
for p in 'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps'.split():
for p in 'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps makeglossaries'.split():
try:
self.find_program(p, var=p.upper())
except self.errors.ConfigurationError: