Fix conversion of SUBDIR pro files not in current directory

This patch fixes the processing of pro files that do not reside in
the current directory. Before this patch statements such as SUBDIRS +=
Foo/Bar/z.pro would cause z.pro to be parsed in the current
CMakeLists.txt. What we want instead is a call to
add_subdirectory(Foo/Bar). Failing to do so leads to issues with
relative paths specified in z.pro being invalid.

Change-Id: I7bfa7837d54877e5340081d1c9aebe855cf6796d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Leander Beernaert 2019-08-08 09:52:36 +02:00
parent d8a7c0f40f
commit 6396840182

View File

@ -1091,14 +1091,22 @@ def handle_subdir(scope: Scope,
collect_subdir_info(sd, current_conditions=current_conditions)
# For the file case, directly write into the file handle.
elif os.path.isfile(sd):
subdir_result = parseProFile(sd, debug=False)
subdir_scope \
= Scope.FromDict(scope, sd,
subdir_result.asDict().get('statements'),
'', scope.basedir)
# Handle cases with SUBDIRS += Foo/bar/z.pro. We want to be able
# to generate add_subdirectory(Foo/bar) instead of parsing the full
# .pro file in the current CMakeLists.txt. This causes issues
# with relative paths in certain projects otherwise.
dirname = os.path.dirname(sd)
if dirname:
collect_subdir_info(dirname, current_conditions=current_conditions)
else:
subdir_result = parseProFile(sd, debug=False)
subdir_scope \
= Scope.FromDict(scope, sd,
subdir_result.asDict().get('statements'),
'', scope.basedir)
do_include(subdir_scope)
cmakeify_scope(subdir_scope, cm_fh, indent=indent, is_example=is_example)
do_include(subdir_scope)
cmakeify_scope(subdir_scope, cm_fh, indent=indent, is_example=is_example)
else:
print(' XXXX: SUBDIR {} in {}: Not found.'.format(sd, scope))