renamed SCons.Tool.ninja -> SCons.Tool.ninja_tool and added alias in tool loading...
[scons.git] / SCons / Tool / msgmerge.py
blob292e75d6db2215b536e5965fd8a547012bd35472
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 """Tool specific initialization for `msgmerge` tool."""
26 import sys
27 import os
29 import SCons.Action
30 import SCons.Tool
31 import SCons.Warnings
32 from SCons.Errors import StopError
33 from SCons.Platform.cygwin import CYGWIN_DEFAULT_PATHS
34 from SCons.Platform.mingw import MINGW_DEFAULT_PATHS
35 from SCons.Tool.GettextCommon import (
36 _detect_msgmerge,
37 _init_po_files,
38 _msgmerge_exists,
39 # MsgmergeToolWarning,
40 _POFileBuilder,
43 def _update_or_init_po_files(target, source, env):
44 """ Action function for `POUpdate` builder """
46 for tgt in target:
47 if tgt.rexists():
48 action = SCons.Action.Action('$MSGMERGECOM', '$MSGMERGECOMSTR')
49 else:
50 action = _init_po_files
51 status = action([tgt], source, env)
52 if status:
53 return status
54 return 0
57 def _POUpdateBuilder(env, **kw):
58 """ Create an object of `POUpdate` builder """
60 action = SCons.Action.Action(_update_or_init_po_files, None)
61 return _POFileBuilder(env, action=action, target_alias='$POUPDATE_ALIAS')
64 from SCons.Environment import _null
67 def _POUpdateBuilderWrapper(env, target=None, source=_null, **kw):
68 """ Wrapper for `POUpdate` builder - make user's life easier """
69 if source is _null:
70 if 'POTDOMAIN' in kw:
71 domain = kw['POTDOMAIN']
72 elif 'POTDOMAIN' in env and env['POTDOMAIN']:
73 domain = env['POTDOMAIN']
74 else:
75 domain = 'messages'
76 source = [domain] # NOTE: Suffix shall be appended automatically
77 return env._POUpdateBuilder(target, source, **kw)
80 def generate(env, **kw) -> None:
81 """ Generate the `msgmerge` tool """
83 if sys.platform == 'win32':
84 msgmerge = SCons.Tool.find_program_path(
85 env, 'msgmerge', default_paths=MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS
87 if msgmerge:
88 msgmerge_bin_dir = os.path.dirname(msgmerge)
89 env.AppendENVPath('PATH', msgmerge_bin_dir)
90 else:
91 SCons.Warnings.warn(
92 # MsgmergeToolWarning, # using this breaks test, so keep:
93 SCons.Warnings.SConsWarning,
94 'msgmerge tool requested, but binary not found in ENV PATH',
96 try:
97 env['MSGMERGE'] = _detect_msgmerge(env)
98 except StopError:
99 env['MSGMERGE'] = 'msgmerge'
100 env.SetDefault(
101 POTSUFFIX=['.pot'],
102 POSUFFIX=['.po'],
103 MSGMERGECOM='$MSGMERGE $MSGMERGEFLAGS --update $TARGET $SOURCE',
104 MSGMERGECOMSTR='',
105 MSGMERGEFLAGS=[],
106 POUPDATE_ALIAS='po-update',
108 env.Append(BUILDERS={'_POUpdateBuilder': _POUpdateBuilder(env)})
109 env.AddMethod(_POUpdateBuilderWrapper, 'POUpdate')
110 env.AlwaysBuild(env.Alias('$POUPDATE_ALIAS'))
113 def exists(env):
114 """ Check if the tool exists """
116 try:
117 return _msgmerge_exists(env)
118 except StopError:
119 return False
121 # Local Variables:
122 # tab-width:4
123 # indent-tabs-mode:nil
124 # End:
125 # vim: set expandtab tabstop=4 shiftwidth=4: