summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2025-09-30 12:10:55 -0400
committerDylan Baker <dylan@pnwbakers.com>2025-10-01 11:29:59 -0700
commit098dc533d659a9ee6e987d46dfcd918bfb133ca3 (patch)
tree9bf1f81d4f21c4c859083d7105aaf2c067d077b6
parentc0a5e9293209f465ab114ae0fcd92de640ef48a6 (diff)
downloadmeson-098dc533d659a9ee6e987d46dfcd918bfb133ca3.tar.gz
Allow CustomTarget source for i18n.xgettext
Fixes #15054
-rw-r--r--docs/markdown/i18n-module.md5
-rw-r--r--docs/markdown/snippets/xgettext-custom-tgt.md7
-rw-r--r--mesonbuild/modules/i18n.py11
-rw-r--r--test cases/frameworks/38 gettext extractor/src/lib3/foo.c0
-rw-r--r--test cases/frameworks/38 gettext extractor/src/lib3/meson.build4
-rw-r--r--test cases/frameworks/38 gettext extractor/src/meson.build1
6 files changed, 25 insertions, 3 deletions
diff --git a/docs/markdown/i18n-module.md b/docs/markdown/i18n-module.md
index ac6146dd5..6cdd74a28 100644
--- a/docs/markdown/i18n-module.md
+++ b/docs/markdown/i18n-module.md
@@ -90,7 +90,7 @@ for each executable.
Positional arguments are the following:
* name `str`: the name of the resulting pot file.
-* sources `array[str|File|build_tgt|custom_tgt]`:
+* sources `array[str|File|build_tgt|custom_tgt|custom_idx]`:
source files or targets. May be a list of `string`, `File`, [[@build_tgt]],
or [[@custom_tgt]] returned from other calls to this function.
@@ -120,4 +120,7 @@ included to generate the final pot file. Therefore, adding a dependency to
source target will automatically add the translations of that dependency to the
needed translations for that source target.
+*New in 1.10.0* sources can be result of [[@custom_tgt]] or [[@custom_idx]].
+Before 1.10.0, custom targets were silently ignored.
+
*Added 1.8.0*
diff --git a/docs/markdown/snippets/xgettext-custom-tgt.md b/docs/markdown/snippets/xgettext-custom-tgt.md
new file mode 100644
index 000000000..37ec43823
--- /dev/null
+++ b/docs/markdown/snippets/xgettext-custom-tgt.md
@@ -0,0 +1,7 @@
+## `i18n.xgettext` now accepts CustomTarget and CustomTargetIndex as sources
+
+Previously, [[@custom_tgt]] were accepted but silently ignored, and
+[[@custom_idx]] were not accepted.
+
+Now, they both can be used, and the generated outputs will be scanned to extract
+translation strings.
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
index 87baab203..8b8306584 100644
--- a/mesonbuild/modules/i18n.py
+++ b/mesonbuild/modules/i18n.py
@@ -75,7 +75,7 @@ if T.TYPE_CHECKING:
install_dir: T.Optional[str]
install_tag: T.Optional[str]
- SourcesType = T.Union[str, mesonlib.File, build.BuildTarget, build.BothLibraries, build.CustomTarget]
+ SourcesType = T.Union[str, mesonlib.File, build.BuildTarget, build.BothLibraries, build.CustomTarget, build.CustomTargetIndex]
_ARGS: KwargInfo[T.List[str]] = KwargInfo(
@@ -202,6 +202,8 @@ class XgettextProgram:
source_files.update(source.get_sources())
elif isinstance(source, build.BothLibraries):
source_files.update(source.get('shared').get_sources())
+ elif isinstance(source, (build.CustomTarget, build.CustomTargetIndex)):
+ source_files.update(mesonlib.File.from_built_file(source.get_subdir(), f) for f in source.get_outputs())
return source_files
def _get_depends(self, sources: T.Iterable[SourcesType]) -> T.Set[build.CustomTarget]:
@@ -531,7 +533,7 @@ class I18nModule(ExtensionModule):
return ModuleReturnValue(ct, [ct])
@FeatureNew('i18n.xgettext', '1.8.0')
- @typed_pos_args('i18n.xgettext', str, varargs=(str, mesonlib.File, build.BuildTarget, build.BothLibraries, build.CustomTarget), min_varargs=1)
+ @typed_pos_args('i18n.xgettext', str, varargs=(str, mesonlib.File, build.BuildTarget, build.BothLibraries, build.CustomTarget, build.CustomTargetIndex), min_varargs=1)
@typed_kwargs(
'i18n.xgettext',
_ARGS,
@@ -541,6 +543,11 @@ class I18nModule(ExtensionModule):
INSTALL_TAG_KW,
)
def xgettext(self, state: ModuleState, args: T.Tuple[str, T.List[SourcesType]], kwargs: XgettextProgramT) -> build.CustomTarget:
+ if any(isinstance(a, build.CustomTarget) for a in args[1]):
+ FeatureNew.single_use('i18n.xgettext with custom_target is broken until 1.10', '1.10.0', self.interpreter.subproject, location=self.interpreter.current_node)
+ if any(isinstance(a, build.CustomTargetIndex) for a in args[1]):
+ FeatureNew.single_use('i18n.xgettext with custom_target index', '1.10.0', self.interpreter.subproject, location=self.interpreter.current_node)
+
toolname = 'xgettext'
if self.tools[toolname] is None or not self.tools[toolname].found():
self.tools[toolname] = state.find_program(toolname, required=True, for_machine=mesonlib.MachineChoice.BUILD)
diff --git a/test cases/frameworks/38 gettext extractor/src/lib3/foo.c b/test cases/frameworks/38 gettext extractor/src/lib3/foo.c
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test cases/frameworks/38 gettext extractor/src/lib3/foo.c
diff --git a/test cases/frameworks/38 gettext extractor/src/lib3/meson.build b/test cases/frameworks/38 gettext extractor/src/lib3/meson.build
new file mode 100644
index 000000000..34afeeb4a
--- /dev/null
+++ b/test cases/frameworks/38 gettext extractor/src/lib3/meson.build
@@ -0,0 +1,4 @@
+fs = import('fs')
+
+foo = fs.copyfile('foo.c')
+i18n.xgettext('test', foo[0])
diff --git a/test cases/frameworks/38 gettext extractor/src/meson.build b/test cases/frameworks/38 gettext extractor/src/meson.build
index 27fc81326..b26646c1a 100644
--- a/test cases/frameworks/38 gettext extractor/src/meson.build
+++ b/test cases/frameworks/38 gettext extractor/src/meson.build
@@ -1,5 +1,6 @@
subdir('lib1')
subdir('lib2')
+subdir('lib3')
main = executable('say', 'main.c', link_with: [lib2], include_directories: lib2_includes)