build/interperter: Add annotations and move input validation to interpreter

This moves the user input validation to the interpreter, instead of
being in the build module, and adds type annotations.
pull/8192/head
Dylan Baker 4 years ago
parent 6180992d49
commit 022632c91b
  1. 10
      mesonbuild/build.py
  2. 19
      mesonbuild/interpreter.py
  3. 4
      mesonbuild/modules/cmake.py
  4. 2
      mesonbuild/modules/gnome.py
  5. 2
      mesonbuild/modules/pkgconfig.py

@ -2567,19 +2567,15 @@ class ConfigurationData:
# A bit poorly named, but this represents plain data files to copy
# during install.
class Data:
def __init__(self, sources, install_dir, install_mode=None, rename=None):
def __init__(self, sources: T.List[File], install_dir: str,
install_mode: T.Optional['FileMode'] = None, rename: T.List[str] = None):
self.sources = sources
self.install_dir = install_dir
self.install_mode = install_mode
self.sources = listify(self.sources)
for s in self.sources:
assert(isinstance(s, File))
if rename is None:
self.rename = [os.path.basename(f.fname) for f in self.sources]
else:
self.rename = stringlistify(rename)
if len(self.rename) != len(self.sources):
raise MesonException('Size of rename argument is different from number of sources')
self.rename = rename
class RunScript(dict):
def __init__(self, script, args):

@ -4300,11 +4300,11 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
@FeatureNewKwargs('install_data', '0.46.0', ['rename'])
@FeatureNewKwargs('install_data', '0.38.0', ['install_mode'])
@permittedKwargs(permitted_kwargs['install_data'])
def func_install_data(self, node, args, kwargs):
def func_install_data(self, node, args: T.List, kwargs: T.Dict[str, T.Any]):
kwsource = mesonlib.stringlistify(kwargs.get('sources', []))
raw_sources = args + kwsource
sources = []
source_strings = []
sources: T.List[mesonlib.File] = []
source_strings: T.List[str] = []
for s in raw_sources:
if isinstance(s, mesonlib.File):
sources.append(s)
@ -4313,11 +4313,18 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
else:
raise InvalidArguments('Argument must be string or file.')
sources += self.source_strings_to_files(source_strings)
install_dir = kwargs.get('install_dir', None)
if not isinstance(install_dir, (str, type(None))):
install_dir: T.Optional[str] = kwargs.get('install_dir', None)
if install_dir is not None and not isinstance(install_dir, str):
raise InvalidArguments('Keyword argument install_dir not a string.')
install_mode = self._get_kwarg_install_mode(kwargs)
rename = kwargs.get('rename', None)
rename: T.Optional[T.List[str]] = kwargs.get('rename', None)
if rename is not None:
rename = mesonlib.stringlistify(rename)
if len(rename) != len(sources):
raise InvalidArguments(
'"rename" and "sources" argument lists must be the same length if "rename" is given. '
f'Rename has {len(rename)} elements and sources has {len(sources)}.')
data = DataHolder(build.Data(sources, install_dir, install_mode, rename))
self.build.data.append(data.held_object)
return data

@ -285,7 +285,7 @@ class CmakeModule(ExtensionModule):
}
mesonlib.do_conf_file(template_file, version_file, conf, 'meson')
res = build.Data(mesonlib.File(True, state.environment.get_scratch_dir(), version_file), pkgroot)
res = build.Data([mesonlib.File(True, state.environment.get_scratch_dir(), version_file)], pkgroot)
return ModuleReturnValue(res, [res])
def create_package_file(self, infile, outfile, PACKAGE_RELATIVE_PATH, extra, confdata):
@ -370,7 +370,7 @@ class CmakeModule(ExtensionModule):
if conffile not in interpreter.build_def_files:
interpreter.build_def_files.append(conffile)
res = build.Data(mesonlib.File(True, ofile_path, ofile_fname), install_dir)
res = build.Data([mesonlib.File(True, ofile_path, ofile_fname)], install_dir)
interpreter.build.data.append(res)
return res

@ -1629,7 +1629,7 @@ G_END_DECLS'''
with open(fname, 'w') as ofile:
for package in packages:
ofile.write(package + '\n')
return build.Data(mesonlib.File(True, outdir, fname), install_dir)
return build.Data([mesonlib.File(True, outdir, fname)], install_dir)
def _get_vapi_link_with(self, target):
link_with = []

@ -539,7 +539,7 @@ class PkgConfigModule(ExtensionModule):
self.generate_pkgconfig_file(state, deps, subdirs, name, description, url,
version, pcfile, conflicts, variables,
False, dataonly)
res = build.Data(mesonlib.File(True, state.environment.get_scratch_dir(), pcfile), pkgroot)
res = build.Data([mesonlib.File(True, state.environment.get_scratch_dir(), pcfile)], pkgroot)
variables = self.interpreter.extract_variables(kwargs, argname='uninstalled_variables', dict_new=True)
variables = parse_variable_list(variables)

Loading…
Cancel
Save