diff options
Diffstat (limited to 'lldb/scripts/swig_bot_lib/local.py')
-rw-r--r-- | lldb/scripts/swig_bot_lib/local.py | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/lldb/scripts/swig_bot_lib/local.py b/lldb/scripts/swig_bot_lib/local.py index 443be258424..6ba5e43e473 100644 --- a/lldb/scripts/swig_bot_lib/local.py +++ b/lldb/scripts/swig_bot_lib/local.py @@ -1,5 +1,10 @@ #!/usr/bin/env python +""" +Shared functionality used by `client` and `server` when generating or preparing +to generate SWIG on the local machine. +""" + # Future imports from __future__ import absolute_import from __future__ import print_function @@ -7,14 +12,57 @@ from __future__ import print_function # Python modules import argparse import imp +import io import logging import os import subprocess import sys +import zipfile # LLDB modules import use_lldb_suite +def pack_input(options): + 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', + compression=zipfile.ZIP_DEFLATED) + except RuntimeError: + zip_file = zipfile.ZipFile(zip_data, 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)) + candidates = [os.path.normpath(os.path.join(full_path, f)) + for f in os.listdir(full_path)] + actual = filter( + lambda f : os.path.isfile(f) and os.path.splitext(f)[1] == ext, + candidates) + return (subfolder, map(lambda f : os.path.basename(f), actual)) + archive_entries = map(filter_func, filters) + + for entry in archive_entries: + subfolder = entry[0] + files = entry[1] + 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)) + logging.info("{} -> {}".format(full_path, relative_path)) + zip_file.write(full_path, relative_path) + return zip_data.getvalue() + def generate(options): include_folder = os.path.join(options.src_root, "include") in_file = os.path.join(options.src_root, "scripts", "lldb.swig") @@ -43,7 +91,8 @@ def generate(options): in_file ]) - logging.info("generating swig {} bindings into {}".format(lang, out_dir)) + logging.info("generating swig {} bindings into {}" + .format(lang, out_dir)) logging.debug("swig command line: {}".format(swig_command)) try: # Execute swig @@ -54,5 +103,6 @@ def generate(options): if swig_output is not None and len(swig_output) > 0: logging.info("swig output: %s", swig_output) except subprocess.CalledProcessError as e: - logging.error("An error occurred executing swig. returncode={}".format(e.returncode)) + logging.error("An error occurred executing swig. returncode={}" + .format(e.returncode)) logging.error(e.output) |