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.

108 lines
4.3 KiB

6 years ago
  1. """ msgfmt tool """
  2. # Copyright (c) 2001 - 2017 The SCons Foundation
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining
  5. # a copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish,
  8. # distribute, sublicense, and/or sell copies of the Software, and to
  9. # permit persons to whom the Software is furnished to do so, subject to
  10. # the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  16. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. __revision__ = "src/engine/SCons/Tool/msgfmt.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  23. from SCons.Builder import BuilderBase
  24. #############################################################################
  25. class _MOFileBuilder(BuilderBase):
  26. """ The builder class for `MO` files.
  27. The reason for this builder to exists and its purpose is quite simillar
  28. as for `_POFileBuilder`. This time, we extend list of sources, not targets,
  29. and call `BuilderBase._execute()` only once (as we assume single-target
  30. here).
  31. """
  32. def _execute(self, env, target, source, *args, **kw):
  33. # Here we add support for 'LINGUAS_FILE' keyword. Emitter is not suitable
  34. # in this case, as it is called too late (after multiple sources
  35. # are handled single_source builder.
  36. import SCons.Util
  37. from SCons.Tool.GettextCommon import _read_linguas_from_files
  38. linguas_files = None
  39. if 'LINGUAS_FILE' in env and env['LINGUAS_FILE'] is not None:
  40. linguas_files = env['LINGUAS_FILE']
  41. # This should prevent from endless recursion.
  42. env['LINGUAS_FILE'] = None
  43. # We read only languages. Suffixes shall be added automatically.
  44. linguas = _read_linguas_from_files(env, linguas_files)
  45. if SCons.Util.is_List(source):
  46. source.extend(linguas)
  47. elif source is not None:
  48. source = [source] + linguas
  49. else:
  50. source = linguas
  51. result = BuilderBase._execute(self,env,target,source,*args, **kw)
  52. if linguas_files is not None:
  53. env['LINGUAS_FILE'] = linguas_files
  54. return result
  55. #############################################################################
  56. #############################################################################
  57. def _create_mo_file_builder(env, **kw):
  58. """ Create builder object for `MOFiles` builder """
  59. import SCons.Action
  60. # FIXME: What factory use for source? Ours or their?
  61. kw['action'] = SCons.Action.Action('$MSGFMTCOM','$MSGFMTCOMSTR')
  62. kw['suffix'] = '$MOSUFFIX'
  63. kw['src_suffix'] = '$POSUFFIX'
  64. kw['src_builder'] = '_POUpdateBuilder'
  65. kw['single_source'] = True
  66. return _MOFileBuilder(**kw)
  67. #############################################################################
  68. #############################################################################
  69. def generate(env,**kw):
  70. """ Generate `msgfmt` tool """
  71. import SCons.Util
  72. from SCons.Tool.GettextCommon import _detect_msgfmt
  73. try:
  74. env['MSGFMT'] = _detect_msgfmt(env)
  75. except:
  76. env['MSGFMT'] = 'msgfmt'
  77. env.SetDefault(
  78. MSGFMTFLAGS = [ SCons.Util.CLVar('-c') ],
  79. MSGFMTCOM = '$MSGFMT $MSGFMTFLAGS -o $TARGET $SOURCE',
  80. MSGFMTCOMSTR = '',
  81. MOSUFFIX = ['.mo'],
  82. POSUFFIX = ['.po']
  83. )
  84. env.Append( BUILDERS = { 'MOFiles' : _create_mo_file_builder(env) } )
  85. #############################################################################
  86. #############################################################################
  87. def exists(env):
  88. """ Check if the tool exists """
  89. from SCons.Tool.GettextCommon import _msgfmt_exists
  90. try:
  91. return _msgfmt_exists(env)
  92. except:
  93. return False
  94. #############################################################################
  95. # Local Variables:
  96. # tab-width:4
  97. # indent-tabs-mode:nil
  98. # End:
  99. # vim: set expandtab tabstop=4 shiftwidth=4: