2015-11-25 05:35:17 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2015-11-25 05:35:32 +08:00
|
|
|
"""
|
|
|
|
SWIG generation top-level script. Supports both local and remote generation
|
|
|
|
of SWIG bindings for multiple languages.
|
|
|
|
"""
|
|
|
|
|
2015-11-25 05:35:17 +08:00
|
|
|
# Python modules
|
2015-11-25 05:35:32 +08:00
|
|
|
import argparse
|
|
|
|
import logging
|
2015-11-25 05:35:17 +08:00
|
|
|
import sys
|
2015-11-25 05:35:32 +08:00
|
|
|
import traceback
|
2015-11-25 05:35:17 +08:00
|
|
|
|
|
|
|
# LLDB modules
|
|
|
|
import use_lldb_suite
|
|
|
|
|
2015-12-03 03:00:52 +08:00
|
|
|
# swig_bot modules
|
|
|
|
from swig_bot_lib import client
|
|
|
|
from swig_bot_lib import server
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-25 05:35:32 +08:00
|
|
|
def process_args(args):
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Run swig-bot client or server.')
|
|
|
|
|
2015-12-03 03:00:52 +08:00
|
|
|
# Create and populate subparser arguments for when swig_bot is
|
|
|
|
# run in client or server mode
|
|
|
|
subparsers = parser.add_subparsers(
|
|
|
|
help="Pass --help to a sub-command to print detailed usage")
|
|
|
|
client_parser = subparsers.add_parser("client",
|
|
|
|
help="Run SWIG generation client")
|
|
|
|
client.add_subparser_args(client_parser)
|
|
|
|
client_parser.set_defaults(func=run_client)
|
|
|
|
|
|
|
|
server_parser = subparsers.add_parser("server",
|
|
|
|
help="Run SWIG generation server")
|
|
|
|
server.add_subparser_args(server_parser)
|
|
|
|
server_parser.set_defaults(func=run_server)
|
2015-11-25 05:35:32 +08:00
|
|
|
|
|
|
|
# Arguments to control logging verbosity.
|
|
|
|
parser.add_argument(
|
|
|
|
"--verbose", "-v",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Increase logging verbosity level.")
|
|
|
|
|
2015-12-03 03:00:52 +08:00
|
|
|
options = parser.parse_args(args)
|
2015-11-25 05:35:32 +08:00
|
|
|
# Set logging level.
|
|
|
|
if options.verbose:
|
|
|
|
log_level = logging.DEBUG
|
|
|
|
else:
|
|
|
|
log_level = logging.NOTSET
|
|
|
|
logging.basicConfig(level=log_level)
|
|
|
|
logging.info("logging is using level: %d", log_level)
|
|
|
|
|
2015-12-03 03:00:52 +08:00
|
|
|
return options
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-12-03 03:00:52 +08:00
|
|
|
def run_client(options):
|
|
|
|
logging.info("Running swig_bot in client mode")
|
|
|
|
client.finalize_subparser_options(options)
|
|
|
|
client.run(options)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-12-03 03:00:52 +08:00
|
|
|
def run_server(options):
|
|
|
|
logging.info("Running swig_bot in server mode")
|
|
|
|
server.finalize_subparser_options(options)
|
|
|
|
server.run(options)
|
2015-11-25 05:35:32 +08:00
|
|
|
|
2015-11-25 05:35:17 +08:00
|
|
|
if __name__ == "__main__":
|
2015-12-03 03:00:52 +08:00
|
|
|
options = process_args(sys.argv[1:])
|
2015-11-25 05:35:32 +08:00
|
|
|
try:
|
2015-12-03 03:00:52 +08:00
|
|
|
if options.func is None:
|
2015-11-25 05:35:32 +08:00
|
|
|
logging.error(
|
|
|
|
"Unknown mode specified. Expected client or server.")
|
|
|
|
sys.exit(-1)
|
2015-12-03 03:00:52 +08:00
|
|
|
else:
|
|
|
|
options.func(options)
|
2015-11-25 05:35:40 +08:00
|
|
|
except KeyboardInterrupt as e:
|
|
|
|
logging.info("Ctrl+C received. Shutting down...")
|
|
|
|
sys.exit(-1)
|
2015-11-25 05:35:32 +08:00
|
|
|
except Exception as e:
|
|
|
|
error = traceback.format_exc()
|
|
|
|
logging.error("An error occurred running swig-bot.")
|
|
|
|
logging.error(error)
|