Added --find-swig option to allow searching for swig in path or other likely locations.

llvm-svn: 253346
This commit is contained in:
Todd Fiala 2015-11-17 17:13:06 +00:00
parent a90e745109
commit 9af81570c7
1 changed files with 76 additions and 0 deletions

View File

@ -13,6 +13,7 @@ to see a description of the supported command line arguments.
import argparse
import logging
import os
import platform
import sys
@ -116,6 +117,13 @@ def process_args(args):
help=(
"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",
@ -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"))