summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2019-07-15 15:38:47 +0200
committerLeander Beernaert <leander.beernaert@qt.io>2019-07-18 07:26:01 +0000
commit341ccc3b590d0a06157f29ce9237bc111e8cebf8 (patch)
tree3fe33c7eea11a5b0be96d81b226b61d90a8559b6
parent48fd425ea8bbb79fad9800db7b8dbb1b35196142 (diff)
Enable recursive expansion of simple qmake variables
Allow _expand_value to expand variables that may have more than one level of expansion when the regular expression covers all of the input. E.g.: A = Foo B = $$A/Bar scope.expand('$$B') While the original code was able to expand the string '$$B/source.cpp' to 'Foo/Bar/source.cpp', it could not expand the string '$$B' completely. The latter would always return '$$A/Bar' instead of the expected 'Foo/Bar' string. A test case has been added which coveres the above example. Change-Id: Ie3b5739c24ecbeb67d408dd204b0f54bab1d0f3f Reviewed-by: Qt CMake Build Bot Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rwxr-xr-xutil/cmake/pro2cmake.py28
-rwxr-xr-xutil/cmake/tests/test_scope_handling.py8
2 files changed, 24 insertions, 12 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index 44768efa03..22b2d03219 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -569,12 +569,12 @@ class Scope(object):
def _evalOps(self, key: str,
transformer: typing.Optional[typing.Callable[[Scope, typing.List[str]], typing.List[str]]],
- result: typing.List[str], *, inherrit: bool = False) \
+ result: typing.List[str], *, inherit: bool = False) \
-> typing.List[str]:
self._visited_keys.add(key)
# Inherrit values from above:
- if self._parent and inherrit:
+ if self._parent and inherit:
result = self._parent._evalOps(key, transformer, result)
if transformer:
@@ -590,7 +590,7 @@ class Scope(object):
return result
- def get(self, key: str, *, ignore_includes: bool = False, inherrit: bool = False) -> typing.List[str]:
+ def get(self, key: str, *, ignore_includes: bool = False, inherit: bool = False) -> typing.List[str]:
is_same_path = self.currentdir == self.basedir
@@ -605,7 +605,7 @@ class Scope(object):
else:
return ['${CMAKE_CURRENT_BINARY_DIR}/' + os.path.relpath(self.currentdir, self.basedir),]
- return self._evalOps(key, None, [], inherrit=inherrit)
+ return self._evalOps(key, None, [], inherit=inherit)
def get_string(self, key: str, default: str = '') -> str:
v = self.get(key)
@@ -625,7 +625,7 @@ class Scope(object):
mapped_files = list(map(lambda f: map_to_file(f, self, is_include=is_include), expanded_files))
if use_vpath:
- result = list(map(lambda f: handle_vpath(f, self.basedir, self.get('VPATH', inherrit=True)), mapped_files))
+ result = list(map(lambda f: handle_vpath(f, self.basedir, self.get('VPATH', inherit=True)), mapped_files))
else:
result = mapped_files
@@ -649,13 +649,17 @@ class Scope(object):
while match:
old_result = result
if match.group(0) == value:
- return self.get(match.group(1))
-
- replacement = self.get(match.group(1))
- replacement_str = replacement[0] if replacement else ''
- result = result[:match.start()] \
- + replacement_str \
- + result[match.end():]
+ get_result = self.get(match.group(1), inherit = True)
+ if len(get_result) == 1:
+ result = get_result[0]
+ else:
+ return get_result
+ else:
+ replacement = self.get(match.group(1), inherit = True)
+ replacement_str = replacement[0] if replacement else ''
+ result = result[:match.start()] \
+ + replacement_str \
+ + result[match.end():]
if result == old_result:
return [result,] # Do not go into infinite loop
diff --git a/util/cmake/tests/test_scope_handling.py b/util/cmake/tests/test_scope_handling.py
index c0b553fabd..14fd266c9c 100755
--- a/util/cmake/tests/test_scope_handling.py
+++ b/util/cmake/tests/test_scope_handling.py
@@ -336,3 +336,11 @@ def test_qstandardpaths_scopes():
assert scope10.total_condition == 'UNIX AND NOT APPLE_OSX AND (ANDROID_EMBEDDED OR NOT ANDROID)'
assert scope11.total_condition == 'HAIKU AND (ANDROID_EMBEDDED OR NOT ANDROID)'
assert scope12.total_condition == 'UNIX AND NOT APPLE_OSX AND NOT HAIKU AND (ANDROID_EMBEDDED OR NOT ANDROID)'
+
+def test_recursive_expansion():
+ scope = _new_scope(A='Foo',B='$$A/Bar')
+ assert scope.get_string('A') == 'Foo'
+ assert scope.get_string('B') == '$$A/Bar'
+ assert scope._expand_value('$$B/Source.cpp') == ['Foo/Bar/Source.cpp']
+ assert scope._expand_value('$$B') == ['Foo/Bar']
+