summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-09-18 15:17:09 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-09-18 14:22:46 +0000
commitc58df80cf7926b07da9fe6515230bd4295c1fc6d (patch)
treede2b0dddc51d60db757c298d2b1ba9008d6122b3
parentb72adf8a911f4281c7c56b359f9ae1a35f766fcf (diff)
pro2cmake: Handle qmake env variables in file paths
Replace things like $$(FOO) to $ENV{FOO}. This is needed to stop the script from crashing when it sees $$(FOO) in a .pro file, like in qtmultimedia/src/plugins/directshow/directshow.pro A better approach in the future will be to write a Find module that uses the env var to find the relevant headers, and then instead use a CMake cache variable, to make the build more robust in case the env var is removed after first configuring the project. Change-Id: Ia5b3dc3a90e1d4159a8b90acdade85f34b5165f9 Reviewed-by: Qt CMake Build Bot Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rwxr-xr-xutil/cmake/pro2cmake.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index bb30cfe3b1..0ebc94d72e 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -951,32 +951,49 @@ class Scope(object):
return list(self._evalOps(key, transformer, []))
+ @staticmethod
+ def _replace_env_var_value(value: Any) -> str:
+ if not isinstance(value, str):
+ return value
+
+ pattern = re.compile(r"\$\$\(?([A-Za-z_][A-Za-z0-9_]*)\)?")
+ match = re.search(pattern, value)
+ if match:
+ value = re.sub(pattern, r"$ENV{\1}", value)
+
+ return value
+
def _expand_value(self, value: str) -> List[str]:
result = value
pattern = re.compile(r"\$\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?")
match = re.search(pattern, result)
while match:
old_result = result
- if match.group(0) == value:
+ match_group_0 = match.group(0)
+ if match_group_0 == value:
get_result = self.get(match.group(1), inherit=True)
if len(get_result) == 1:
result = get_result[0]
+ result = self._replace_env_var_value(result)
else:
# Recursively expand each value from the result list
# returned from self.get().
result_list = []
for entry_value in get_result:
- result_list += self._expand_value(entry_value)
+ result_list += self._expand_value(self._replace_env_var_value(entry_value))
return result_list
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() :]
+ result = self._replace_env_var_value(result)
if result == old_result:
return [result] # Do not go into infinite loop
match = re.search(pattern, result)
+
+ result = self._replace_env_var_value(result)
return [result]
def expand(self, key: str) -> List[str]: