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.

116 lines
4.1 KiB

6 years ago
  1. """SCons.Tool.jar
  2. Tool-specific initialization for jar.
  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. #
  29. __revision__ = "src/engine/SCons/Tool/jar.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  30. import SCons.Subst
  31. import SCons.Util
  32. def jarSources(target, source, env, for_signature):
  33. """Only include sources that are not a manifest file."""
  34. try:
  35. env['JARCHDIR']
  36. except KeyError:
  37. jarchdir_set = False
  38. else:
  39. jarchdir_set = True
  40. jarchdir = env.subst('$JARCHDIR', target=target, source=source)
  41. if jarchdir:
  42. jarchdir = env.fs.Dir(jarchdir)
  43. result = []
  44. for src in source:
  45. contents = src.get_text_contents()
  46. if contents[:16] != "Manifest-Version":
  47. if jarchdir_set:
  48. _chdir = jarchdir
  49. else:
  50. try:
  51. _chdir = src.attributes.java_classdir
  52. except AttributeError:
  53. _chdir = None
  54. if _chdir:
  55. # If we are changing the dir with -C, then sources should
  56. # be relative to that directory.
  57. src = SCons.Subst.Literal(src.get_path(_chdir))
  58. result.append('-C')
  59. result.append(_chdir)
  60. result.append(src)
  61. return result
  62. def jarManifest(target, source, env, for_signature):
  63. """Look in sources for a manifest file, if any."""
  64. for src in source:
  65. contents = src.get_text_contents()
  66. if contents[:16] == "Manifest-Version":
  67. return src
  68. return ''
  69. def jarFlags(target, source, env, for_signature):
  70. """If we have a manifest, make sure that the 'm'
  71. flag is specified."""
  72. jarflags = env.subst('$JARFLAGS', target=target, source=source)
  73. for src in source:
  74. contents = src.get_text_contents()
  75. if contents[:16] == "Manifest-Version":
  76. if not 'm' in jarflags:
  77. return jarflags + 'm'
  78. break
  79. return jarflags
  80. def generate(env):
  81. """Add Builders and construction variables for jar to an Environment."""
  82. SCons.Tool.CreateJarBuilder(env)
  83. env['JAR'] = 'jar'
  84. env['JARFLAGS'] = SCons.Util.CLVar('cf')
  85. env['_JARFLAGS'] = jarFlags
  86. env['_JARMANIFEST'] = jarManifest
  87. env['_JARSOURCES'] = jarSources
  88. env['_JARCOM'] = '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARSOURCES'
  89. env['JARCOM'] = "${TEMPFILE('$_JARCOM','$JARCOMSTR')}"
  90. env['JARSUFFIX'] = '.jar'
  91. def exists(env):
  92. # As reported by Jan Nijtmans in issue #2730, the simple
  93. # return env.Detect('jar')
  94. # doesn't always work during initialization. For now, we
  95. # stop trying to detect an executable (analogous to the
  96. # javac Builder).
  97. # TODO: Come up with a proper detect() routine...and enable it.
  98. return 1
  99. # Local Variables:
  100. # tab-width:4
  101. # indent-tabs-mode:nil
  102. # End:
  103. # vim: set expandtab tabstop=4 shiftwidth=4: