aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-01-12 11:31:25 -0800
committerDylan Baker <dylan@pnwbakers.com>2021-01-13 13:32:48 -0800
commite36aca42d0980ce4b43e5753d798c986135e9f43 (patch)
treebe24e9dca9f08196ac83dfffa5d6b6aef9d6e026
parent59328aba2929b969a7e7ce1390d891dafe391a7f (diff)
downloadmeson-e36aca42d0980ce4b43e5753d798c986135e9f43.zip
meson-e36aca42d0980ce4b43e5753d798c986135e9f43.tar.gz
meson-e36aca42d0980ce4b43e5753d798c986135e9f43.tar.bz2
build/interpreter: Split InstallDir to fix layering violation
Currently InstallDir is part of the interpreter, and is an Interpreter object, which is then put in the Build object. This is a layering violation, the interperter should have a Holder for build data. This patch fixes that.
-rw-r--r--mesonbuild/build.py17
-rw-r--r--mesonbuild/interpreter.py40
-rw-r--r--mesonbuild/modules/unstable_external_project.py18
-rw-r--r--test cases/failing/69 install_data rename bad size/test.json2
4 files changed, 44 insertions, 33 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 23d2ff7..017b0f0 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -171,6 +171,21 @@ class Man:
return self.sources
+class InstallDir:
+
+ def __init__(self, src_subdir: str, inst_subdir: str, install_dir: str,
+ install_mode: T.Optional['FileMode'],
+ exclude: T.Tuple[T.Set[str], T.Set[str]],
+ strip_directory: bool, from_source_dir: bool = True):
+ self.source_subdir = src_subdir
+ self.installable_subdir = inst_subdir
+ self.install_dir = install_dir
+ self.install_mode = install_mode
+ self.exclude = exclude
+ self.strip_directory = strip_directory
+ self.from_source_dir = from_source_dir
+
+
class Build:
"""A class that holds the status of one build including
all dependencies and so on.
@@ -198,7 +213,7 @@ class Build:
self.install_scripts = []
self.postconf_scripts = []
self.dist_scripts = []
- self.install_dirs = []
+ self.install_dirs: T.List[InstallDir] = []
self.dep_manifest_name = None
self.dep_manifest = {}
self.stdlibs = PerMachine({}, {})
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index fdb6fa7..15a6ddd 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -757,17 +757,11 @@ class DataHolder(InterpreterObject, ObjectHolder):
def get_install_dir(self):
return self.held_object.install_dir
-class InstallDir(InterpreterObject):
- def __init__(self, src_subdir, inst_subdir, install_dir, install_mode,
- exclude, strip_directory, from_source_dir=True):
+class InstallDirHolder(InterpreterObject, ObjectHolder):
+
+ def __init__(self, obj: build.InstallDir):
InterpreterObject.__init__(self)
- self.source_subdir = src_subdir
- self.installable_subdir = inst_subdir
- self.install_dir = install_dir
- self.install_mode = install_mode
- self.exclude = exclude
- self.strip_directory = strip_directory
- self.from_source_dir = from_source_dir
+ ObjectHolder.__init__(self, obj)
class ManHolder(InterpreterObject, ObjectHolder):
@@ -2591,8 +2585,8 @@ class Interpreter(InterpreterBase):
# FIXME: This is special cased and not ideal:
# The first source is our new VapiTarget, the rest are deps
self.process_new_values(v.sources[0])
- elif isinstance(v, InstallDir):
- self.build.install_dirs.append(v)
+ elif isinstance(v, InstallDirHolder):
+ self.build.install_dirs.append(v.held_object)
elif isinstance(v, Test):
self.build.tests.append(v)
elif hasattr(v, 'held_object'):
@@ -4336,43 +4330,45 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
def func_install_subdir(self, node, args, kwargs):
if len(args) != 1:
raise InvalidArguments('Install_subdir requires exactly one argument.')
- subdir = args[0]
+ subdir: str = args[0]
+ if not isinstance(subdir, str):
+ raise InvalidArguments('install_subdir positional argument 1 must be a string.')
if 'install_dir' not in kwargs:
raise InvalidArguments('Missing keyword argument install_dir')
- install_dir = kwargs['install_dir']
+ install_dir: str = kwargs['install_dir']
if not isinstance(install_dir, str):
raise InvalidArguments('Keyword argument install_dir not a string.')
if 'strip_directory' in kwargs:
- if not isinstance(kwargs['strip_directory'], bool):
+ strip_directory: bool = kwargs['strip_directory']
+ if not isinstance(strip_directory, bool):
raise InterpreterException('"strip_directory" keyword must be a boolean.')
- strip_directory = kwargs['strip_directory']
else:
strip_directory = False
if 'exclude_files' in kwargs:
- exclude = extract_as_list(kwargs, 'exclude_files')
+ exclude: T.List[str] = extract_as_list(kwargs, 'exclude_files')
for f in exclude:
if not isinstance(f, str):
raise InvalidArguments('Exclude argument not a string.')
elif os.path.isabs(f):
raise InvalidArguments('Exclude argument cannot be absolute.')
- exclude_files = set(exclude)
+ exclude_files: T.Set[str] = set(exclude)
else:
exclude_files = set()
if 'exclude_directories' in kwargs:
- exclude = extract_as_list(kwargs, 'exclude_directories')
+ exclude: T.List[str] = extract_as_list(kwargs, 'exclude_directories')
for d in exclude:
if not isinstance(d, str):
raise InvalidArguments('Exclude argument not a string.')
elif os.path.isabs(d):
raise InvalidArguments('Exclude argument cannot be absolute.')
- exclude_directories = set(exclude)
+ exclude_directories: T.Set[str] = set(exclude)
else:
exclude_directories = set()
exclude = (exclude_files, exclude_directories)
install_mode = self._get_kwarg_install_mode(kwargs)
- idir = InstallDir(self.subdir, subdir, install_dir, install_mode, exclude, strip_directory)
+ idir = build.InstallDir(self.subdir, subdir, install_dir, install_mode, exclude, strip_directory)
self.build.install_dirs.append(idir)
- return idir
+ return InstallDirHolder(idir)
@FeatureNewKwargs('configure_file', '0.47.0', ['copy', 'output_format', 'install_mode', 'encoding'])
@FeatureNewKwargs('configure_file', '0.46.0', ['format'])
diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py
index 809b590..1604e25 100644
--- a/mesonbuild/modules/unstable_external_project.py
+++ b/mesonbuild/modules/unstable_external_project.py
@@ -22,7 +22,7 @@ from ..mesonlib import (MesonException, Popen_safe, MachineChoice,
get_variable_regex, do_replacement)
from ..interpreterbase import InterpreterObject, InterpreterException, FeatureNew
from ..interpreterbase import stringArgs, permittedKwargs
-from ..interpreter import Interpreter, DependencyHolder, InstallDir
+from ..interpreter import Interpreter, DependencyHolder, InstallDirHolder
from ..compilers.compilers import CFLAGS_MAPPING, CEXE_MAPPING
from ..dependencies.base import InternalDependency, PkgConfigDependency
from ..environment import Environment
@@ -192,15 +192,15 @@ class ExternalProject(InterpreterObject):
self.subproject,
target_kwargs)
- idir = InstallDir(self.subdir.as_posix(),
- Path('dist', self.rel_prefix).as_posix(),
- install_dir='.',
- install_mode=None,
- exclude=None,
- strip_directory=True,
- from_source_dir=False)
+ idir = build.InstallDir(self.subdir.as_posix(),
+ Path('dist', self.rel_prefix).as_posix(),
+ install_dir='.',
+ install_mode=None,
+ exclude=None,
+ strip_directory=True,
+ from_source_dir=False)
- return [self.target, idir]
+ return [self.target, InstallDirHolder(idir)]
@stringArgs
@permittedKwargs({'subdir'})
diff --git a/test cases/failing/69 install_data rename bad size/test.json b/test cases/failing/69 install_data rename bad size/test.json
index 1329fec..b99688a 100644
--- a/test cases/failing/69 install_data rename bad size/test.json
+++ b/test cases/failing/69 install_data rename bad size/test.json
@@ -1,7 +1,7 @@
{
"stdout": [
{
- "line": "test cases/failing/69 install_data rename bad size/meson.build:3:0: ERROR: Size of rename argument is different from number of sources"
+ "line": "test cases/failing/69 install_data rename bad size/meson.build:3:0: ERROR: \"rename\" and \"sources\" argument lists must be the same length if \"rename\" is given. Rename has 1 elements and sources has 2."
}
]
}