interpreter: move handling of module stability to interpreter
Thanks to `ModuleInfo`, all modules are just named `foo.py` instead of `unstable_foo.py`, which simplifies the import method a bit. This also allows for accurate FeatureNew/FeatureDeprecated use, as we know when the module was added and if/when it was stabilized.
This commit is contained in:
parent
c32f83a829
commit
a78992dd81
|
@ -599,26 +599,6 @@ class Interpreter(InterpreterBase, HoldableObject):
|
|||
dep = df.lookup(kwargs, force_fallback=True)
|
||||
self.build.stdlibs[for_machine][l] = dep
|
||||
|
||||
def _import_module(self, modname: str, required: bool, node: mparser.BaseNode) -> NewExtensionModule:
|
||||
if modname in self.modules:
|
||||
return self.modules[modname]
|
||||
try:
|
||||
module = importlib.import_module('mesonbuild.modules.' + modname)
|
||||
except ImportError:
|
||||
if required:
|
||||
raise InvalidArguments(f'Module "{modname}" does not exist')
|
||||
ext_module = NotFoundExtensionModule(modname)
|
||||
else:
|
||||
ext_module = module.initialize(self)
|
||||
assert isinstance(ext_module, (ExtensionModule, NewExtensionModule))
|
||||
self.build.modules.append(modname)
|
||||
if ext_module.INFO.added:
|
||||
FeatureNew.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.added, self.subproject, location=node)
|
||||
if ext_module.INFO.deprecated:
|
||||
FeatureDeprecated.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.deprecated, self.subproject, location=node)
|
||||
self.modules[modname] = ext_module
|
||||
return ext_module
|
||||
|
||||
@typed_pos_args('import', str)
|
||||
@typed_kwargs(
|
||||
'import',
|
||||
|
@ -633,17 +613,56 @@ class Interpreter(InterpreterBase, HoldableObject):
|
|||
if disabled:
|
||||
return NotFoundExtensionModule(modname)
|
||||
|
||||
if modname.startswith('unstable-'):
|
||||
plainname = modname.split('-', 1)[1]
|
||||
try:
|
||||
# check if stable module exists
|
||||
mod = self._import_module(plainname, required, node)
|
||||
mlog.warning(f'Module {modname} is now stable, please use the {plainname} module instead.')
|
||||
return mod
|
||||
except InvalidArguments:
|
||||
mlog.warning(f'Module {modname} has no backwards or forwards compatibility and might not exist in future releases.', location=node)
|
||||
modname = 'unstable_' + plainname
|
||||
return self._import_module(modname, required, node)
|
||||
expect_unstable = False
|
||||
# Some tests use "unstable_" instead of "unstable-", and that happens to work because
|
||||
# of implementation details
|
||||
if modname.startswith(('unstable-', 'unstable_')):
|
||||
real_modname = modname[len('unstable') + 1:] # + 1 to handle the - or _
|
||||
expect_unstable = True
|
||||
else:
|
||||
real_modname = modname
|
||||
|
||||
if real_modname in self.modules:
|
||||
return self.modules[real_modname]
|
||||
try:
|
||||
module = importlib.import_module(f'mesonbuild.modules.{real_modname}')
|
||||
except ImportError:
|
||||
if required:
|
||||
raise InvalidArguments(f'Module "{modname}" does not exist')
|
||||
ext_module = NotFoundExtensionModule(real_modname)
|
||||
else:
|
||||
ext_module = module.initialize(self)
|
||||
assert isinstance(ext_module, (ExtensionModule, NewExtensionModule))
|
||||
self.build.modules.append(real_modname)
|
||||
if ext_module.INFO.added:
|
||||
FeatureNew.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.added, self.subproject, location=node)
|
||||
if ext_module.INFO.deprecated:
|
||||
FeatureDeprecated.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.deprecated, self.subproject, location=node)
|
||||
if expect_unstable and not ext_module.INFO.unstable and ext_module.INFO.stabilized is None:
|
||||
raise InvalidArguments(f'Module {ext_module.INFO.name} has never been unstable, remove "unstable-" prefix.')
|
||||
if ext_module.INFO.stabilized is not None:
|
||||
if expect_unstable:
|
||||
FeatureDeprecated.single_use(
|
||||
f'module {ext_module.INFO.name} has been stabilized',
|
||||
ext_module.INFO.stabilized, self.subproject,
|
||||
'drop "unstable-" prefix from the module name',
|
||||
location=node)
|
||||
else:
|
||||
FeatureNew.single_use(
|
||||
f'module {ext_module.INFO.name} as stable module',
|
||||
ext_module.INFO.stabilized, self.subproject,
|
||||
f'Consider either adding "unstable-" to the module name, or updating the meson required version to ">= {ext_module.INFO.stabilized}"',
|
||||
location=node)
|
||||
elif ext_module.INFO.unstable:
|
||||
if not expect_unstable:
|
||||
if required:
|
||||
raise InvalidArguments(f'Module "{ext_module.INFO.name}" has not been stabilized, and must be imported as unstable-{ext_module.INFO.name}')
|
||||
ext_module = NotFoundExtensionModule(real_modname)
|
||||
else:
|
||||
mlog.warning(f'Module {ext_module.INFO.name} has no backwards or forwards compatibility and might not exist in future releases.', location=node)
|
||||
|
||||
self.modules[real_modname] = ext_module
|
||||
return ext_module
|
||||
|
||||
@typed_pos_args('files', varargs=str)
|
||||
@noKwargs
|
||||
|
|
|
@ -40,18 +40,18 @@ modules = [
|
|||
'mesonbuild/mintro.py',
|
||||
'mesonbuild/mlog.py',
|
||||
'mesonbuild/msubprojects.py',
|
||||
'mesonbuild/modules/external_project.py',
|
||||
'mesonbuild/modules/fs.py',
|
||||
'mesonbuild/modules/gnome.py',
|
||||
'mesonbuild/modules/i18n.py',
|
||||
'mesonbuild/modules/icestorm.py',
|
||||
'mesonbuild/modules/java.py',
|
||||
'mesonbuild/modules/keyval.py',
|
||||
'mesonbuild/modules/modtest.py',
|
||||
'mesonbuild/modules/qt.py',
|
||||
'mesonbuild/modules/rust.py',
|
||||
'mesonbuild/modules/sourceset.py',
|
||||
'mesonbuild/modules/unstable_external_project.py',
|
||||
'mesonbuild/modules/unstable_icestorm.py',
|
||||
'mesonbuild/modules/unstable_rust.py',
|
||||
'mesonbuild/modules/unstable_wayland.py',
|
||||
'mesonbuild/modules/wayland.py',
|
||||
'mesonbuild/modules/windows.py',
|
||||
'mesonbuild/mparser.py',
|
||||
'mesonbuild/msetup.py',
|
||||
|
|
|
@ -2,3 +2,7 @@ project('module warnings', meson_version : '>= 0.56')
|
|||
|
||||
import('python3') # deprecated module
|
||||
import('java') # new module
|
||||
import('unstable-keyval') # module that has been stabilized, import with unstable-
|
||||
|
||||
ice = import('icestorm', required : false)
|
||||
assert(not ice.found(), 'unstable-icestorm module should not be importable as `simd`')
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
},
|
||||
{
|
||||
"line": "test cases/common/253 module warnings/meson.build:4: WARNING: Project targets '>= 0.56' but uses feature introduced in '0.60.0': module java."
|
||||
},
|
||||
{
|
||||
"line": "test cases/common/253 module warnings/meson.build:5: WARNING: Project targets '>= 0.56' but uses feature deprecated since '0.56.0': module keyval has been stabilized. drop \"unstable-\" prefix from the module name"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
project('keyval basic test')
|
||||
project('keyval basic test', meson_version : '>= 0.55')
|
||||
|
||||
k = import('keyval')
|
||||
conf = k.load('.config')
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"stdout": [
|
||||
{
|
||||
"line": "WARNING: Module unstable-keyval is now stable, please use the keyval module instead."
|
||||
"line": "test cases/keyval/1 basic/meson.build:3: WARNING: Project targets '>= 0.55' but uses feature introduced in '0.56.0': module keyval as stable module. Consider either adding \"unstable-\" to the module name, or updating the meson required version to \">= 0.56.0\""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
project('module import without unstable', meson_version : '>= 0.55')
|
||||
|
||||
import('keyval')
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"stdout": [
|
||||
{
|
||||
"line": "test cases/warning/7 module without unstable/meson.build:3: WARNING: Project targets '>= 0.55' but uses feature introduced in '0.56.0': module keyval as stable module. Consider either adding \"unstable-\" to the module name, or updating the meson required version to \">= 0.56.0\""
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1929,7 +1929,7 @@ class AllPlatformTests(BasePlatformTests):
|
|||
r'sub' + os.path.sep + r'meson.build:3: WARNING: Keyword argument "link_with" defined multiple times.',
|
||||
r'meson.build:6: WARNING: a warning of some sort',
|
||||
r'sub' + os.path.sep + r'meson.build:4: WARNING: subdir warning',
|
||||
r'meson.build:7: WARNING: Module unstable-simd has no backwards or forwards compatibility and might not exist in future releases.',
|
||||
r'meson.build:7: WARNING: Module SIMD has no backwards or forwards compatibility and might not exist in future releases.',
|
||||
r"meson.build:11: WARNING: The variable(s) 'MISSING' in the input file 'conf.in' are not present in the given configuration data.",
|
||||
]:
|
||||
with self.subTest(expected):
|
||||
|
|
Loading…
Reference in New Issue