[Lldb-commits] [lldb] r253346 - Added --find-swig option to allow searching for swig in path or other likely locations.
Todd Fiala via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 17 09:13:07 PST 2015
Author: tfiala
Date: Tue Nov 17 11:13:06 2015
New Revision: 253346
URL: http://llvm.org/viewvc/llvm-project?rev=253346&view=rev
Log:
Added --find-swig option to allow searching for swig in path or other likely locations.
Modified:
lldb/trunk/scripts/prepare_bindings.py
Modified: lldb/trunk/scripts/prepare_bindings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/prepare_bindings.py?rev=253346&r1=253345&r2=253346&view=diff
==============================================================================
--- lldb/trunk/scripts/prepare_bindings.py (original)
+++ lldb/trunk/scripts/prepare_bindings.py Tue Nov 17 11:13:06 2015
@@ -13,6 +13,7 @@ to see a description of the supported co
import argparse
import logging
import os
+import platform
import sys
@@ -117,6 +118,13 @@ def process_args(args):
"Configuration build dir, will use python module path "
"if unspecified."))
parser.add_argument(
+ "--find-swig",
+ action="store_true",
+ help=(
+ "Indicates the swig executable should be searched for "
+ "if not eplicitly provided. Either this or the explicit "
+ "swig executable option must be provided."))
+ parser.add_argument(
"--framework",
action="store_true",
help="Prepare as OS X-style framework.")
@@ -170,6 +178,63 @@ def process_args(args):
return options
+def find_file_in_paths(paths, exe_basename):
+ """Returns the full exe path for the first path match.
+
+ @params paths the list of directories to search for the exe_basename
+ executable
+ @params exe_basename the name of the file for which to search.
+ e.g. "swig" or "swig.exe".
+
+ @return the full path to the executable if found in one of the
+ given paths; otherwise, returns None.
+ """
+ for path in paths:
+ trial_exe_path = os.path.join(path, exe_basename)
+ if os.path.exists(trial_exe_path):
+ return os.path.normcase(trial_exe_path)
+ return None
+
+
+def find_swig_executable(options):
+ """Finds the swig executable in the PATH or known good locations.
+
+ Replaces options.swig_executable with the full swig executable path.
+ """
+ # Figure out what we're looking for.
+ if platform.system() == 'Windows':
+ exe_basename = "swig.exe"
+ extra_dirs = []
+ else:
+ exe_basename = "swig"
+ extra_dirs = ["/usr/local/bin"]
+
+ # Figure out what paths to check.
+ path_env = os.environ.get("PATH", None)
+ if path_env is not None:
+ paths_to_check = path_env.split(os.path.pathsep)
+ else:
+ paths_to_check = []
+
+ # 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)
+
+ # 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)
+
+
def main(args):
"""Drives the main script preparation steps.
@@ -179,6 +244,17 @@ def main(args):
options = process_args(args)
logging.debug("Processed args: options=%s", options)
+ # 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)
+ else:
+ logging.error(
+ "The --find-swig option must be specified "
+ "when the swig executable location is not "
+ "explicitly provided.")
+ sys.exit(-12)
+
# Check if the swig file exists.
swig_path = os.path.normcase(
os.path.join(options.src_root, "scripts", "lldb.swig"))
More information about the lldb-commits
mailing list