aboutsummaryrefslogtreecommitdiff
path: root/scripts/Python/prepare_binding_Python.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Python/prepare_binding_Python.py')
-rw-r--r--scripts/Python/prepare_binding_Python.py62
1 files changed, 33 insertions, 29 deletions
diff --git a/scripts/Python/prepare_binding_Python.py b/scripts/Python/prepare_binding_Python.py
index 28fc3e5bc7fc..cf64d49504f3 100644
--- a/scripts/Python/prepare_binding_Python.py
+++ b/scripts/Python/prepare_binding_Python.py
@@ -18,8 +18,10 @@ import subprocess
import sys
import platform
+
class SwigSettings(object):
"""Provides a single object to represent swig files and settings."""
+
def __init__(self):
self.extensions_file = None
self.header_files = None
@@ -194,34 +196,37 @@ def do_swig_rebuild(options, dependency_file, config_build_dir, settings):
temp_dep_file_path = dependency_file + ".tmp"
# Build the SWIG args list
- command = [
- options.swig_executable,
- "-c++",
- "-shadow",
- "-python",
- "-threads",
- "-I\"%s\"" % os.path.normcase(
- os.path.join(options.src_root, "include")),
- "-I\"%s\"" % os.path.normcase("./."),
- "-D__STDC_LIMIT_MACROS",
- "-D__STDC_CONSTANT_MACROS"]
- if options.target_platform == "Darwin":
- command.append("-D__APPLE__")
- if options.generate_dependency_file:
- command.append("-MMD -MF \"%s\"" % temp_dep_file_path)
- command.extend([
- "-outdir", "\"%s\"" % config_build_dir,
- "-o", "\"%s\"" % settings.output_file,
- "\"%s\"" % settings.input_file
- ])
- logging.info("running swig with: %s", command)
+ is_darwin = options.target_platform == "Darwin"
+ gen_deps = options.generate_dependency_file
+ darwin_extras = ["-D__APPLE__"] if is_darwin else []
+ deps_args = ["-MMD", "-MF", temp_dep_file_path] if gen_deps else []
+ command = ([
+ options.swig_executable,
+ "-c++",
+ "-shadow",
+ "-python",
+ "-threads",
+ "-I" + os.path.normpath(os.path.join(options.src_root, "include")),
+ "-I" + os.path.curdir,
+ "-D__STDC_LIMIT_MACROS",
+ "-D__STDC_CONSTANT_MACROS"
+ ]
+ + darwin_extras
+ + deps_args
+ + [
+ "-outdir", config_build_dir,
+ "-o", settings.output_file,
+ settings.input_file
+ ]
+ )
+ logging.info("running swig with: %r", command)
# Execute swig
process = subprocess.Popen(
- ' '.join(command),
+ command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
- shell=True)
+ )
# Wait for SWIG process to terminate
swig_stdout, swig_stderr = process.communicate()
return_code = process.returncode
@@ -262,15 +267,15 @@ def run_python_script(script_and_args):
@param script_and_args the python script to execute, along with
the command line arguments to pass to it.
"""
- command_line = "%s %s" % (sys.executable, script_and_args)
- process = subprocess.Popen(command_line, shell=True)
+ command = [sys.executable] + script_and_args
+ process = subprocess.Popen(command)
script_stdout, script_stderr = process.communicate()
return_code = process.returncode
if return_code != 0:
- logging.error("failed to run '%s': %s", command_line, script_stderr)
+ logging.error("failed to run %r: %r", command, script_stderr)
sys.exit(return_code)
else:
- logging.info("ran script '%s'", command_line)
+ logging.info("ran script %r'", command)
if script_stdout is not None:
logging.info("output: %s", script_stdout)
@@ -292,8 +297,7 @@ def do_modify_python_lldb(options, config_build_dir):
logging.error("failed to find python script: '%s'", script_path)
sys.exit(-11)
- script_invocation = "%s %s" % (script_path, config_build_dir)
- run_python_script(script_invocation)
+ run_python_script([script_path, config_build_dir])
def get_python_module_path(options):