Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS path environment variables now correctly evaluated #156

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions cmake_converter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
#
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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()))
)
Expand Down
2 changes: 1 addition & 1 deletion cmake_converter/visual_studio/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
#
Expand Down Expand Up @@ -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), ''
)
Expand Down