From 062d9f63b75f56827e25b93bffd387f8c5dc7133 Mon Sep 17 00:00:00 2001 From: Keon Amini Date: Sun, 5 Jan 2025 01:08:19 -0600 Subject: [PATCH] VS path env vars now correctly evaluated --- cmake_converter/utils.py | 26 ++++++++++++++++++++--- cmake_converter/visual_studio/solution.py | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmake_converter/utils.py b/cmake_converter/utils.py index f092396..5430248 100644 --- a/cmake_converter/utils.py +++ b/cmake_converter/utils.py @@ -4,6 +4,7 @@ # Copyright (c) 2016-2020: # Matthieu Estrada, ttamalfor@gmail.com # Pavel Liavonau, liavonlida@gmail.com +# Keon Amini, keon.a380@gmail.com # # This file is part of (CMakeConverter). # @@ -322,20 +323,35 @@ def replace_vs_var_with_cmake_var(context, var): cmake_env_var = '$ENV{{{}}}'.format(var_name) if var_name not in os.environ: message(context, 'Unknown variable: {}, trying {}'.format(var, cmake_env_var), 'warn') + return cmake_env_var + def replace_vs_vars_with_cmake_vars(context, output): """ Translates variables at given string to corresponding CMake ones """ - var_ex = re.compile(r'(\$\(.*?\))') - - vars_list = var_ex.findall(output) + cmake_var_regex = re.compile(r'(\$\(.*?\))') + vars_list = cmake_var_regex.findall(output) for var in vars_list: replace_with = replace_vs_var_with_cmake_var(context, var) output = output.replace(var, replace_with) return output +def expand_cmake_env_vars(context, output): + """ Translates env-variables from a CMake variable""" + cmake_env_var_regex = re.compile(r'(\$ENV\{.*?\})') + vars_list = cmake_env_var_regex.findall(output) + for var in vars_list: + var_name = var[5:-1] + if var_name not in os.environ: + message(context, 'Unknown variable: {}'.format(var), 'warn') + continue + replace_with = os.environ[var_name] + output = output.replace(var, replace_with) + + return output + def cleaning_output(context, output): """ @@ -410,6 +426,10 @@ def normalize_path(context, working_path, path_to_normalize, remove_relative=Tru :rtype: str """ + # path_to_normalize might contain special vars in the form of $(var) - expand them + path_to_normalize = replace_vs_vars_with_cmake_vars(context, path_to_normalize) + path_to_normalize = expand_cmake_env_vars(context, path_to_normalize) + joined_path = set_native_slash( os.path.join(working_path, ntpath.normpath(path_to_normalize.strip())) ) diff --git a/cmake_converter/visual_studio/solution.py b/cmake_converter/visual_studio/solution.py index 1204c4d..616f949 100644 --- a/cmake_converter/visual_studio/solution.py +++ b/cmake_converter/visual_studio/solution.py @@ -4,6 +4,7 @@ # Copyright (c) 2016-2020: # Matthieu Estrada, ttamalfor@gmail.com # Pavel Liavonau, liavonlida@gmail.com +# Keon Amini, keon.a380@gmail.com # # This file is part of (CMakeConverter). # @@ -303,7 +304,6 @@ def convert_solution(self, project_context, sln_file_path): """ Routine converts Visual studio solution into set of CMakeLists.txt scripts """ - message( project_context, '------- Started parsing solution {} -------'.format(sln_file_path), '' )