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.

120 lines
4.6 KiB

6 years ago
  1. """ msginit tool
  2. Tool specific initialization of msginit tool.
  3. """
  4. # Copyright (c) 2001 - 2017 The SCons Foundation
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining
  7. # a copy of this software and associated documentation files (the
  8. # "Software"), to deal in the Software without restriction, including
  9. # without limitation the rights to use, copy, modify, merge, publish,
  10. # distribute, sublicense, and/or sell copies of the Software, and to
  11. # permit persons to whom the Software is furnished to do so, subject to
  12. # the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included
  15. # in all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  18. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  19. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. __revision__ = "src/engine/SCons/Tool/msginit.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  25. import SCons.Warnings
  26. import SCons.Builder
  27. import re
  28. #############################################################################
  29. def _optional_no_translator_flag(env):
  30. """ Return '--no-translator' flag if we run *msginit(1)* in non-interactive
  31. mode."""
  32. import SCons.Util
  33. if 'POAUTOINIT' in env:
  34. autoinit = env['POAUTOINIT']
  35. else:
  36. autoinit = False
  37. if autoinit:
  38. return [SCons.Util.CLVar('--no-translator')]
  39. else:
  40. return [SCons.Util.CLVar('')]
  41. #############################################################################
  42. #############################################################################
  43. def _POInitBuilder(env, **kw):
  44. """ Create builder object for `POInit` builder. """
  45. import SCons.Action
  46. from SCons.Tool.GettextCommon import _init_po_files, _POFileBuilder
  47. action = SCons.Action.Action(_init_po_files, None)
  48. return _POFileBuilder(env, action=action, target_alias='$POCREATE_ALIAS')
  49. #############################################################################
  50. #############################################################################
  51. from SCons.Environment import _null
  52. #############################################################################
  53. def _POInitBuilderWrapper(env, target=None, source=_null, **kw):
  54. """ Wrapper for _POFileBuilder. We use it to make user's life easier.
  55. This wrapper checks for `$POTDOMAIN` construction variable (or override in
  56. `**kw`) and treats it appropriatelly.
  57. """
  58. if source is _null:
  59. if 'POTDOMAIN' in kw:
  60. domain = kw['POTDOMAIN']
  61. elif 'POTDOMAIN' in env:
  62. domain = env['POTDOMAIN']
  63. else:
  64. domain = 'messages'
  65. source = [ domain ] # NOTE: Suffix shall be appended automatically
  66. return env._POInitBuilder(target, source, **kw)
  67. #############################################################################
  68. #############################################################################
  69. def generate(env,**kw):
  70. """ Generate the `msginit` tool """
  71. import SCons.Util
  72. from SCons.Tool.GettextCommon import _detect_msginit
  73. try:
  74. env['MSGINIT'] = _detect_msginit(env)
  75. except:
  76. env['MSGINIT'] = 'msginit'
  77. msginitcom = '$MSGINIT ${_MSGNoTranslator(__env__)} -l ${_MSGINITLOCALE}' \
  78. + ' $MSGINITFLAGS -i $SOURCE -o $TARGET'
  79. # NOTE: We set POTSUFFIX here, in case the 'xgettext' is not loaded
  80. # (sometimes we really don't need it)
  81. env.SetDefault(
  82. POSUFFIX = ['.po'],
  83. POTSUFFIX = ['.pot'],
  84. _MSGINITLOCALE = '${TARGET.filebase}',
  85. _MSGNoTranslator = _optional_no_translator_flag,
  86. MSGINITCOM = msginitcom,
  87. MSGINITCOMSTR = '',
  88. MSGINITFLAGS = [ ],
  89. POAUTOINIT = False,
  90. POCREATE_ALIAS = 'po-create'
  91. )
  92. env.Append( BUILDERS = { '_POInitBuilder' : _POInitBuilder(env) } )
  93. env.AddMethod(_POInitBuilderWrapper, 'POInit')
  94. env.AlwaysBuild(env.Alias('$POCREATE_ALIAS'))
  95. #############################################################################
  96. #############################################################################
  97. def exists(env):
  98. """ Check if the tool exists """
  99. from SCons.Tool.GettextCommon import _msginit_exists
  100. try:
  101. return _msginit_exists(env)
  102. except:
  103. return False
  104. #############################################################################
  105. # Local Variables:
  106. # tab-width:4
  107. # indent-tabs-mode:nil
  108. # End:
  109. # vim: set expandtab tabstop=4 shiftwidth=4: