From c58df80cf7926b07da9fe6515230bd4295c1fc6d Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 18 Sep 2019 15:17:09 +0200 Subject: 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 Reviewed-by: Cristian Maureira-Fredes --- util/cmake/pro2cmake.py | 21 +++++++++++++++++++-- 1 file 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]: -- cgit v1.2.3