Commit Graph

82 Commits

Author SHA1 Message Date
Eli Schwartz 34da721ec2
gettext: explicitly pass source root / subdir as cli args
Because this is a wrapper script and we could/should do this, we even
have half the infra for it.
2022-05-29 18:23:03 -04:00
Eli Schwartz fdcc566590
i18n: don't let our maintainer targets run via wrapped env
They are RunTargets because they are one-shot commands without outputs.
But we implement them purely via our internal wrapper for gettext, so
there is no reason to wrap them *again* in our internal wrapper for
meson_exe and set a bunch of environment variables we know we absolutely
do not need, use, or want.

This avoids the ugly "wrapped due to env" status, and allows users to
directly see the command being run without going into despair at obscure
pickled nonsense.

It also offers a tiny defense against upgrading Meson without
reconfiguring. People should not do that, and we error out about this in
a bunch of places, but `--internal gettext` has a perfectly stable
interface just like most build tools that aren't part of Meson
internals, since it uses command line arguments instead of pickling.
2022-03-31 22:52:31 -04:00
Xavier Claessens e33ec88ac7 Pass environment down to base Target class 2022-03-29 16:10:28 -04:00
Eli Schwartz 8b573d7dc6
i18n.merge_file: do not disable in the absence of gettext tools
Disabling targets because the tools used to build them aren't available
is a pretty suspicious thing to do. Users who want this are probably, in
general, advised to check themselves whether it is possible to build
those targets with find_program(..., required: false)

The i18n.gettext() invocation is a bit unusual because the product of
running it is non-critical files, specifically, translation catalogs. If
users don't have the tools needed to build them, they may not be able to
use them either, because perhaps they have NLS disabled on their
platform or it's difficult to put it in the bootstrap path.

So, for this reason, it was made non-fatal and the message catalogs are
just not created, and the resulting build is still perfectly usable
*unless* you want to use it in another language, at which point it
"works" but the text is all inscrutable to the end user, and that's a
feature of the target platform.

That's an acceptable tradeoff for translation catalogs.

It is NOT an acceptable tradeoff for merge_file, which produces desktop
files or MIME database catalogs or other files which have crucial roles
to perform, without which the software in question simply doesn't work
at all. In such cases, this just fails to install crucial files, users
report bugs to the project in question, and the project adds
`find_program('xgettext')` to guarantee the hard error due to lack of
confidence in Meson.

Fixes #6165
Fixes #8436
2022-03-06 11:09:56 -05:00
Eli Schwartz 1f3640c7db
i18n module: report initial call site when disabling translation support 2022-03-06 11:09:56 -05:00
Eli Schwartz 08928821ec
i18n module: detect gettext tools at configure time
Use this instead of shutil.which to detect whether they will be
available, and pass the ExternalProgram object to CustomTarget
invocations, or else make use of the new functionality to specify the
correct program path in wrapper scripts.

Drop duplicate reporting for itstool missing. Since we use find_program
in required mode, its absence is already fatal, and already has a really
good error description.
2022-03-06 11:09:47 -05:00
Eli Schwartz e67fd1f551
i18n module: fix bug that made msgfmthelper die on combinations of args
Due to misuse of argparse in commit 82492f5d76
it was impossible to use both --datadirs and extra args passed directly
to msgfmt at the same time.

I'm not sure anyone actually knows how argparse works, so misusing it is
easy. What is definitely known is that argparse is NOT a POSIX compliant
parser and doesn't behave the way you'd expect a standards based parser
to handle options. Instead it caters to the easy use case, and hopes and
prays you don't need to do anything too complicated "with the wrong kind
of complicated".

Apparently, this particular type of complicated is when you have mixed
option_arguments and operands while simultaneously passing some operands
as nargs after a --.

It totally breaks, and interprets --datadirs, which is supposed to be an
option_argument, as an operand, eats it up as a msgfmt wrapped argument,
and breaks.

But if you don't pass additional arguments with -- then it interprets
--datadirs after operands as an option_argument. This is what we were
doing.

Instead pass option_arguments before all operands (including the ones
specified via `-- ...`). Add test case to pass meaningless datadirs (we
don't actually care if $GETTEXTDATADIRS is set to something that doesn't
contain gettext data).
2022-03-06 10:48:34 -05:00
Dylan Baker 11f9638035 build: replace kwargs in CustomTarget initializer
Because we don't want to pass the Interpreter kwargs into the build
layer. This turned out to be a mega commit, as there's really on elegant
way to make this change in an incremental way. On the nice side, mypy
made this change super easy, as nearly all of the calls to
`CustomTarget` are fully type checked!

It also turns out that we're not handling install_tags in custom_target
correctly, since we're not converting the boolean values into Optional
values!
2022-01-28 15:53:20 -05:00
Eli Schwartz 3990dc6d64 flake8: fix indentation style 2022-01-27 10:48:01 -08:00
Eli Schwartz 603244b059
fix broken version annotations for the new itstool_join feature
It was not added in 0.61.0 as that was already released.
2022-01-22 22:11:32 -05:00
Matthias Klumpp 02fb0c3f8b i18n: Add support for joining XML localization via itstool 2022-01-21 22:26:17 +01:00
Matthias Klumpp efd7c7f228 i18n: Fix typo for typed_pos_args 2021-12-18 04:43:19 +01:00
Eli Schwartz 172fa4d3b2
i18n module: correctly annotate the availability of data_dirs
It was originally forgotten in merge_file() and later added for parity
with gettext(). This means that the FeatureNew for each function is
different.
2021-12-02 12:29:58 -05:00
Xavier Claessens 018d928cf5 i18n: Fix backtrace when missing input kwarg
When input kwarg is missing in i18n.merge_file() it was crashing with a
backtrace because of kwargs['input'][0]. That code was useless anyway
because CustomTarget now uses first output as default name which is what
we need here.
2021-11-16 23:35:46 -05:00
Eli Schwartz d06cc042eb
f-strings 2021-10-04 16:29:32 -04:00
Dan Streetman 3c2cca5699 modules/i18n: fix gettext use of --datadirs param
The previous commit bd2fcb268b
accidentally used the wrong var so the param name was missing,
leading to an error of "unrecognized arguments" for the
datadirs parameter value.
2021-10-03 16:23:46 -04:00
Dylan Baker bd2fcb268b modules/i18n: Fix remaining mypy spotted issues 2021-09-30 16:09:14 -07:00
Dylan Baker 6399544e4c modules/i18n: use typed_kwargs for gettext
There were two allowed kwargs that were unused, I've dropped them for
now, though I need to check if they were documented. If they are then we
need to deprecate them to remove them, otherwise we'll just leave them
removed.
2021-09-30 16:09:14 -07:00
Dylan Baker 6b1a80024c modules/i18n: Use typed_kwargs for merge_file 2021-09-30 16:09:14 -07:00
Dylan Baker 61f2866a9f modules/i18n: use typed_pos_args 2021-09-30 16:09:14 -07:00
Dylan Baker b923163109 modules/i18n: add easy type annotations 2021-09-30 16:09:14 -07:00
Dylan Baker 57d0d4e95a modules/i18n: sort and clean up imports 2021-09-30 16:09:14 -07:00
Eli Schwartz 1dbb6d6b8c
make the display name of a gettext translation build, look prettier
And more accurate too, TBH. Currently it says it is building "lang.mo",
even though it is actually building "domain.mo" inside
lang/LC_MESSAGES/.

Since meson loudly complains if I try to name the display name
"lang/domain.mo", name it with a dash instead of a slash. The actual
name isn't a priority here IMO, and this is nicely readable.
2021-09-01 21:18:44 -04:00
Eli Schwartz 22c38a0006
i18n module: restore the <packagename>-gmo target
Removed in commit 487d45c1e5 but perhaps
it should not have -- people may have been depending on ensuring those
are built somehow. Even though the internal implementation changed and
it is now built by the all target, let's keep the old target around too.

Now it just aliases the actual build rules, though.
2021-08-31 23:37:33 -04:00
Eli Schwartz 2fc7592e13
i18n module: provide targets as return value for gettext()
Users may wish to make use of these files for their own purposes.

For example, the -pot and -update-po pseudo targets could be reused in
an alias_target(), and at least one person wanted to reuse the built .mo
files as custom_target input.

Fixes #6227
2021-08-31 23:37:33 -04:00
Xavier Claessens 8c5aa031b5 Add install tags
Fixes: #7007.
2021-08-17 15:19:18 -04:00
Xavier Claessens 223991c09e Fix i18n target name when using @BASENAME@ and configure_file() input
Fixes: #9022
2021-08-09 19:43:45 -04:00
Eli Schwartz 487d45c1e5
i18n: use real build/install targets for gmo files
Don't just create a .PHONY target which runs a script that magically
generates files ninja doesn't know about. It results in untracked files,
and `meson install` has to run additional commands instead of copying
over files, and then cannot track them to uninstall them later.

I'm not even really sure why it was originally done via a proxy script,
most likely bad legacy design. This is after all one of the oldest
modules...

One side effect of this is that meson doesn't know how to rename
build.CustomTarget files on install (only data files are supported?),
and every file needs to be installed as "domainname.mo" so it must be
named that in-tree too. To prevent clashes, every locale gets its own
locale-specific subdirectory.

Once we are doing that anyway, we can output them to the actual
structure required by the gettext family of functions, and
bindtextdomain() can therefore point to this location if desired. This
might be useful for running localized programs from the build tree.
2021-08-09 18:25:17 -04:00
Daniel Mensinger 34c28dc92c holders: remove unholder 2021-06-18 23:48:33 +02:00
Xavier Claessens 2e02ef6592 modules: Add methods dict everywhere
This fix calling random internal methods from meson.build as long as
they were not prefixed by underscore.
2021-05-28 15:17:10 -04:00
Xavier Claessens a734bcfc83 modules: Stop using ModuleReturnValue where it's not needed
It is only needed in functions that need to add targets to the
interpreter.
2021-05-28 15:17:10 -04:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Xavier Claessens 522392e755 run_target: Add env kwarg
Re-implement it in backend using the same code path as for
custom_target(). This for example handle setting PATH on Windows when
command is an executable.
2021-02-05 17:53:09 -05:00
Xavier Claessens 0626465ea8 Fix executable as script on Windows
On Windows this would fail because of missing DLL:
```
mylib = library(...)
exe = executable(..., link_with: mylib)
meson.add_install_script(exe)
```

The reason is on Windows we cannot rely on rpath to find libraries from
build directory, they are searched in $PATH. We already have all that
mechanism in place for custom_target() using ExecutableSerialisation
class, so reuse it for install/dist/postconf scripts too.

This has bonus side effect to also use exe_wrapper for those scripts.

Fixes: #8187
2021-01-30 09:51:06 +00:00
Dylan Baker e81acbd606 Use a single coredata dictionary for options
This patches takes the options work to it's logical conclusion: A single
flat dictionary of OptionKey: UserOptions. This allows us to simplify a
large number of cases, as we don't need to check if an option is in this
dict or that one (or any of 5 or 6, actually).
2021-01-04 12:20:58 -08:00
Dylan Baker b231ff36df Remove some uses of mesonlib.run_once
These are basically doing what mlog.log(..., once=True) does, so lets
just use that. The once argument to mlog is newer, so these probably
should have been changed already.
2020-03-05 09:31:29 -08:00
Zbigniew Jędrzejewski-Szmek 3a6920ebdc Add helper to print warnings once
The helper is general, although in this patch it is only used for
warnings. No functional change intended.
2019-09-25 14:52:07 +02:00
Jussi Pakkanen 5f2e44b0dd Make gettext targets no-ops if gettext is not installed. Closes: #821. 2019-08-04 21:46:52 +03:00
Konstantin 841995cddf i18n: add args keyword to merge_file
* i18n: add args keyword to merge_file

* i18n: add testcase to msgfmt args
2019-04-22 14:54:05 +03:00
Georges Basile Stavracas Neto 5f00c30200 i18n: Use CustomTarget.known_kwargs at permittedKwargs()
@permittedKwargs() is basically copying the logic of CustomTarget,
but it is not actually up to date, leading to warnings on perfectly
valid values such as 'build_by_default'.

Use CustomTarget.known_kwargs instead, and only append the specific
kwargs of i18n.merge_file().

Fixes https://github.com/mesonbuild/meson/issues/5079
2019-03-14 05:14:29 +00:00
Frediano Ziglio 683c768fed i18n: Catch additional GLib functions
Add some missing functions having C-format strings to the list.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-02-16 15:00:06 +02:00
Sergey Shatunov c07e5124bc Add install_dir to i18n.gettext 2019-01-26 23:29:05 +02:00
Jussi Pakkanen fe3efe0bc6 Fix merge file using an array. Closes #4424. 2018-10-29 23:33:21 +02:00
Jon Turney 99b0a7acda Fix flake8 whitespace reports
$ flake8 | grep -E '(E128|E203|E221|E226|E303|W291|W293)'
./mesonbuild/backend/backends.py:32:1: E303 too many blank lines (3)
./mesonbuild/modules/i18n.py:90:56: E128 continuation line under-indented for visual indent
2018-10-24 19:11:46 +03:00
Marty E. Plummer 8fd5297f76 i18n: replace path separator with @
using state.subdir will cause / or \ to be inserted into the target name.
Replace them with @ to future-proof it.

Signed-off-by: Marty E. Plummer <hanetzer@startmail.com>
2018-10-06 03:10:11 -07:00
Jussi Pakkanen 2ff69b20df Fix handling generated .desktop files. Closes #4304. 2018-10-05 00:48:22 +03:00
Marty E. Plummer add55bb861 i18n: allow custom target names for merge_file
As it currently stands, if for whatever reason you have two files you
want to merge with the same output name, it will fail due to multiple
targets with the same name due to the target name being autogenerated
from the output kwarg.

Signed-off-by: Marty E. Plummer <hanetzer@startmail.com>
2018-09-16 15:08:43 +03:00
Corentin Noël 176af2c8c3 i18n: respect variable substitution for the target name when merging translations
Previously it wasn't possible to use twice @BASENAME@ as the targets would then be named @BASENAME@_merge
2018-09-03 22:34:22 -07:00
Salamandar accea4889b Add 0.37.0 features 2018-06-01 14:23:24 +02:00
Jussi Pakkanen 998892ed29 Updated all modules to work with the new API. 2018-04-15 13:32:38 +05:30