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.

Change-Id: I8fee1cfbf048e7afc6783b0a52eaca75be17072f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit 1a1d3a9a44e6e5946c375509c3f4a3a0fec5282d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Joerg Bornemann 2020-11-27 13:32:13 +01:00 committed by Qt Cherry-pick Bot
parent c765b8f280
commit 211ad0f768

View File

@ -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
@ -1023,6 +1025,10 @@ class Scope(object):
def parent(self) -> Optional[Scope]:
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: