Merge pull request #264 from bast/radovan/quotes-workaround
preserve quotes in setup_command; closes #169
This commit is contained in:
commit
85a4d068b7
@ -52,7 +52,29 @@ def setup_build_path(build_path):
|
||||
os.makedirs(build_path, 0o755)
|
||||
|
||||
|
||||
def run_cmake(command, build_path, default_build_path):
|
||||
def add_quotes_to_argv(argv, arguments):
|
||||
"""
|
||||
This function tries to solve this problem:
|
||||
https://stackoverflow.com/questions/19120247/python-sys-argv-to-preserve-or
|
||||
|
||||
The problem is that sys.argv has been stripped of quotes by the shell but
|
||||
docopt's arguments contains quotes.
|
||||
|
||||
So what we do is cycle through all docopt arguments: if they are also
|
||||
present in sys.argv and contain spaces, we add quotes.
|
||||
"""
|
||||
setup_command = ' '.join(argv[:])
|
||||
|
||||
for k, v in arguments.items():
|
||||
if isinstance(v, str):
|
||||
if ' ' in v:
|
||||
if v in setup_command:
|
||||
setup_command = setup_command.replace(v, '"{}"'.format(v))
|
||||
|
||||
return setup_command
|
||||
|
||||
|
||||
def run_cmake(command, build_path, default_build_path, arguments):
|
||||
"""
|
||||
Execute CMake command.
|
||||
"""
|
||||
@ -88,7 +110,8 @@ def run_cmake(command, build_path, default_build_path):
|
||||
configuration_successful = configuring_done and generating_done and build_files_written
|
||||
|
||||
if configuration_successful:
|
||||
save_setup_command(sys.argv, build_path)
|
||||
setup_command = add_quotes_to_argv(sys.argv, arguments)
|
||||
save_setup_command(setup_command, build_path)
|
||||
print_build_help(build_path, default_build_path)
|
||||
|
||||
|
||||
@ -105,16 +128,16 @@ def print_build_help(build_path, default_build_path):
|
||||
print(' $ make')
|
||||
|
||||
|
||||
def save_setup_command(argv, build_path):
|
||||
def save_setup_command(setup_command, build_path):
|
||||
"""
|
||||
Save setup command to a file.
|
||||
"""
|
||||
file_name = os.path.join(build_path, 'setup_command')
|
||||
with open(file_name, 'w') as f:
|
||||
f.write(' '.join(argv[:]) + '\n')
|
||||
f.write(setup_command + '\n')
|
||||
|
||||
|
||||
def configure(root_directory, build_path, cmake_command, only_show):
|
||||
def configure(root_directory, build_path, cmake_command, arguments):
|
||||
"""
|
||||
Main configure function.
|
||||
"""
|
||||
@ -126,12 +149,12 @@ def configure(root_directory, build_path, cmake_command, only_show):
|
||||
# deal with build path
|
||||
if build_path is None:
|
||||
build_path = default_build_path
|
||||
if not only_show:
|
||||
if not arguments['--show']:
|
||||
setup_build_path(build_path)
|
||||
|
||||
cmake_command += ' -B' + build_path
|
||||
print('{0}\n'.format(cmake_command))
|
||||
if only_show:
|
||||
if arguments['--show']:
|
||||
sys.exit(0)
|
||||
|
||||
run_cmake(cmake_command, build_path, default_build_path)
|
||||
run_cmake(cmake_command, build_path, default_build_path, arguments)
|
||||
|
@ -150,7 +150,7 @@ def gen_setup(config, default_build_type, relative_path, setup_script_name):
|
||||
s.append("cmake_command = '{0} -H{1}'.format(gen_cmake_command(options, arguments), root_directory)")
|
||||
s.append("\n")
|
||||
s.append("# run cmake")
|
||||
s.append("configure.configure(root_directory, build_path, cmake_command, arguments['--show'])")
|
||||
s.append("configure.configure(root_directory, build_path, cmake_command, arguments)")
|
||||
|
||||
return s
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user