Skip to content

Commit

Permalink
Enable use of get_options in project statement
Browse files Browse the repository at this point in the history
  • Loading branch information
bcorby committed Dec 16, 2024
1 parent 0b41b36 commit a3481b6
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,9 @@ def get_option_internal(self, optname: str) -> options.UserOption:
def func_get_option(self, nodes: mparser.BaseNode, args: T.Tuple[str],
kwargs: 'TYPE_kwargs') -> T.Union[options.UserOption, 'TYPE_var']:
optname = args[0]

self.load_options(nodes, args)

if ':' in optname:
raise InterpreterException('Having a colon in option name is forbidden, '
'projects are not allowed to directly access '
Expand Down Expand Up @@ -1148,34 +1151,7 @@ def set_backend(self) -> None:
options = {k: v for k, v in self.environment.options.items() if self.environment.coredata.optstore.is_backend_option(k)}
self.coredata.set_options(options)

@typed_pos_args('project', str, varargs=str)
@typed_kwargs(
'project',
DEFAULT_OPTIONS,
KwargInfo('meson_version', (str, NoneType)),
KwargInfo(
'version',
(str, mesonlib.File, NoneType, list),
default='undefined',
validator=_project_version_validator,
convertor=lambda x: x[0] if isinstance(x, list) else x,
),
KwargInfo('license', (ContainerTypeInfo(list, str), NoneType), default=None, listify=True),
KwargInfo('license_files', ContainerTypeInfo(list, str), default=[], listify=True, since='1.1.0'),
KwargInfo('subproject_dir', str, default='subprojects'),
)
def func_project(self, node: mparser.FunctionNode, args: T.Tuple[str, T.List[str]], kwargs: 'kwtypes.Project') -> None:
proj_name, proj_langs = args
if ':' in proj_name:
raise InvalidArguments(f"Project name {proj_name!r} must not contain ':'")

# This needs to be evaluated as early as possible, as meson uses this
# for things like deprecation testing.
if kwargs['meson_version']:
self.handle_meson_version(kwargs['meson_version'], node)
else:
mesonlib.project_meson_versions[self.subproject] = mesonlib.NoProjectVersion()

def load_options(self, node: mparser.FunctionNode, args: T.Tuple[str, T.List[str]]) -> None:
# Load "meson.options" before "meson_options.txt", and produce a warning if
# it is being used with an old version. I have added check that if both
# exist the warning isn't raised
Expand Down Expand Up @@ -1204,6 +1180,34 @@ def func_project(self, node: mparser.FunctionNode, args: T.Tuple[str, T.List[str
else:
self.coredata.options_files[self.subproject] = None

@typed_pos_args('project', str, varargs=str)
@typed_kwargs(
'project',
DEFAULT_OPTIONS,
KwargInfo('meson_version', (str, NoneType)),
KwargInfo(
'version',
(str, mesonlib.File, NoneType, list),
default='undefined',
validator=_project_version_validator,
convertor=lambda x: x[0] if isinstance(x, list) else x,
),
KwargInfo('license', (ContainerTypeInfo(list, str), NoneType), default=None, listify=True),
KwargInfo('license_files', ContainerTypeInfo(list, str), default=[], listify=True, since='1.1.0'),
KwargInfo('subproject_dir', str, default='subprojects'),
)
def func_project(self, node: mparser.FunctionNode, args: T.Tuple[str, T.List[str]], kwargs: 'kwtypes.Project') -> None:
proj_name, proj_langs = args
if ':' in proj_name:
raise InvalidArguments(f"Project name {proj_name!r} must not contain ':'")

# This needs to be evaluated as early as possible, as meson uses this
# for things like deprecation testing.
if kwargs['meson_version']:
self.handle_meson_version(kwargs['meson_version'], node)
else:
mesonlib.project_meson_versions[self.subproject] = mesonlib.NoProjectVersion()

if self.subproject:
self.project_default_options = {k.evolve(subproject=self.subproject): v
for k, v in kwargs['default_options'].items()}
Expand Down

0 comments on commit a3481b6

Please sign in to comment.