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."""
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 (
39 # MsgmergeToolWarning,
43 def _update_or_init_po_files(target
, source
, env
):
44 """ Action function for `POUpdate` builder """
48 action
= SCons
.Action
.Action('$MSGMERGECOM', '$MSGMERGECOMSTR')
50 action
= _init_po_files
51 status
= action([tgt
], source
, env
)
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 """
71 domain
= kw
['POTDOMAIN']
72 elif 'POTDOMAIN' in env
and env
['POTDOMAIN']:
73 domain
= env
['POTDOMAIN']
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
88 msgmerge_bin_dir
= os
.path
.dirname(msgmerge
)
89 env
.AppendENVPath('PATH', msgmerge_bin_dir
)
92 # MsgmergeToolWarning, # using this breaks test, so keep:
93 SCons
.Warnings
.SConsWarning
,
94 'msgmerge tool requested, but binary not found in ENV PATH',
97 env
['MSGMERGE'] = _detect_msgmerge(env
)
99 env
['MSGMERGE'] = 'msgmerge'
103 MSGMERGECOM
='$MSGMERGE $MSGMERGEFLAGS --update $TARGET $SOURCE',
106 POUPDATE_ALIAS
='po-update',
108 env
.Append(BUILDERS
={'_POUpdateBuilder': _POUpdateBuilder(env
)})
109 env
.AddMethod(_POUpdateBuilderWrapper
, 'POUpdate')
110 env
.AlwaysBuild(env
.Alias('$POUPDATE_ALIAS'))
114 """ Check if the tool exists """
117 return _msgmerge_exists(env
)
123 # indent-tabs-mode:nil
125 # vim: set expandtab tabstop=4 shiftwidth=4: