summaryrefslogtreecommitdiff
path: root/engine/SCons/Tool/tex.py
diff options
context:
space:
mode:
authorLuca Falavigna <dktrkranz@debian.org>2012-08-20 23:14:13 +0200
committerLuca Falavigna <dktrkranz@debian.org>2012-08-20 23:14:13 +0200
commitde88ed62712f996f44628e2e83af1026181175d8 (patch)
tree18715dc1b1be71481efa362c12a6c2ccbffd2f84 /engine/SCons/Tool/tex.py
parent9dc7be6c34e2bda6d0d96a450bb8eee03b277ba3 (diff)
Imported Upstream version 2.2.0upstream/2.2.0
Diffstat (limited to 'engine/SCons/Tool/tex.py')
-rw-r--r--engine/SCons/Tool/tex.py90
1 files changed, 76 insertions, 14 deletions
diff --git a/engine/SCons/Tool/tex.py b/engine/SCons/Tool/tex.py
index 79da6be..ce394e4 100644
--- a/engine/SCons/Tool/tex.py
+++ b/engine/SCons/Tool/tex.py
@@ -10,7 +10,7 @@ selection method.
"""
#
-# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 The SCons Foundation
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -32,7 +32,7 @@ selection method.
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Tool/tex.py 5357 2011/09/09 21:31:03 bdeegan"
+__revision__ = "src/engine/SCons/Tool/tex.py issue-2856:2676:d23b7a2f45e8 2012/08/05 15:38:28 garyo"
import os.path
import re
@@ -55,14 +55,18 @@ must_rerun_latex = True
check_suffixes = ['.toc', '.lof', '.lot', '.out', '.nav', '.snm']
# these are files that require bibtex or makeindex to be run when they change
-all_suffixes = check_suffixes + ['.bbl', '.idx', '.nlo', '.glo', '.acn']
+all_suffixes = check_suffixes + ['.bbl', '.idx', '.nlo', '.glo', '.acn', '.bcf']
#
# regular expressions used to search for Latex features
# or outputs that require rerunning latex
#
# search for all .aux files opened by latex (recorded in the .fls file)
-openout_aux_re = re.compile(r"INPUT *(.*\.aux)")
+openout_aux_re = re.compile(r"OUTPUT *(.*\.aux)")
+
+# search for all .bcf files opened by latex (recorded in the .fls file)
+# for use by biber
+openout_bcf_re = re.compile(r"OUTPUT *(.*\.bcf)")
#printindex_re = re.compile(r"^[^%]*\\printindex", re.MULTILINE)
#printnomenclature_re = re.compile(r"^[^%]*\\printnomenclature", re.MULTILINE)
@@ -86,6 +90,8 @@ tableofcontents_re = re.compile(r"^[^%\n]*\\tableofcontents", re.MULTILINE)
makeindex_re = re.compile(r"^[^%\n]*\\makeindex", re.MULTILINE)
bibliography_re = re.compile(r"^[^%\n]*\\bibliography", re.MULTILINE)
bibunit_re = re.compile(r"^[^%\n]*\\begin\{bibunit\}", re.MULTILINE)
+multibib_re = re.compile(r"^[^%\n]*\\newcites\{([^\}]*)\}", re.MULTILINE)
+addbibresource_re = re.compile(r"^[^%\n]*\\(addbibresource|addglobalbib|addsectionbib)", re.MULTILINE)
listoffigures_re = re.compile(r"^[^%\n]*\\listoffigures", re.MULTILINE)
listoftables_re = re.compile(r"^[^%\n]*\\listoftables", re.MULTILINE)
hyperref_re = re.compile(r"^[^%\n]*\\usepackage.*\{hyperref\}", re.MULTILINE)
@@ -236,6 +242,9 @@ def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None
must_rerun_latex = True
+ # .aux files already processed by BibTex
+ already_bibtexed = []
+
#
# routine to update MD5 hash and compare
#
@@ -291,27 +300,61 @@ def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None
dups[x] = 1
auxfiles = list(dups.keys())
+ bcffiles = []
+ if os.path.isfile(flsfilename):
+ flsContent = open(flsfilename, "rb").read()
+ bcffiles = openout_bcf_re.findall(flsContent)
+ # remove duplicates
+ dups = {}
+ for x in bcffiles:
+ dups[x] = 1
+ bcffiles = list(dups.keys())
+
if Verbose:
print "auxfiles ",auxfiles
+ print "bcffiles ",bcffiles
# Now decide if bibtex will need to be run.
# The information that bibtex reads from the .aux file is
# pass-independent. If we find (below) that the .bbl file is unchanged,
# then the last latex saw a correct bibliography.
- # Therefore only do this on the first pass
- if count == 1:
- for auxfilename in auxfiles:
+ # Therefore only do this once
+ # Go through all .aux files and remember the files already done.
+ for auxfilename in auxfiles:
+ if auxfilename not in already_bibtexed:
+ already_bibtexed.append(auxfilename)
target_aux = os.path.join(targetdir, auxfilename)
if os.path.isfile(target_aux):
content = open(target_aux, "rb").read()
if content.find("bibdata") != -1:
if Verbose:
- print "Need to run bibtex"
+ print "Need to run bibtex on ",auxfilename
bibfile = env.fs.File(SCons.Util.splitext(target_aux)[0])
result = BibTeXAction(bibfile, bibfile, env)
if result != 0:
check_file_error_message(env['BIBTEX'], 'blg')
- must_rerun_latex = must_rerun_latex or check_MD5(suffix_nodes['.bbl'],'.bbl')
+ must_rerun_latex = True
+
+ # Now decide if biber will need to be run.
+ # The information that bibtex reads from the .bcf file is
+ # pass-independent. If we find (below) that the .bbl file is unchanged,
+ # then the last latex saw a correct bibliography.
+ # Therefore only do this once
+ # Go through all .bcf files and remember the files already done.
+ for bcffilename in bcffiles:
+ if bcffilename not in already_bibtexed:
+ already_bibtexed.append(bcffilename)
+ target_bcf = os.path.join(targetdir, bcffilename)
+ if os.path.isfile(target_bcf):
+ content = open(target_bcf, "rb").read()
+ if content.find("bibdata") != -1:
+ if Verbose:
+ print "Need to run bibtex on ",bcffilename
+ bibfile = env.fs.File(SCons.Util.splitext(target_bcf)[0])
+ result = BibTeXAction(bibfile, bibfile, env)
+ if result != 0:
+ check_file_error_message(env['BIBTEX'], 'blg')
+ must_rerun_latex = True
# Now decide if latex will need to be run again due to index.
if check_MD5(suffix_nodes['.idx'],'.idx') or (count == 1 and run_makeindex):
@@ -553,6 +596,8 @@ def ScanFiles(theFile, target, paths, file_tests, file_tests_search, env, graphi
for i in range(len(file_tests_search)):
if file_tests[i][0] is None:
file_tests[i][0] = file_tests_search[i].search(content)
+ if Verbose and file_tests[i][0]:
+ print " found match for ",file_tests[i][-1][-1]
incResult = includeOnly_re.search(content)
if incResult:
@@ -621,6 +666,8 @@ def tex_emitter_core(target, source, env, graphics_extensions):
makeindex_re,
bibliography_re,
bibunit_re,
+ multibib_re,
+ addbibresource_re,
tableofcontents_re,
listoffigures_re,
listoftables_re,
@@ -636,6 +683,8 @@ def tex_emitter_core(target, source, env, graphics_extensions):
['.idx', '.ind', '.ilg','makeindex'],
['.bbl', '.blg','bibliography'],
['.bbl', '.blg','bibunit'],
+ ['.bbl', '.blg','multibib'],
+ ['.bbl', '.blg','.bcf','addbibresource'],
['.toc','contents'],
['.lof','figures'],
['.lot','tables'],
@@ -678,6 +727,8 @@ def tex_emitter_core(target, source, env, graphics_extensions):
for (theSearch,suffix_list) in file_tests:
# add side effects if feature is present.If file is to be generated,add all side effects
+ if Verbose and theSearch:
+ print "check side effects for ",suffix_list[-1]
if (theSearch != None) or (not source[0].exists() ):
file_list = [targetbase,]
# for bibunit we need a list of files
@@ -686,20 +737,31 @@ def tex_emitter_core(target, source, env, graphics_extensions):
file_list = glob.glob(file_basename)
# remove the suffix '.aux'
for i in range(len(file_list)):
- file_list[i] = SCons.Util.splitext(file_list[i])[0]
+ file_list.append(SCons.Util.splitext(file_list[i])[0])
+ # for multibib we need a list of files
+ if suffix_list[-1] == 'multibib':
+ for multibibmatch in multibib_re.finditer(content):
+ if Verbose:
+ print "multibib match ",multibibmatch.group(1)
+ if multibibmatch != None:
+ baselist = multibibmatch.group(1).split(',')
+ if Verbose:
+ print "multibib list ", baselist
+ for i in range(len(baselist)):
+ file_list.append(os.path.join(targetdir, baselist[i]))
# now define the side effects
for file_name in file_list:
for suffix in suffix_list[:-1]:
env.SideEffect(file_name + suffix,target[0])
if Verbose:
- print "side effect :",file_name + suffix
+ print "side effect tst :",file_name + suffix, " target is ",str(target[0])
env.Clean(target[0],file_name + suffix)
for aFile in aux_files:
aFile_base = SCons.Util.splitext(aFile)[0]
env.SideEffect(aFile_base + '.aux',target[0])
if Verbose:
- print "side effect :",aFile_base + '.aux'
+ print "side effect aux :",aFile_base + '.aux'
env.Clean(target[0],aFile_base + '.aux')
# read fls file to get all other files that latex creates and will read on the next pass
# remove files from list that we explicitly dealt with above
@@ -712,7 +774,7 @@ def tex_emitter_core(target, source, env, graphics_extensions):
out_files.remove(filename)
env.SideEffect(out_files,target[0])
if Verbose:
- print "side effect :",out_files
+ print "side effect fls :",out_files
env.Clean(target[0],out_files)
return (target, source)
@@ -826,7 +888,7 @@ def generate_common(env):
env['LATEX'] = 'latex'
env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')
env['LATEXCOM'] = CDCOM + '${TARGET.dir} && $LATEX $LATEXFLAGS ${SOURCE.file}'
- env['LATEXRETRIES'] = 3
+ env['LATEXRETRIES'] = 4
env['PDFLATEX'] = 'pdflatex'
env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode -recorder')