build: use an object rather than a dict for the dep_manifest

This really is more of a struct than a dict, as the types are disjoint
and they are internally handled, (ie, not from user input). This cleans
some things up, in addition I spotted a bug in the ModuleState where the
dict with the version and license is passed to a field that expects just
the version string.
pull/9167/head
Dylan Baker 3 years ago
parent 6c5bfd4c24
commit d661a0cd96
  1. 3
      mesonbuild/backend/backends.py
  2. 15
      mesonbuild/build.py
  3. 3
      mesonbuild/interpreter/interpreter.py
  4. 6
      mesonbuild/interpreter/mesonmain.py
  5. 2
      mesonbuild/modules/__init__.py
  6. 16
      mesonbuild/modules/pkgconfig.py
  7. 2
      mesonbuild/modules/unstable_external_project.py

@ -1144,7 +1144,8 @@ class Backend:
ifilename = os.path.join(self.environment.get_build_dir(), 'depmf.json')
ofilename = os.path.join(self.environment.get_prefix(), self.build.dep_manifest_name)
out_name = os.path.join('{prefix}', self.build.dep_manifest_name)
mfobj = {'type': 'dependency manifest', 'version': '1.0', 'projects': self.build.dep_manifest}
mfobj = {'type': 'dependency manifest', 'version': '1.0',
'projects': {k: v.to_json() for k, v in self.build.dep_manifest.items()}}
with open(ifilename, 'w', encoding='utf-8') as f:
f.write(json.dumps(mfobj))
# Copy file from, to, and with mode unchanged

@ -206,6 +206,19 @@ class InstallDir(HoldableObject):
self.install_tag = install_tag
class DepManifest:
def __init__(self, version: str, license: T.List[str]):
self.version = version
self.license = license
def to_json(self) -> T.Dict[str, T.Union[str, T.List[str]]]:
return {
'version': self.version,
'license': self.license,
}
class Build:
"""A class that holds the status of one build including
all dependencies and so on.
@ -235,7 +248,7 @@ class Build:
self.dist_scripts: T.List['ExecutableSerialisation'] = []
self.install_dirs: T.List[InstallDir] = []
self.dep_manifest_name: T.Optional[str] = None
self.dep_manifest: T.Dict[str, T.Dict[str, T.Any]] = {} # TODO: what should this dict be?
self.dep_manifest: T.Dict[str, DepManifest] = {}
self.stdlibs = PerMachine({}, {})
self.test_setups: T.Dict[str, TestSetup] = {}
self.test_setup_default_name = None

@ -1060,8 +1060,7 @@ external dependencies (including libraries) must go to "dependencies".''')
if self.build.project_version is None:
self.build.project_version = self.project_version
proj_license = mesonlib.stringlistify(kwargs.get('license', 'unknown'))
self.build.dep_manifest[proj_name] = {'version': self.project_version,
'license': proj_license}
self.build.dep_manifest[proj_name] = build.DepManifest(self.project_version, proj_license)
if self.subproject in self.build.projects:
raise InvalidCode('Second call to project().')

@ -384,14 +384,14 @@ class MesonMain(MesonInterpreterObject):
@noPosargs
@noKwargs
def project_version_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str:
return self.build.dep_manifest[self.interpreter.active_projectname]['version']
def project_version_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> T.List[str]:
return self.build.dep_manifest[self.interpreter.active_projectname].version
@FeatureNew('meson.project_license()', '0.45.0')
@noPosargs
@noKwargs
def project_license_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> str:
return self.build.dep_manifest[self.interpreter.active_projectname]['license']
return self.build.dep_manifest[self.interpreter.active_projectname].license
@noPosargs
@noKwargs

@ -45,7 +45,7 @@ class ModuleState:
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]
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

@ -12,18 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from pathlib import PurePath
import os
import typing as T
from . import ExtensionModule
from . import ModuleReturnValue
from .. import build
from .. import dependencies
from ..dependencies import ThreadDependency
from .. import mesonlib
from .. import mlog
from . import ModuleReturnValue
from . import ExtensionModule
from ..dependencies import ThreadDependency
from ..interpreterbase import permittedKwargs, FeatureNew, FeatureNewKwargs
if T.TYPE_CHECKING:
from . import ModuleState
already_warned_objs = set()
class DependenciesHelper:
@ -451,8 +455,8 @@ class PkgConfigModule(ExtensionModule):
'install_dir', 'extra_cflags', 'variables', 'url', 'd_module_versions',
'dataonly', 'conflicts', 'uninstalled_variables',
'unescaped_variables', 'unescaped_uninstalled_variables'})
def generate(self, state, args, kwargs):
default_version = state.project_version['version']
def generate(self, state: 'ModuleState', args, kwargs):
default_version = state.project_version
default_install_dir = None
default_description = None
default_name = None

@ -232,7 +232,7 @@ class ExternalProject(NewExtensionModule):
abs_includedir = Path(abs_includedir, subdir)
abs_libdir = Path(self.install_dir, self.rel_prefix, self.libdir)
version = self.project_version['version']
version = self.project_version
incdir = []
compile_args = [f'-I{abs_includedir}']
link_args = [f'-L{abs_libdir}', f'-l{libname}']

Loading…
Cancel
Save