diff options
-rw-r--r-- | lldb/scripts/swig_bot_lib/client.py | 32 | ||||
-rw-r--r-- | lldb/scripts/swig_bot_lib/local.py | 25 | ||||
-rw-r--r-- | lldb/scripts/swig_bot_lib/remote.py (renamed from lldb/scripts/swig_bot_lib/config.py) | 15 | ||||
-rw-r--r-- | lldb/scripts/swig_bot_lib/server.py | 38 |
4 files changed, 74 insertions, 36 deletions
diff --git a/lldb/scripts/swig_bot_lib/client.py b/lldb/scripts/swig_bot_lib/client.py index 6d21aaff4d9..80a3114ddb8 100644 --- a/lldb/scripts/swig_bot_lib/client.py +++ b/lldb/scripts/swig_bot_lib/client.py @@ -11,6 +11,7 @@ from __future__ import print_function # Python modules import argparse +import io import logging import os import socket @@ -23,8 +24,8 @@ from lldbsuite.support import fs from lldbsuite.support import sockutil # package imports -from . import config from . import local +from . import remote default_ip = "127.0.0.1" default_port = 8537 @@ -152,21 +153,32 @@ def run(args): if not os.path.isfile(options.swig_executable): logging.error("Swig executable '{}' does not exist." .format(options.swig_executable)) - gen_options = local.GenOptions() - gen_options.languages = options.languages - gen_options.src_root = options.src_root - gen_options.target_dir = options.target_dir - gen_options.swig_executable = options.swig_executable - local.generate(gen_options) + config = local.LocalConfig() + config.languages = options.languages + config.src_root = options.src_root + config.target_dir = options.target_dir + config.swig_executable = options.swig_executable + local.generate(config) else: logging.info("swig bot client using remote generation with server '{}'" .format(options.remote)) connection = None try: - config_json = config.generate_config_json(options) - packed_input = local.pack_archive(config_json, options) + config = remote.generate_config(options.languages) + logging.debug("Generated config json {}".format(config)) + inputs = [("include/lldb", ".h"), + ("include/lldb/API", ".h"), + ("scripts", ".swig"), + ("scripts/Python", ".swig"), + ("scripts/interface", ".i")] + zip_data = io.BytesIO() + packed_input = local.pack_archive(zip_data, options.src_root, inputs) + logging.info("(null) -> config.json") + packed_input.writestr("config.json", config) + packed_input.close() + connection = establish_remote_connection(options.remote) - response = transmit_data(connection, packed_input) + response = transmit_data(connection, zip_data.getvalue()) logging.debug("Received {} byte response.".format(len(response))) finally: if connection is not None: diff --git a/lldb/scripts/swig_bot_lib/local.py b/lldb/scripts/swig_bot_lib/local.py index 974cd35bb7e..9ee04c1d59d 100644 --- a/lldb/scripts/swig_bot_lib/local.py +++ b/lldb/scripts/swig_bot_lib/local.py @@ -23,34 +23,32 @@ import zipfile # LLDB modules import use_lldb_suite -class GenOptions(object): +# Package imports +from lldbsuite.support import fs + +class LocalConfig(object): src_root = None target_dir = None languages = None swig_executable = None -def pack_archive(config_json, options): +def pack_archive(bytes_io, src_root, filters): logging.info("Creating input file package...") - zip_data = io.BytesIO() zip_file = None try: # It's possible that a custom-built interpreter will not have the # standard zlib module. If so, we can only store, not compress. By # try to compress since we usually have a standard Python distribution. - zip_file = zipfile.ZipFile(zip_data, mode='w', + zip_file = zipfile.ZipFile(bytes_io, mode='w', compression=zipfile.ZIP_DEFLATED) except RuntimeError: - zip_file = zipfile.ZipFile(zip_data, mode='w', + zip_file = zipfile.ZipFile(bytes_io, mode='w', compression=zipfile.ZIP_STORED) - filters = [("include/lldb", ".h"), - ("scripts", ".swig"), - ("scripts/Python", ".swig"), - ("scripts/interface", ".i")] def filter_func(t): subfolder = t[0] ext = t[1] - full_path = os.path.normpath(os.path.join(options.src_root, subfolder)) + full_path = os.path.normpath(os.path.join(src_root, subfolder)) candidates = [os.path.normpath(os.path.join(full_path, f)) for f in os.listdir(full_path)] actual = filter( @@ -65,14 +63,11 @@ def pack_archive(config_json, options): for file in files: relative_path = os.path.normpath(os.path.join(subfolder, file)) full_path = os.path.normpath( - os.path.join(options.src_root, relative_path)) + os.path.join(src_root, relative_path)) logging.info("{} -> {}".format(full_path, relative_path)) zip_file.write(full_path, relative_path) - logging.info("(null) -> config.json") - zip_file.writestr("config.json", config_json) - zip_file.close() - return zip_data.getvalue() + return zip_file def unpack_archive(subfolder, archive_bytes): tempfolder = os.path.join(tempfile.gettempdir(), subfolder) diff --git a/lldb/scripts/swig_bot_lib/config.py b/lldb/scripts/swig_bot_lib/remote.py index 36ec4173c04..74edb67f69c 100644 --- a/lldb/scripts/swig_bot_lib/config.py +++ b/lldb/scripts/swig_bot_lib/remote.py @@ -2,7 +2,7 @@ """ Shared functionality used by `client` and `server` when dealing with -configuration data +remote transmission """ # Future imports @@ -20,12 +20,11 @@ import sys # LLDB modules import use_lldb_suite -# package imports -from . import local - -def generate_config_json(options): - config = {"languages": options.languages} +def generate_config(languages): + config = {"languages": languages} return json.dumps(config) -def parse_config_json(option_json): - return json.loads(option_json) +def parse_config(json_reader): + json_data = json_reader.read() + options_dict = json.loads(json_data) + return options_dict diff --git a/lldb/scripts/swig_bot_lib/server.py b/lldb/scripts/swig_bot_lib/server.py index b973ca9bcf1..b7f14cfd599 100644 --- a/lldb/scripts/swig_bot_lib/server.py +++ b/lldb/scripts/swig_bot_lib/server.py @@ -11,6 +11,7 @@ from __future__ import print_function # Python modules import argparse +import io import logging import os import select @@ -23,10 +24,12 @@ import traceback # LLDB modules import use_lldb_suite +from lldbsuite.support import fs from lldbsuite.support import sockutil # package imports from . import local +from . import remote default_port = 8537 @@ -40,6 +43,12 @@ def process_args(args): default=default_port, help=("The local port to bind to")) + parser.add_argument( + "--swig-executable", + action="store", + default=fs.find_executable("swig"), + dest="swig_executable") + # Process args. return parser.parse_args(args) @@ -75,9 +84,31 @@ def accept_once(sock, options): pack_location = local.unpack_archive("swig-bot", data) logging.debug("Successfully unpacked archive...") - logging.info("Sending {} byte response".format(len(data))) - client.sendall(struct.pack("!I", len(data))) - client.sendall(data) + config_file = os.path.normpath(os.path.join(pack_location, + "config.json")) + parsed_config = remote.parse_config(io.open(config_file)) + config = local.LocalConfig() + config.languages = parsed_config["languages"] + config.swig_executable = options.swig_executable + config.src_root = pack_location + config.target_dir = os.path.normpath( + os.path.join(config.src_root, "output")) + logging.info( + "Running swig. languages={}, swig={}, src_root={}, target={}" + .format(config.languages, config.swig_executable, + config.src_root, config.target_dir)) + + local.generate(config) + logging.debug("Finished running swig. Packaging up output") + zip_data = io.BytesIO() + zip_file = local.pack_archive(zip_data, + config.target_dir, + [(".", None)]) + zip_file.close() + response_data = zip_data.getvalue() + logging.info("Sending {} byte response".format(len(response_data))) + client.sendall(struct.pack("!I", len(response_data))) + client.sendall(response_data) finally: if pack_location is not None: logging.debug("Removing temporary folder {}" @@ -95,6 +126,7 @@ def accept_loop(sock, options): def run(args): options = process_args(args) + print(options) sock = initialize_listening_socket(options) accept_loop(sock, options) return options |