From: stevenknight Date: Sun, 20 Nov 2005 03:11:08 +0000 (+0000) Subject: Have the LaTeX scanner also look for \includegraphics{} strings. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=33b152233665f67260dcce8aebce8aec7f527676;p=scons.git Have the LaTeX scanner also look for \includegraphics{} strings. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1397 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Scanner/LaTeX.py b/src/engine/SCons/Scanner/LaTeX.py index 22a5e871..6451a58a 100644 --- a/src/engine/SCons/Scanner/LaTeX.py +++ b/src/engine/SCons/Scanner/LaTeX.py @@ -1,6 +1,6 @@ """SCons.Scanner.LaTeX -This module implements the dependency scanner for LaTeX code. +This module implements the dependency scanner for LaTeX code. """ @@ -35,15 +35,32 @@ import SCons.Scanner def LaTeXScanner(fs = SCons.Node.FS.default_fs): """Return a prototype Scanner instance for scanning LaTeX source files""" ds = LaTeX(name = "LaTeXScanner", - suffixes = '$LATEXSUFFIXES', - path_variable = 'TEXINPUTS', - regex = '\\\\(?:include|input){([^}]*)}', - recursive = 0) + suffixes = '$LATEXSUFFIXES', + path_variable = 'TEXINPUTS', + regex = '\\\\(include|includegraphics(?:\[[^\]]+\])?|input){([^}]*)}', + recursive = 0) return ds class LaTeX(SCons.Scanner.Classic): + """Class for scanning LaTeX files for included files. + + Unlike most scanners, which use regular expressions that just + return the included file name, this returns a tuple consisting + of the keyword for the inclusion ("include", "includegraphics" or + "input"), and then the file name itself. Base on a quick look at + LaTeX documentation, it seems that we need a should append .tex + suffix for "include" and "input" keywords, but leave the file name + untouched for "includegraphics." + """ + def latex_name(self, include): + filename = include[1] + if include[0][:15] != 'includegraphics': + filename = filename + '.tex' + return filename + def sort_key(self, include): + return SCons.Node.FS._my_normcase(self.latex_name(include)) def find_include(self, include, source_dir, path): if callable(path): path=path() - i = SCons.Node.FS.find_file(include + '.tex', + i = SCons.Node.FS.find_file(self.latex_name(include), (source_dir,) + path) return i, include diff --git a/src/engine/SCons/Scanner/LaTeXTests.py b/src/engine/SCons/Scanner/LaTeXTests.py index 3fc121c4..1f1861e8 100644 --- a/src/engine/SCons/Scanner/LaTeXTests.py +++ b/src/engine/SCons/Scanner/LaTeXTests.py @@ -40,16 +40,24 @@ test.write('test1.latex',""" \include{inc1} \input{inc2} """) + test.write('test2.latex',""" \include{inc1} \include{inc3} """) +test.write('test3.latex',""" +\includegraphics{inc4.eps} +\includegraphics[width=60mm]{inc5.xyz} +""") + test.subdir('subdir') test.write('inc1.tex',"\n") test.write('inc2.tex',"\n") -test.write([ 'subdir', 'inc3.tex'], "\n") +test.write(['subdir', 'inc3.tex'], "\n") +test.write(['subdir', 'inc4.eps'], "\n") +test.write('inc5.xyz', "\n") # define some helpers: # copied from CTest.py @@ -119,11 +127,21 @@ class LaTeXScannerTestCase2(unittest.TestCase): headers = ['inc1.tex', 'subdir/inc3.tex'] deps_match(self, deps, headers) +class LaTeXScannerTestCase3(unittest.TestCase): + def runTest(self): + env = DummyEnvironment(TEXINPUTS=[test.workpath("subdir")]) + s = SCons.Scanner.LaTeX.LaTeXScanner() + path = s.path(env) + deps = s(env.File('test3.latex'), env, path) + files = ['subdir/inc4.eps', 'inc5.xyz'] + deps_match(self, deps, files) + def suite(): suite = unittest.TestSuite() suite.addTest(LaTeXScannerTestCase1()) suite.addTest(LaTeXScannerTestCase2()) + suite.addTest(LaTeXScannerTestCase3()) return suite if __name__ == "__main__": @@ -131,4 +149,3 @@ if __name__ == "__main__": result = runner.run(suite()) if not result.wasSuccessful(): sys.exit(1) -