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 of msginit tool."""
33 from SCons
.Environment
import _null
34 from SCons
.Errors
import StopError
35 from SCons
.Platform
.cygwin
import CYGWIN_DEFAULT_PATHS
36 from SCons
.Platform
.mingw
import MINGW_DEFAULT_PATHS
37 from SCons
.Tool
.GettextCommon
import (
46 def _optional_no_translator_flag(env
):
47 """Return '--no-translator' flag if we run *msginit(1)* in non-interactive
49 if 'POAUTOINIT' in env
:
50 autoinit
= env
['POAUTOINIT']
54 return [SCons
.Util
.CLVar('--no-translator')]
56 return [SCons
.Util
.CLVar('')]
59 def _POInitBuilder(env
, **kw
):
60 """ Create builder object for `POInit` builder. """
62 action
= SCons
.Action
.Action(_init_po_files
, None)
63 return _POFileBuilder(env
, action
=action
, target_alias
='$POCREATE_ALIAS')
66 def _POInitBuilderWrapper(env
, target
=None, source
=_null
, **kw
):
67 """Wrapper for _POFileBuilder. We use it to make user's life easier.
69 This wrapper checks for `$POTDOMAIN` construction variable (or override in
70 `**kw`) and treats it appropriatelly.
74 domain
= kw
['POTDOMAIN']
75 elif 'POTDOMAIN' in env
:
76 domain
= env
['POTDOMAIN']
79 source
= [domain
] # NOTE: Suffix shall be appended automatically
80 return env
._POInitBuilder
(target
, source
, **kw
)
82 def generate(env
, **kw
) -> None:
83 """ Generate the `msginit` tool """
85 if sys
.platform
== 'win32':
86 msginit
= SCons
.Tool
.find_program_path(
87 env
, 'msginit', default_paths
=MINGW_DEFAULT_PATHS
+ CYGWIN_DEFAULT_PATHS
90 msginit_bin_dir
= os
.path
.dirname(msginit
)
91 env
.AppendENVPath('PATH', msginit_bin_dir
)
94 # MsginitToolWarning, # using this breaks test, so keep:
95 SCons
.Warnings
.SConsWarning
,
96 'msginit tool requested, but binary not found in ENV PATH',
100 env
['MSGINIT'] = _detect_msginit(env
)
102 env
['MSGINIT'] = 'msginit'
104 '$MSGINIT ${_MSGNoTranslator(__env__)} -l ${_MSGINITLOCALE}'
105 + ' $MSGINITFLAGS -i $SOURCE -o $TARGET'
107 # NOTE: We set POTSUFFIX here, in case the 'xgettext' is not loaded
108 # (sometimes we really don't need it)
112 _MSGINITLOCALE
='${TARGET.filebase}',
113 _MSGNoTranslator
=_optional_no_translator_flag
,
114 MSGINITCOM
=msginitcom
,
118 POCREATE_ALIAS
='po-create',
120 env
.Append(BUILDERS
={'_POInitBuilder': _POInitBuilder(env
)})
121 env
.AddMethod(_POInitBuilderWrapper
, 'POInit')
122 env
.AlwaysBuild(env
.Alias('$POCREATE_ALIAS'))
126 """ Check if the tool exists """
129 return _msginit_exists(env
)
135 # indent-tabs-mode:nil
137 # vim: set expandtab tabstop=4 shiftwidth=4: