Skip to content

Commit

Permalink
pro2cmake: Fix is_public_module calculation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jobor committed Nov 30, 2020
1 parent c140b26 commit 1a1d3a9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions util/cmake/pro2cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ def __init__(
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
Expand All @@ -1012,6 +1013,7 @@ def reset_visited_keys(self):

def merge(self, other: "Scope") -> None:
assert self != other
other._including_scope = self
self._included_children.append(other)

@property
Expand All @@ -1023,6 +1025,10 @@ def scope_debug(self) -> bool:
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
Expand Down Expand Up @@ -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
):
Expand All @@ -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:
Expand Down

0 comments on commit 1a1d3a9

Please sign in to comment.