diff options
| author | Andrew McNulty <amcn@users.noreply.github.com> | 2025-04-09 18:13:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-09 09:13:39 -0700 |
| commit | f23b0e7f35661645b7fec82025e72dffa189ab59 (patch) | |
| tree | 24725595e179c525e71acd2cc662c23084c365f2 | |
| parent | 1afdac1bc4cbf9816e7109bbedef2825c4fe1155 (diff) | |
| download | meson-f23b0e7f35661645b7fec82025e72dffa189ab59.tar.gz | |
interpreter: Error if java sources used with non-jar target (#14424)
If the user specifies java sources as input to a non-jar build
target, raise an error with a message directing them to use the jar
target instead.
Fixes: https://github.com/mesonbuild/meson/issues/13870
6 files changed, 26 insertions, 0 deletions
diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index 116b3fa7a..aab761af4 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -19,6 +19,7 @@ __all__ = [ 'is_llvm_ir', 'is_object', 'is_source', + 'is_java', 'is_known_suffix', 'lang_suffixes', 'LANGUAGES_USING_LDFLAGS', @@ -55,6 +56,7 @@ from .compilers import ( get_base_link_args, is_header, is_source, + is_java, is_assembly, is_llvm_ir, is_object, diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index a3b243dd9..3c1d58b4e 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -148,6 +148,12 @@ def is_assembly(fname: 'mesonlib.FileOrString') -> bool: suffix = fname.split('.')[-1] return suffix in assembler_suffixes +def is_java(fname: mesonlib.FileOrString) -> bool: + if isinstance(fname, mesonlib.File): + fname = fname.fname + suffix = fname.split('.')[-1] + return suffix in lang_suffixes['java'] + def is_llvm_ir(fname: 'mesonlib.FileOrString') -> bool: if isinstance(fname, mesonlib.File): fname = fname.fname diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index dedd20c82..2cd272db3 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -3390,6 +3390,7 @@ class Interpreter(InterpreterBase, HoldableObject): kwargs['language_args'][lang].extend(args) kwargs['depend_files'].extend(deps) if targetclass is not build.Jar: + self.check_for_jar_sources(sources, targetclass) kwargs['d_import_dirs'] = self.extract_incdirs(kwargs, 'd_import_dirs') # Filter out kwargs from other target types. For example 'soversion' @@ -3479,6 +3480,13 @@ class Interpreter(InterpreterBase, HoldableObject): if not os.path.isfile(fname): raise InterpreterException(f'Tried to add non-existing source file {s}.') + def check_for_jar_sources(self, sources, targetclass): + for s in sources: + if isinstance(s, (str, mesonlib.File)) and compilers.is_java(s): + raise InvalidArguments(f'Build target of type "{targetclass.typename}" cannot build java source: "{s}". Use "{build.Jar.typename}" instead.') + elif isinstance(s, build.StructuredSources): + self.check_for_jar_sources(s.as_list(), targetclass) + # Only permit object extraction from the same subproject def validate_extraction(self, buildtarget: mesonlib.HoldableObject) -> None: if self.subproject != buildtarget.subproject: diff --git a/test cases/failing/134 java sources in non jar target/Test.java b/test cases/failing/134 java sources in non jar target/Test.java new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/test cases/failing/134 java sources in non jar target/Test.java diff --git a/test cases/failing/134 java sources in non jar target/meson.build b/test cases/failing/134 java sources in non jar target/meson.build new file mode 100644 index 000000000..0aa802a48 --- /dev/null +++ b/test cases/failing/134 java sources in non jar target/meson.build @@ -0,0 +1,3 @@ +# https://github.com/mesonbuild/meson/issues/13870 +project('134 java sources in non jar target') +executable('Test.jar', 'Test.java') diff --git a/test cases/failing/134 java sources in non jar target/test.json b/test cases/failing/134 java sources in non jar target/test.json new file mode 100644 index 000000000..271ac36af --- /dev/null +++ b/test cases/failing/134 java sources in non jar target/test.json @@ -0,0 +1,7 @@ +{ + "stdout": [ + { + "line": "test cases/failing/134 java sources in non jar target/meson.build:3:0: ERROR: Build target of type \"executable\" cannot build java source: \"Test.java\". Use \"jar\" instead." + } + ] +} |
