aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2021-03-02 21:49:23 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2021-03-02 22:08:11 +0200
commitbcfa1218a89a8ee5567ae1fc1e5646eeae1e2d60 (patch)
tree3e629c532e4cc82e945796e522386a22d39bcaf3
parentb7bcdb7839f7c2ac53f540235ec44c6ba8e344d7 (diff)
downloadmeson-subdirrefac.zip
meson-subdirrefac.tar.gz
meson-subdirrefac.tar.bz2
Refactor subdir visitation to track files instead of dirs.subdirrefac
-rw-r--r--mesonbuild/ast/interpreter.py13
-rw-r--r--mesonbuild/interpreter.py7
-rw-r--r--test cases/failing/112 enter subdir twice/meson.build3
-rw-r--r--test cases/failing/112 enter subdir twice/sub/meson.build1
-rw-r--r--test cases/failing/112 enter subdir twice/test.json7
5 files changed, 22 insertions, 9 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py
index 23c8427..68ecddd 100644
--- a/mesonbuild/ast/interpreter.py
+++ b/mesonbuild/ast/interpreter.py
@@ -70,10 +70,10 @@ class AstInterpreter(interpreterbase.InterpreterBase):
def __init__(self, source_root: str, subdir: str, subproject: str, visitors: T.Optional[T.List[AstVisitor]] = None):
super().__init__(source_root, subdir, subproject)
self.visitors = visitors if visitors is not None else []
- self.visited_subdirs = {} # type: T.Dict[str, bool]
- self.assignments = {} # type: T.Dict[str, BaseNode]
- self.assign_vals = {} # type: T.Dict[str, T.Any]
- self.reverse_assignment = {} # type: T.Dict[str, BaseNode]
+ self.processed_buildfiles = {} # type: T.Dict[str, bool]
+ self.assignments = {} # type: T.Dict[str, BaseNode]
+ self.assign_vals = {} # type: T.Dict[str, T.Any]
+ self.reverse_assignment = {} # type: T.Dict[str, BaseNode]
self.funcs.update({'project': self.func_do_nothing,
'test': self.func_do_nothing,
'benchmark': self.func_do_nothing,
@@ -150,10 +150,11 @@ class AstInterpreter(interpreterbase.InterpreterBase):
buildfilename = os.path.join(subdir, environment.build_filename)
absname = os.path.join(self.source_root, buildfilename)
symlinkless_dir = os.path.realpath(absdir)
- if symlinkless_dir in self.visited_subdirs:
+ build_file = os.path.join(symlinkless_dir, 'meson.build')
+ if build_file in self.processed_buildfiles:
sys.stderr.write('Trying to enter {} which has already been visited --> Skipping\n'.format(args[0]))
return
- self.visited_subdirs[symlinkless_dir] = True
+ self.processed_buildfiles[build_file] = True
if not os.path.isfile(absname):
sys.stderr.write('Unable to find build file {} --> Skipping\n'.format(buildfilename))
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 5642242..dde3b4c 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2431,7 +2431,7 @@ class Interpreter(InterpreterBase):
self.sanity_check_ast()
self.builtin.update({'meson': MesonMain(build, self)})
self.generators = []
- self.visited_subdirs = {}
+ self.processed_buildfiles = {}
self.project_args_frozen = False
self.global_args_frozen = False # implies self.project_args_frozen
self.subprojects = {}
@@ -4272,10 +4272,11 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
raise InvalidArguments('Subdir argument must be a relative path.')
absdir = os.path.join(self.environment.get_source_dir(), subdir)
symlinkless_dir = os.path.realpath(absdir)
- if symlinkless_dir in self.visited_subdirs:
+ build_file = os.path.join(symlinkless_dir, 'meson.build')
+ if build_file in self.processed_buildfiles:
raise InvalidArguments('Tried to enter directory "%s", which has already been visited.'
% subdir)
- self.visited_subdirs[symlinkless_dir] = True
+ self.processed_buildfiles[build_file] = True
self.subdir = subdir
os.makedirs(os.path.join(self.environment.build_dir, subdir), exist_ok=True)
buildfilename = os.path.join(self.subdir, environment.build_filename)
diff --git a/test cases/failing/112 enter subdir twice/meson.build b/test cases/failing/112 enter subdir twice/meson.build
new file mode 100644
index 0000000..9343233
--- /dev/null
+++ b/test cases/failing/112 enter subdir twice/meson.build
@@ -0,0 +1,3 @@
+project('subdir2', 'c')
+subdir('sub')
+subdir('sub')
diff --git a/test cases/failing/112 enter subdir twice/sub/meson.build b/test cases/failing/112 enter subdir twice/sub/meson.build
new file mode 100644
index 0000000..d036a3f
--- /dev/null
+++ b/test cases/failing/112 enter subdir twice/sub/meson.build
@@ -0,0 +1 @@
+message('Now in subdir')
diff --git a/test cases/failing/112 enter subdir twice/test.json b/test cases/failing/112 enter subdir twice/test.json
new file mode 100644
index 0000000..9443b2f
--- /dev/null
+++ b/test cases/failing/112 enter subdir twice/test.json
@@ -0,0 +1,7 @@
+{
+ "stdout": [
+ {
+ "line": "test cases/failing/112 enter subdir twice/meson.build:3:0: ERROR: Tried to enter directory \"sub\", which has already been visited."
+ }
+ ]
+}