Skip to content

Commit

Permalink
Defer evaluating ModuleState.project_version
Browse files Browse the repository at this point in the history
This property is only used in `pkgconfig.generate`, and
`external_project.dependency`, not elsewhere. By avoiding this
evaluation, it fixes an exception if using `import` in the `version`
argument of `project`.

Fixes mesonbuild#5134
  • Loading branch information
QuLogic committed May 27, 2024
1 parent 8d92487 commit d8ed284
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion mesonbuild/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def __init__(self, interpreter: 'Interpreter') -> None:
self.current_lineno = interpreter.current_lineno
self.environment = interpreter.environment
self.project_name = interpreter.build.project_name
self.project_version = interpreter.build.dep_manifest[interpreter.active_projectname].version
# The backend object is under-used right now, but we will need it:
# https://github.com/mesonbuild/meson/issues/1419
self.backend = interpreter.backend
Expand All @@ -52,6 +51,10 @@ def __init__(self, interpreter: 'Interpreter') -> None:
self.project_args = interpreter.build.projects_args.host.get(interpreter.subproject, {})
self.current_node = interpreter.current_node

@property
def project_version(self) -> str:
return self._interpreter.build.dep_manifest[self._interpreter.active_projectname].version

def get_include_args(self, include_dirs: T.Iterable[T.Union[str, build.IncludeDirs]], prefix: str = '-I') -> T.List[str]:
if not include_dirs:
return []
Expand Down
3 changes: 1 addition & 2 deletions mesonbuild/modules/external_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def __init__(self,
})

self.subdir = Path(state.subdir)
self.project_version = state.project_version
self.subproject = state.subproject
self.env = state.environment
self.configure_command = configure_command
Expand Down Expand Up @@ -262,7 +261,7 @@ def dependency_method(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'D
abs_includedir = Path(abs_includedir, kwargs['subdir'])
abs_libdir = Path(self.install_dir, self.rel_prefix, self.libdir)

version = self.project_version
version = state.project_version
compile_args = [f'-I{abs_includedir}']
link_args = [f'-L{abs_libdir}', f'-l{libname}']
sources = self.target
Expand Down

0 comments on commit d8ed284

Please sign in to comment.