diff options
author | Robert Managan <managan1@llnl.gov> | 2008-09-04 18:05:49 (GMT) |
---|---|---|
committer | Robert Managan <managan1@llnl.gov> | 2008-09-04 18:05:49 (GMT) |
commit | 6a4d9df86030463c35d40e1a314721eb546fb84e (patch) | |
tree | 5fcab134f7685c3c589cd2b701d811b6cbc12131 | |
parent | 43528ea6633d5d0d2005de38298b45d631642436 (diff) | |
download | SCons-6a4d9df86030463c35d40e1a314721eb546fb84e.zip SCons-6a4d9df86030463c35d40e1a314721eb546fb84e.tar.gz SCons-6a4d9df86030463c35d40e1a314721eb546fb84e.tar.bz2 |
Added a strfunction to the various tex builders. Since the sub-actions report
their commands as they build the strfunction only returns a string for
GetOption("no_exec") which covers --dry-run.
Therefore --dry-run now gets output, the first command to be run plus " ..."
to indicate that the ral builder may repeat or run bibtex, makeindex,...
Also updating the flags to pass -interaction=nonstopmode
This prevents errors in the .tex files from stopping the build
while Latex asks for input.
Updated several tests to handle this new flag by switching to getopt module
-rw-r--r-- | src/engine/SCons/Tool/latex.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Tool/pdflatex.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Tool/pdftex.py | 6 | ||||
-rw-r--r-- | src/engine/SCons/Tool/tex.py | 21 | ||||
-rw-r--r-- | test/DVIPDF/DVIPDF.py | 18 | ||||
-rw-r--r-- | test/DVIPDF/DVIPDFFLAGS.py | 12 | ||||
-rw-r--r-- | test/DVIPS/DVIPS.py | 12 | ||||
-rw-r--r-- | test/DVIPS/DVIPSFLAGS.py | 12 | ||||
-rw-r--r-- | test/TEX/LATEX.py | 15 | ||||
-rw-r--r-- | test/TEX/PDFLATEX.py | 6 | ||||
-rw-r--r-- | test/TEX/PDFTEX.py | 6 | ||||
-rw-r--r-- | test/TEX/TEX.py | 8 | ||||
-rw-r--r-- | test/TEX/dryrun.py | 67 |
13 files changed, 150 insertions, 42 deletions
diff --git a/src/engine/SCons/Tool/latex.py b/src/engine/SCons/Tool/latex.py index c4934c3..8258829 100644 --- a/src/engine/SCons/Tool/latex.py +++ b/src/engine/SCons/Tool/latex.py @@ -45,7 +45,8 @@ LaTeXAction = None def LaTeXAuxFunction(target = None, source= None, env=None): SCons.Tool.tex.InternalLaTeXAuxAction( LaTeXAction, target, source, env ) -LaTeXAuxAction = SCons.Action.Action(LaTeXAuxFunction, strfunction=None) +LaTeXAuxAction = SCons.Action.Action(LaTeXAuxFunction, + strfunction=SCons.Tool.tex.TeXLaTeXStrFunction) def generate(env): """Add Builders and construction variables for LaTeX to an Environment.""" @@ -63,7 +64,7 @@ def generate(env): bld.add_emitter('.latex', SCons.Tool.tex.tex_emitter) env['LATEX'] = 'latex' - env['LATEXFLAGS'] = SCons.Util.CLVar('') + env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode') env['LATEXCOM'] = 'cd ${TARGET.dir} && $LATEX $LATEXFLAGS ${SOURCE.file}' env['LATEXRETRIES'] = 3 diff --git a/src/engine/SCons/Tool/pdflatex.py b/src/engine/SCons/Tool/pdflatex.py index 97420a8..b8a7736 100644 --- a/src/engine/SCons/Tool/pdflatex.py +++ b/src/engine/SCons/Tool/pdflatex.py @@ -54,7 +54,7 @@ def generate(env): global PDFLaTeXAuxAction if PDFLaTeXAuxAction is None: PDFLaTeXAuxAction = SCons.Action.Action(PDFLaTeXAuxFunction, - strfunction=None) + strfunction=SCons.Tool.tex.TeXLaTeXStrFunction) import pdf pdf.generate(env) @@ -66,7 +66,7 @@ def generate(env): bld.add_emitter('.latex', SCons.Tool.tex.tex_emitter) env['PDFLATEX'] = 'pdflatex' - env['PDFLATEXFLAGS'] = SCons.Util.CLVar('') + env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode') env['PDFLATEXCOM'] = 'cd ${TARGET.dir} && $PDFLATEX $PDFLATEXFLAGS ${SOURCE.file}' env['LATEXRETRIES'] = 3 diff --git a/src/engine/SCons/Tool/pdftex.py b/src/engine/SCons/Tool/pdftex.py index e740fac..7bd57b0 100644 --- a/src/engine/SCons/Tool/pdftex.py +++ b/src/engine/SCons/Tool/pdftex.py @@ -71,7 +71,7 @@ def generate(env): global PDFTeXLaTeXAction if PDFTeXLaTeXAction is None: PDFTeXLaTeXAction = SCons.Action.Action(PDFTeXLaTeXFunction, - strfunction=None) + strfunction=SCons.Tool.tex.TeXLaTeXStrFunction) import pdf pdf.generate(env) @@ -81,12 +81,12 @@ def generate(env): bld.add_emitter('.tex', SCons.Tool.tex.tex_emitter) env['PDFTEX'] = 'pdftex' - env['PDFTEXFLAGS'] = SCons.Util.CLVar('') + env['PDFTEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode') env['PDFTEXCOM'] = 'cd ${TARGET.dir} && $PDFTEX $PDFTEXFLAGS ${SOURCE.file}' # Duplicate from latex.py. If latex.py goes away, then this is still OK. env['PDFLATEX'] = 'pdflatex' - env['PDFLATEXFLAGS'] = SCons.Util.CLVar('') + env['PDFLATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode') env['PDFLATEXCOM'] = 'cd ${TARGET.dir} && $PDFLATEX $PDFLATEXFLAGS ${SOURCE.file}' env['LATEXRETRIES'] = 3 diff --git a/src/engine/SCons/Tool/tex.py b/src/engine/SCons/Tool/tex.py index c3156a3..29dc81d 100644 --- a/src/engine/SCons/Tool/tex.py +++ b/src/engine/SCons/Tool/tex.py @@ -208,7 +208,19 @@ def TeXLaTeXFunction(target = None, source= None, env=None): LaTeXAuxAction(target,source,env) else: TeXAction(target,source,env) - return 0 + +def TeXLaTeXStrFunction(target = None, source= None, env=None): + """A strfunction for TeX and LaTeX that scans the source file to + decide the "flavor" of the source and then returns the appropriate + command string.""" + if env.GetOption("no_exec"): + if is_LaTeX(source): + result = env.subst('$LATEXCOM',0,target,source)+" ..." + else: + result = env.subst("$TEXCOM",0,target,source)+" ..." + else: + result = '' + return result def tex_emitter(target, source, env): base = SCons.Util.splitext(str(source[0]))[0] @@ -275,7 +287,8 @@ def generate(env): global TeXLaTeXAction if TeXLaTeXAction is None: - TeXLaTeXAction = SCons.Action.Action(TeXLaTeXFunction, strfunction=None) + TeXLaTeXAction = SCons.Action.Action(TeXLaTeXFunction, + strfunction=TeXLaTeXStrFunction) import dvi dvi.generate(env) @@ -285,12 +298,12 @@ def generate(env): bld.add_emitter('.tex', tex_emitter) env['TEX'] = 'tex' - env['TEXFLAGS'] = SCons.Util.CLVar('') + env['TEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode') env['TEXCOM'] = 'cd ${TARGET.dir} && $TEX $TEXFLAGS ${SOURCE.file}' # Duplicate from latex.py. If latex.py goes away, then this is still OK. env['LATEX'] = 'latex' - env['LATEXFLAGS'] = SCons.Util.CLVar('') + env['LATEXFLAGS'] = SCons.Util.CLVar('-interaction=nonstopmode') env['LATEXCOM'] = 'cd ${TARGET.dir} && $LATEX $LATEXFLAGS ${SOURCE.file}' env['LATEXRETRIES'] = 3 diff --git a/test/DVIPDF/DVIPDF.py b/test/DVIPDF/DVIPDF.py index 8d36e5a..6f62f34 100644 --- a/test/DVIPDF/DVIPDF.py +++ b/test/DVIPDF/DVIPDF.py @@ -39,8 +39,10 @@ test = TestSCons.TestSCons() test.write('mytex.py', r""" import os import sys -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') out_file = open(base_name+'.dvi', 'wb') for l in infile.readlines(): if l[:4] != '#tex': @@ -51,8 +53,10 @@ sys.exit(0) test.write('mylatex.py', r""" import os import sys -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') out_file = open(base_name+'.dvi', 'wb') for l in infile.readlines(): if l[:6] != '#latex': @@ -63,8 +67,10 @@ sys.exit(0) test.write('mydvipdf.py', r""" import os import sys -infile = open(sys.argv[1], 'rb') -out_file = open(sys.argv[2], 'wb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +infile = open(arg[0], 'rb') +out_file = open(arg[1], 'wb') for l in infile.readlines(): if l[:7] != '#dvipdf': out_file.write(l) diff --git a/test/DVIPDF/DVIPDFFLAGS.py b/test/DVIPDF/DVIPDFFLAGS.py index 4268705..cc90105 100644 --- a/test/DVIPDF/DVIPDFFLAGS.py +++ b/test/DVIPDF/DVIPDFFLAGS.py @@ -39,8 +39,10 @@ test = TestSCons.TestSCons() test.write('mytex.py', r""" import os import sys -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') out_file = open(base_name+'.dvi', 'wb') for l in infile.readlines(): if l[:4] != '#tex': @@ -51,8 +53,10 @@ sys.exit(0) test.write('mylatex.py', r""" import os import sys -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') out_file = open(base_name+'.dvi', 'wb') for l in infile.readlines(): if l[:6] != '#latex': diff --git a/test/DVIPS/DVIPS.py b/test/DVIPS/DVIPS.py index 490ac95..882cb6a 100644 --- a/test/DVIPS/DVIPS.py +++ b/test/DVIPS/DVIPS.py @@ -39,8 +39,10 @@ test = TestSCons.TestSCons() test.write('mytex.py', r""" import os import sys -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') out_file = open(base_name+'.dvi', 'wb') for l in infile.readlines(): if l[:4] != '#tex': @@ -51,8 +53,10 @@ sys.exit(0) test.write('mylatex.py', r""" import os import sys -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') out_file = open(base_name+'.dvi', 'wb') for l in infile.readlines(): if l[:6] != '#latex': diff --git a/test/DVIPS/DVIPSFLAGS.py b/test/DVIPS/DVIPSFLAGS.py index 635acb0..4b70e41 100644 --- a/test/DVIPS/DVIPSFLAGS.py +++ b/test/DVIPS/DVIPSFLAGS.py @@ -39,8 +39,10 @@ test = TestSCons.TestSCons() test.write('mytex.py', r""" import os import sys -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') out_file = open(base_name+'.dvi', 'wb') for l in infile.readlines(): if l[:4] != '#tex': @@ -51,8 +53,10 @@ sys.exit(0) test.write('mylatex.py', r""" import os import sys -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') out_file = open(base_name+'.dvi', 'wb') for l in infile.readlines(): if l[:6] != '#latex': diff --git a/test/TEX/LATEX.py b/test/TEX/LATEX.py index 0636109..bb034be 100644 --- a/test/TEX/LATEX.py +++ b/test/TEX/LATEX.py @@ -45,8 +45,10 @@ test = TestSCons.TestSCons() test.write('mylatex.py', r""" import sys import os -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') dvi_file = open(base_name+'.dvi', 'wb') aux_file = open(base_name+'.aux', 'wb') log_file = open(base_name+'.log', 'wb') @@ -112,9 +114,10 @@ ENV = { 'PATH' : os.environ['PATH'], foo = Environment(ENV = ENV) latex = foo.Dictionary('LATEX') makeindex = foo.Dictionary('MAKEINDEX') +python_path = r'%(_python_)s' bar = Environment(ENV = ENV, - LATEX = r'%(_python_)s wrapper.py ' + latex, - MAKEINDEX = r' wrapper.py ' + makeindex) + LATEX = python_path + ' wrapper.py ' + latex, + MAKEINDEX = python_path + ' wrapper.py ' + makeindex) foo.DVI(target = 'foo.dvi', source = 'foo.ltx') bar.DVI(target = 'bar', source = 'bar.latex') @@ -130,7 +133,7 @@ This is the %s LaTeX file. """ makeindex = r""" -\documentclass{letter} +\documentclass{report} \usepackage{makeidx} \makeindex \begin{document} @@ -141,7 +144,7 @@ This is the %s LaTeX file. """ latex1 = r""" -\documentclass{letter} +\documentclass{report} \usepackage{makeidx} \makeindex \begin{document} diff --git a/test/TEX/PDFLATEX.py b/test/TEX/PDFLATEX.py index e1cf00e..11ada7b 100644 --- a/test/TEX/PDFLATEX.py +++ b/test/TEX/PDFLATEX.py @@ -45,8 +45,10 @@ test = TestSCons.TestSCons() test.write('mypdflatex.py', r""" import sys import os -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') pdf_file = open(base_name+'.pdf', 'wb') aux_file = open(base_name+'.aux', 'wb') log_file = open(base_name+'.log', 'wb') diff --git a/test/TEX/PDFTEX.py b/test/TEX/PDFTEX.py index ad77b8a..cde6015 100644 --- a/test/TEX/PDFTEX.py +++ b/test/TEX/PDFTEX.py @@ -45,8 +45,10 @@ test = TestSCons.TestSCons() test.write('mypdftex.py', r""" import sys import os -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[2:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') pdf_file = open(base_name+'.pdf', 'wb') aux_file = open(base_name+'.aux', 'wb') log_file = open(base_name+'.log', 'wb') diff --git a/test/TEX/TEX.py b/test/TEX/TEX.py index eaea49a..5a0daec 100644 --- a/test/TEX/TEX.py +++ b/test/TEX/TEX.py @@ -45,8 +45,10 @@ test = TestSCons.TestSCons() test.write('mytex.py', r""" import sys import os -base_name = os.path.splitext(sys.argv[1])[0] -infile = open(sys.argv[1], 'rb') +import getopt +cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:', []) +base_name = os.path.splitext(arg[0])[0] +infile = open(arg[0], 'rb') dvi_file = open(base_name+'.dvi', 'wb') aux_file = open(base_name+'.aux', 'wb') log_file = open(base_name+'.log', 'wb') @@ -175,7 +177,7 @@ Run \texttt{latex}, then \texttt{bibtex}, then \texttt{latex} twice again \cite{ test.run(stderr = None) output_lines = string.split(test.stdout(), '\n') - reruns = filter(lambda x: string.find(x, 'latex rerun.tex') != -1, output_lines) + reruns = filter(lambda x: string.find(x, 'latex -interaction=nonstopmode rerun.tex') != -1, output_lines) if len(reruns) != 2: print "Expected 2 latex calls, got %s:" % len(reruns) print string.join(reruns, '\n') diff --git a/test/TEX/dryrun.py b/test/TEX/dryrun.py new file mode 100644 index 0000000..80458af --- /dev/null +++ b/test/TEX/dryrun.py @@ -0,0 +1,67 @@ +#!/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__" + +""" +Validate that we can set the LATEX string to our own utility, that +the produced .dvi, .aux and .log files get removed by the -c option, +and that we can use this to wrap calls to the real latex utility. +""" + +import os +import os.path +import string +import sys +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +latex = test.where_is('latex') + +if not latex: + test.skip_test('could not find latex; skipping test\n') + +test.write('SConstruct', """ +import os +ENV = { 'PATH' : os.environ['PATH'] } +foo = Environment(ENV = ENV) +foo.DVI(target = 'foo.dvi', source = 'foo.ltx') +""" % locals()) + +test.write('foo.ltx', r""" +\documentclass{letter} +\begin{document} +This is the foo.ltx file. +\end{document} +""") + +test.run(arguments = '--dry-run', stdout = test.wrap_stdout("""\ +cd . && latex -interaction=nonstopmode foo.ltx ... +"""), stderr = None) + + +test.pass_test() |