Skip to content

Commit f6918fe

Browse files
committed
mesonmain: mark getting a language from another subproject as broken
Currently, you can call `meson.get_compiler('c')`, if you haven't initialized 'c' for your project, but a super-project has initialized it. This happens because we check the wrong set of compilers (the global list vs the per-subproject one). Because of how fragile this is, we can mark it as broken an move on.
1 parent 79854e4 commit f6918fe

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Using `meson.get_compiler()` to get a language from another project is marked broken
2+
3+
Meson currently will return a compiler instance from the `meson.get_compiler()`
4+
call, if that language has been initialized in any project. This can result in
5+
situations where a project can only work as a subproject, or if a dependency is
6+
provided by a subproject rather than by a pre-built dependency.

mesonbuild/interpreter/mesonmain.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ..options import OptionKey
1717
from ..programs import OverrideProgram, ExternalProgram
1818
from ..interpreter.type_checking import ENV_KW, ENV_METHOD_KW, ENV_SEPARATOR_KW, env_convertor_with_method
19-
from ..interpreterbase import (MesonInterpreterObject, FeatureNew, FeatureDeprecated,
19+
from ..interpreterbase import (MesonInterpreterObject, FeatureNew, FeatureDeprecated, FeatureBroken,
2020
typed_pos_args, noArgsFlattening, noPosargs, noKwargs,
2121
typed_kwargs, KwargInfo, InterpreterException, InterpreterObject)
2222
from .primitives import MesonVersionString
@@ -285,13 +285,19 @@ def is_cross_build_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs')
285285
@typed_kwargs('meson.get_compiler', NATIVE_KW)
286286
@InterpreterObject.method('get_compiler')
287287
def get_compiler_method(self, args: T.Tuple[str], kwargs: 'NativeKW') -> 'Compiler':
288-
cname = args[0]
288+
lang = args[0]
289289
for_machine = kwargs['native']
290-
clist = self.interpreter.coredata.compilers[for_machine]
291290
try:
292-
return clist[cname]
291+
return self.interpreter.compilers[for_machine][lang]
293292
except KeyError:
294-
raise InterpreterException(f'Tried to access compiler for language "{cname}", not specified for {for_machine.get_lower_case_name()} machine.')
293+
try:
294+
comp = self.interpreter.coredata.compilers[for_machine][lang]
295+
except KeyError:
296+
raise InterpreterException(f'Tried to access compiler for language "{lang}", not specified for {for_machine.get_lower_case_name()} machine.')
297+
298+
FeatureBroken.single_use('Using `meson.get_compiler()` for languages only initialized in another subproject', '1.11.0', self.subproject,
299+
'This is extremely fragile, as your project likely cannot be used outside of your environment.')
300+
return comp
295301

296302
@noPosargs
297303
@noKwargs

0 commit comments

Comments
 (0)