prepare_bindings.py: enable static bindings

Added a new flag, --allow-static-binding.  When specified,
if (and only if) the swig binary cannot be found, then the
LLDBWrapPython.cpp and lldb.py from the
scripts/Python/{static-binding-dir} are copied into the place where
swig would have generated them.

{static-binding-dir} defaults to static-binding, and can be
overridden with the --static-binding-dir command line argument.

The static bindings checked in are from r253424.

llvm-svn: 253448
This commit is contained in:
Todd Fiala 2015-11-18 08:52:33 +00:00
parent 5574730454
commit d434a1d3e0
5 changed files with 83996 additions and 20 deletions

View File

@ -6226,7 +6226,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/bash;
shellScript = "/usr/bin/python $SRCROOT/scripts/prepare_bindings.py --find-swig --framework --src-root $SRCROOT --target-dir $TARGET_BUILD_DIR --config-build-dir $CONFIGURATION_BUILD_DIR";
shellScript = "/usr/bin/python $SRCROOT/scripts/prepare_bindings.py --find-swig --framework --src-root $SRCROOT --target-dir $TARGET_BUILD_DIR --config-build-dir $CONFIGURATION_BUILD_DIR --allow-static-binding";
};
4959511A1A1ACE9500F6F8FC /* Install Clang compiler headers */ = {
isa = PBXShellScriptBuildPhase;

View File

@ -251,6 +251,42 @@ def do_swig_rebuild(options, dependency_file, config_build_dir, settings):
sys.exit(-10)
def copy_static_bindings(options, config_build_dir, settings):
"""Copies the static Python bindings over to the build dir.
"""
# Copy the LLDBWrapPython.cpp C++ binding file impl over.
lldb_wrap_python_src_path = os.path.join(
options.src_root,
"scripts",
"Python",
options.static_binding_dir,
"LLDBWrapPython.cpp")
if not os.path.exists(lldb_wrap_python_src_path):
logging.error(
"failed to find static Python binding .cpp file at '%s'",
lldb_wrap_python_src_path)
sys.exit(-12)
shutil.copyfile(lldb_wrap_python_src_path, settings.output_file)
# Copy the lldb.py impl over.
lldb_py_src_path = os.path.join(
options.src_root,
"scripts",
"Python",
options.static_binding_dir,
"lldb.py")
if not os.path.exists(lldb_py_src_path):
logging.error(
"failed to find static Python binding .py file at '%s'",
lldb_py_src_path)
sys.exit(-13)
lldb_py_dest_path = os.path.join(
os.path.dirname(settings.output_file),
"lldb.py")
shutil.copyfile(lldb_py_src_path, lldb_py_dest_path)
def run_python_script(script_and_args):
"""Runs a python script, logging appropriately.
@ -418,14 +454,21 @@ def main(options):
"Skipping Python binding generation: everything is up to date")
return
# Generate the Python binding with swig.
logging.info("Python binding is out of date, regenerating")
do_swig_rebuild(options, dependency_file, config_build_dir, settings)
if options.generate_dependency_file:
return
# Generate the Python binding with swig, or use the static bindings if no swig.
if not options.swig_executable or not os.path.exists(options.swig_executable):
# Copy over the static bindings. We capture the the modified (i.e. post-processed)
# binding, so we don't do the modify step here - the modifications have
# already been applied.
copy_static_bindings(options, config_build_dir, settings)
else:
# Generate the bindings with swig.
logging.info("Python binding is out of date, regenerating")
do_swig_rebuild(options, dependency_file, config_build_dir, settings)
if options.generate_dependency_file:
return
# Post process the swig-generated file.
do_modify_python_lldb(options, config_build_dir)
# Post process the swig-generated file.
do_modify_python_lldb(options, config_build_dir)
# This script can be called by another Python script by calling the main()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -158,6 +158,19 @@ def process_args(args):
"Specifies the build dir where the language binding "
"should be placed"))
group = parser.add_argument_group("static binding usage")
group.add_argument(
"--allow-static-binding",
action="store_true",
help=(
"Specify the pre-baked binding can be used if "
"swig cannot be found."))
group.add_argument(
"--static-binding-dir",
default="static-binding",
help="script-relative directory for appropriate static bindings"
)
# Process args.
options = parser.parse_args(args)
@ -196,9 +209,14 @@ def find_file_in_paths(paths, exe_basename):
return None
def find_swig_executable(options):
def find_swig_executable(options, must_exist):
"""Finds the swig executable in the PATH or known good locations.
:param options the command line options returned by argparse.
:param must_exist if True, this method exits the program if
swig is not found; otherwise, always returns whether swig is found.
Replaces options.swig_executable with the full swig executable path.
"""
# Figure out what we're looking for.
@ -219,20 +237,28 @@ def find_swig_executable(options):
# Add in the extra dirs
paths_to_check.extend(extra_dirs)
if len(paths_to_check) < 1:
logging.error(
"swig executable was not specified, PATH has no "
"contents, and there are no extra directories to search")
sys.exit(-6)
if must_exist:
logging.error(
"swig executable was not specified, PATH has no "
"contents, and there are no extra directories to search")
sys.exit(-6)
else:
logging.info("failed to find swig: no paths available")
return
# Find the swig executable
options.swig_executable = find_file_in_paths(paths_to_check, exe_basename)
if not options.swig_executable or len(options.swig_executable) < 1:
logging.error(
"failed to find exe='%s' in paths='%s'",
exe_basename,
paths_to_check)
sys.exit(-6)
logging.info("found swig executable: %s", options.swig_executable)
if must_exist:
logging.error(
"failed to find exe='%s' in paths='%s'",
exe_basename,
paths_to_check)
sys.exit(-6)
else:
logging.info("%s not found in paths %s", exe_basename, paths_to_check)
else:
logging.info("found swig executable: %s", options.swig_executable)
def main(args):
@ -247,7 +273,8 @@ def main(args):
# Ensure we have a swig executable.
if not options.swig_executable or len(options.swig_executable) == 0:
if options.find_swig:
find_swig_executable(options)
must_exist = not options.allow_static_binding
find_swig_executable(options, must_exist)
else:
logging.error(
"The --find-swig option must be specified "