You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.0 KiB

6 years ago
  1. """SCons.Tool.dvipdf
  2. Tool-specific initialization for dvipdf.
  3. There normally shouldn't be any need to import this module directly.
  4. It will usually be imported through the generic SCons.Tool.Tool()
  5. selection method.
  6. """
  7. #
  8. # Copyright (c) 2001 - 2017 The SCons Foundation
  9. #
  10. # Permission is hereby granted, free of charge, to any person obtaining
  11. # a copy of this software and associated documentation files (the
  12. # "Software"), to deal in the Software without restriction, including
  13. # without limitation the rights to use, copy, modify, merge, publish,
  14. # distribute, sublicense, and/or sell copies of the Software, and to
  15. # permit persons to whom the Software is furnished to do so, subject to
  16. # the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included
  19. # in all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  22. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  23. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. __revision__ = "src/engine/SCons/Tool/dvipdf.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  29. import SCons.Action
  30. import SCons.Defaults
  31. import SCons.Tool.pdf
  32. import SCons.Tool.tex
  33. import SCons.Util
  34. _null = SCons.Scanner.LaTeX._null
  35. def DviPdfPsFunction(XXXDviAction, target = None, source= None, env=None):
  36. """A builder for DVI files that sets the TEXPICTS environment
  37. variable before running dvi2ps or dvipdf."""
  38. try:
  39. abspath = source[0].attributes.path
  40. except AttributeError :
  41. abspath = ''
  42. saved_env = SCons.Scanner.LaTeX.modify_env_var(env, 'TEXPICTS', abspath)
  43. result = XXXDviAction(target, source, env)
  44. if saved_env is _null:
  45. try:
  46. del env['ENV']['TEXPICTS']
  47. except KeyError:
  48. pass # was never set
  49. else:
  50. env['ENV']['TEXPICTS'] = saved_env
  51. return result
  52. def DviPdfFunction(target = None, source= None, env=None):
  53. result = DviPdfPsFunction(PDFAction,target,source,env)
  54. return result
  55. def DviPdfStrFunction(target = None, source= None, env=None):
  56. """A strfunction for dvipdf that returns the appropriate
  57. command string for the no_exec options."""
  58. if env.GetOption("no_exec"):
  59. result = env.subst('$DVIPDFCOM',0,target,source)
  60. else:
  61. result = ''
  62. return result
  63. PDFAction = None
  64. DVIPDFAction = None
  65. def PDFEmitter(target, source, env):
  66. """Strips any .aux or .log files from the input source list.
  67. These are created by the TeX Builder that in all likelihood was
  68. used to generate the .dvi file we're using as input, and we only
  69. care about the .dvi file.
  70. """
  71. def strip_suffixes(n):
  72. return not SCons.Util.splitext(str(n))[1] in ['.aux', '.log']
  73. source = [src for src in source if strip_suffixes(src)]
  74. return (target, source)
  75. def generate(env):
  76. """Add Builders and construction variables for dvipdf to an Environment."""
  77. global PDFAction
  78. if PDFAction is None:
  79. PDFAction = SCons.Action.Action('$DVIPDFCOM', '$DVIPDFCOMSTR')
  80. global DVIPDFAction
  81. if DVIPDFAction is None:
  82. DVIPDFAction = SCons.Action.Action(DviPdfFunction, strfunction = DviPdfStrFunction)
  83. from . import pdf
  84. pdf.generate(env)
  85. bld = env['BUILDERS']['PDF']
  86. bld.add_action('.dvi', DVIPDFAction)
  87. bld.add_emitter('.dvi', PDFEmitter)
  88. env['DVIPDF'] = 'dvipdf'
  89. env['DVIPDFFLAGS'] = SCons.Util.CLVar('')
  90. env['DVIPDFCOM'] = 'cd ${TARGET.dir} && $DVIPDF $DVIPDFFLAGS ${SOURCE.file} ${TARGET.file}'
  91. # Deprecated synonym.
  92. env['PDFCOM'] = ['$DVIPDFCOM']
  93. def exists(env):
  94. SCons.Tool.tex.generate_darwin(env)
  95. return env.Detect('dvipdf')
  96. # Local Variables:
  97. # tab-width:4
  98. # indent-tabs-mode:nil
  99. # End:
  100. # vim: set expandtab tabstop=4 shiftwidth=4: