diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-11-27 13:32:13 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-11-30 23:17:40 +0100 |
commit | 1a1d3a9a44e6e5946c375509c3f4a3a0fec5282d (patch) | |
tree | 8ef631278e7789eff8a5dfdd827d44dbad4e74bf /util | |
parent | c140b26959038ada22452079ebc6e33195e9957d (diff) |
pro2cmake: Fix is_public_module calculation
write_library_section traverses the parent/child hierarchy of scopes to
determine whether the scope belongs to a public Qt module. This doesn't
work for scopes that stem from included .pri files, because each
included file has its own parent/child hierarchy.
We already have an include scope hierarchy in the form of
Scope._included_children, but lack a way to get to the including
scope.
Add Scope._including_scope and adjust the is_public_module calculation
to take that into account after hitting the top of the parent/child
hierarchy.
Pick-to: 6.0
Change-Id: I8fee1cfbf048e7afc6783b0a52eaca75be17072f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-x | util/cmake/pro2cmake.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 6308ab0a6d..12dad0ebaf 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -994,6 +994,7 @@ class Scope(object): self._condition = map_condition(condition) self._children = [] # type: List[Scope] self._included_children = [] # type: List[Scope] + self._including_scope = None # type: Optional[Scope] self._visited_keys = set() # type: Set[str] self._total_condition = None # type: Optional[str] self._parent_include_line_no = parent_include_line_no @@ -1012,6 +1013,7 @@ class Scope(object): def merge(self, other: "Scope") -> None: assert self != other + other._including_scope = self self._included_children.append(other) @property @@ -1024,6 +1026,10 @@ class Scope(object): return self._parent @property + def including_scope(self) -> Optional[Scope]: + return self._including_scope + + @property def basedir(self) -> str: return self._basedir @@ -2159,6 +2165,18 @@ def write_compile_options( write_list(cm_fh, compile_options, cmake_parameter, indent, footer=footer) +# Return True if given scope belongs to a public module. +# First, traverse the parent/child hierarchy. Then, traverse the include hierarchy. +def recursive_is_public_module(scope: Scope): + if scope.is_public_module: + return True + if scope.parent: + return recursive_is_public_module(scope.parent) + if scope.including_scope: + return recursive_is_public_module(scope.including_scope) + return False + + def write_library_section( cm_fh: IO[str], scope: Scope, *, indent: int = 0, known_libraries: Optional[Set[str]] = None ): @@ -2168,11 +2186,7 @@ def write_library_section( scope, known_libraries=known_libraries ) - is_public_module = scope.is_public_module - current_scope = scope - while not is_public_module and current_scope.parent: - current_scope = current_scope.parent - is_public_module = current_scope.is_public_module + is_public_module = recursive_is_public_module(scope) # When handling module dependencies, handle QT += foo-private magic. # This implies: |