summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/engine/SCons/Tool/tex.py62
-rw-r--r--test/TEX/variant_dir_bibunit.py279
2 files changed, 319 insertions, 22 deletions
diff --git a/src/engine/SCons/Tool/tex.py b/src/engine/SCons/Tool/tex.py
index a4da98e..57e6c32 100644
--- a/src/engine/SCons/Tool/tex.py
+++ b/src/engine/SCons/Tool/tex.py
@@ -39,6 +39,7 @@ import re
import shutil
import sys
import platform
+import glob
import SCons.Action
import SCons.Node
@@ -84,6 +85,7 @@ auxfile_re = re.compile(r".", re.MULTILINE)
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)
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)
@@ -283,6 +285,12 @@ def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None
if os.path.exists(flsfilename):
flsContent = open(flsfilename, "rb").read()
auxfiles = openout_aux_re.findall(flsContent)
+ # remove duplicates
+ dups = {}
+ for x in auxfiles:
+ dups[x] = 1
+ auxfiles = list(dups.keys())
+
if Verbose:
print "auxfiles ",auxfiles
@@ -299,13 +307,11 @@ def InternalLaTeXAuxAction(XXXLaTeXAction, target = None, source= None, env=None
if content.find("bibdata") != -1:
if Verbose:
print "Need to run bibtex"
- bibfile = env.fs.File(targetbase)
+ 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')
- return result
- must_rerun_latex = check_MD5(suffix_nodes['.bbl'],'.bbl')
- break
+ must_rerun_latex = must_rerun_latex or check_MD5(suffix_nodes['.bbl'],'.bbl')
# 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):
@@ -583,7 +589,7 @@ def tex_emitter_core(target, source, env, graphics_extensions):
basedir = os.path.split(str(source[0]))[0]
abspath = os.path.abspath(basedir)
target[0].attributes.path = abspath
-
+
#
# file names we will make use of in searching the sources and log file
#
@@ -613,6 +619,7 @@ def tex_emitter_core(target, source, env, graphics_extensions):
file_tests_search = [auxfile_re,
makeindex_re,
bibliography_re,
+ bibunit_re,
tableofcontents_re,
listoffigures_re,
listoftables_re,
@@ -624,18 +631,19 @@ def tex_emitter_core(target, source, env, graphics_extensions):
beamer_re ]
# set up list with the file suffixes that need emitting
# when a feature is found
- file_tests_suff = [['.aux'],
- ['.idx', '.ind', '.ilg'],
- ['.bbl', '.blg'],
- ['.toc'],
- ['.lof'],
- ['.lot'],
- ['.out'],
- ['.nlo', '.nls', '.nlg'],
- ['.glo', '.gls', '.glg'],
- ['.glo', '.gls', '.glg'],
- ['.acn', '.acr', '.alg'],
- ['.nav', '.snm', '.out', '.toc'] ]
+ file_tests_suff = [['.aux','aux_file'],
+ ['.idx', '.ind', '.ilg','makeindex'],
+ ['.bbl', '.blg','bibliography'],
+ ['.bbl', '.blg','bibunit'],
+ ['.toc','contents'],
+ ['.lof','figures'],
+ ['.lot','tables'],
+ ['.out','hyperref'],
+ ['.nlo', '.nls', '.nlg','nomenclature'],
+ ['.glo', '.gls', '.glg','glossary'],
+ ['.glo', '.gls', '.glg','glossaries'],
+ ['.acn', '.acr', '.alg','acronyms'],
+ ['.nav', '.snm', '.out', '.toc','beamer'] ]
# build the list of lists
file_tests = []
for i in range(len(file_tests_search)):
@@ -670,11 +678,21 @@ 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 (theSearch != None) or (not source[0].exists() ):
- for suffix in suffix_list:
- env.SideEffect(targetbase + suffix,target[0])
- if Verbose:
- print "side effect :",targetbase + suffix
- env.Clean(target[0],targetbase + suffix)
+ file_list = [targetbase,]
+ # for bibunit we need a list of files
+ if suffix_list[-1] == 'bibunit':
+ file_basename = os.path.join(targetdir, 'bu*.aux')
+ 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]
+ # 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
+ env.Clean(target[0],file_name + suffix)
for aFile in aux_files:
aFile_base = SCons.Util.splitext(aFile)[0]
diff --git a/test/TEX/variant_dir_bibunit.py b/test/TEX/variant_dir_bibunit.py
new file mode 100644
index 0000000..0603922
--- /dev/null
+++ b/test/TEX/variant_dir_bibunit.py
@@ -0,0 +1,279 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test creation of a fully-featured TeX document (with bibunit
+driven bibliographies) in a variant_dir.
+
+Also test that the target can be named differently than what
+Latex produces by default.
+
+Test courtesy Rob Managan.
+"""
+
+import TestSCons
+import os
+
+test = TestSCons.TestSCons()
+
+latex = test.where_is('pdflatex')
+bibtex = test.where_is('bibtex')
+if not latex or not bibtex:
+ test.skip_test("Could not find 'latex' or 'bibtex'; skipping test.\n")
+
+bibunits = os.system('kpsewhich bibunits.sty')
+if not bibunits==0:
+ test.skip_test("bibunits.sty not installed; skipping test(s).\n")
+
+test.subdir(['src'])
+
+
+test.write(['SConstruct'], """\
+import os
+
+env = Environment(ENV = { 'PATH' : os.environ['PATH'] })
+Export(['env'])
+
+env.SConscript(os.path.join('src', 'SConscript'),
+ variant_dir='build',
+ duplicate=0)
+""")
+
+
+test.write(['src', 'SConscript'], """\
+Import('env')
+
+env.PDF('units.tex')
+""")
+
+
+test.write(['src', 'units.tex'],
+r"""
+\documentclass{article}
+\usepackage{bibunits}
+\begin{document}
+\begin{bibunit}[plain]
+some text \cite{lamport:1994} more text more citations
+2
+\putbib[units]
+\end{bibunit}
+some text between the units
+\begin{bibunit}[abbrv]
+some text \cite{gnu:1998} more text more citations 2
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text \cite{gnu:1999} more text more citations 3
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text \cite{gnu:1998} more text more citations 4
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text \cite{gnu:2000} more text more citations 5
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text \cite{gnu:1998} more text more citations 6
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text \cite{gnu:2001} more text more citations 7
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text more \cite{gnu:2002} text more citations 8
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text more text more citations 9
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text \cite{gnu:1998} more text more citations 10
+\putbib[units]
+\end{bibunit}
+
+some text between the units
+\begin{bibunit}[abbrv]
+some text \cite{gnu:2003} more text more citations 11
+\putbib[units]
+\end{bibunit}
+
+
+after the last unit another ref \cite{gnu:1998} and then a second \cite{gnu:2003}
+\bibliographystyle{unsrt}
+\bibliography{units}
+\end{document}
+""")
+
+
+test.write(['src', 'units.bib'], """\
+%% This BibTeX bibliography file was created using BibDesk.
+%% http://bibdesk.sourceforge.net/
+
+@techreport{gnu:1998,
+ Author = {A. N. Author},
+ Date-Added = {2006-11-15 12:51:30 -0800},
+ Date-Modified = {2006-11-15 12:52:35 -0800},
+ Institution = {none},
+ Month = {November},
+ Title = {A Test Paper},
+ Year = {1998}}
+@techreport{gnu:1999,
+ Author = {A. N. Author},
+ Date-Added = {2006-11-15 12:51:30 -0800},
+ Date-Modified = {2006-11-15 12:52:35 -0800},
+ Institution = {none},
+ Month = {November},
+ Title = {A Test Paper 1},
+ Year = {1999}}
+@techreport{gnu:2000,
+ Author = {A. N. Author},
+ Date-Added = {2006-11-15 12:51:30 -0800},
+ Date-Modified = {2006-11-15 12:52:35 -0800},
+ Institution = {none},
+ Month = {November},
+ Title = {A Test Paper 2},
+ Year = {2000}}
+@techreport{gnu:2001,
+ Author = {A. N. Author},
+ Date-Added = {2006-11-15 12:51:30 -0800},
+ Date-Modified = {2006-11-15 12:52:35 -0800},
+ Institution = {none},
+ Month = {November},
+ Title = {A Test Paper 3},
+ Year = {2001}}
+@techreport{gnu:2002,
+ Author = {A. N. Author},
+ Date-Added = {2006-11-15 12:51:30 -0800},
+ Date-Modified = {2006-11-15 12:52:35 -0800},
+ Institution = {none},
+ Month = {November},
+ Title = {A Test Paper 4},
+ Year = {2002}}
+@techreport{gnu:2003,
+ Author = {A. N. Author},
+ Date-Added = {2006-11-15 12:51:30 -0800},
+ Date-Modified = {2006-11-15 12:52:35 -0800},
+ Institution = {none},
+ Month = {November},
+ Title = {A Test Paper 5},
+ Year = {2003}}
+@techreport{lamport:1994,
+ Author = {A. N. Lamport},
+ Date-Added = {2006-11-15 12:51:30 -0800},
+ Date-Modified = {2006-11-15 12:52:35 -0800},
+ Institution = {none},
+ Month = {November},
+ Title = {A Test Paper},
+ Year = {1994}}
+""")
+
+
+
+#test.run(arguments = '.', stderr=None)
+test.run(arguments = '.')
+
+
+# All (?) the files we expect will get created in the variant_dir
+# (build/docs) and not in the srcdir (src).
+files = [
+'bu.aux',
+'bu1.aux',
+'bu1.bbl',
+'bu1.blg',
+'bu10.aux',
+'bu10.bbl',
+'bu10.blg',
+'bu11.aux',
+'bu11.bbl',
+'bu11.blg',
+'bu2.aux',
+'bu2.bbl',
+'bu2.blg',
+'bu3.aux',
+'bu3.bbl',
+'bu3.blg',
+'bu4.aux',
+'bu4.bbl',
+'bu4.blg',
+'bu5.aux',
+'bu5.bbl',
+'bu5.blg',
+'bu6.aux',
+'bu6.bbl',
+'bu6.blg',
+'bu7.aux',
+'bu7.bbl',
+'bu7.blg',
+'bu8.aux',
+'bu8.bbl',
+'bu8.blg',
+'bu9.aux',
+'bu9.bbl',
+'bu9.blg',
+'units.aux',
+'units.bbl',
+'units.blg',
+'units.fls',
+'units.log',
+'units.pdf',
+]
+
+for f in files:
+ test.must_exist(['build', f])
+ test.must_not_exist(['src', f])
+
+test.run(arguments = '-c')
+
+for f in files:
+ test.must_not_exist(['build', f])
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: