Skip to content

Commit

Permalink
update autocmake
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Apr 15, 2020
1 parent b144bac commit 42ba8e4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
39 changes: 31 additions & 8 deletions cmake/autocmake/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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)


Expand All @@ -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.
"""
Expand All @@ -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)
2 changes: 1 addition & 1 deletion cmake/autocmake/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ cmake_command = '{0} -H{1}'.format(gen_cmake_command(options, arguments), root_d


# run cmake
configure.configure(root_directory, build_path, cmake_command, arguments['--show'])
configure.configure(root_directory, build_path, cmake_command, arguments)

0 comments on commit 42ba8e4

Please sign in to comment.