[Lldb-commits] [lldb] r254340 - Have swig_bot actually run swig, and send back the output.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 30 14:31:14 PST 2015


Author: zturner
Date: Mon Nov 30 16:31:13 2015
New Revision: 254340

URL: http://llvm.org/viewvc/llvm-project?rev=254340&view=rev
Log:
Have swig_bot actually run swig, and send back the output.

Added:
    lldb/trunk/scripts/swig_bot_lib/remote.py
      - copied, changed from r254338, lldb/trunk/scripts/swig_bot_lib/config.py
Removed:
    lldb/trunk/scripts/swig_bot_lib/config.py
Modified:
    lldb/trunk/scripts/swig_bot_lib/client.py
    lldb/trunk/scripts/swig_bot_lib/local.py
    lldb/trunk/scripts/swig_bot_lib/server.py

Modified: lldb/trunk/scripts/swig_bot_lib/client.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/swig_bot_lib/client.py?rev=254340&r1=254339&r2=254340&view=diff
==============================================================================
--- lldb/trunk/scripts/swig_bot_lib/client.py (original)
+++ lldb/trunk/scripts/swig_bot_lib/client.py Mon Nov 30 16:31:13 2015
@@ -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:

Removed: lldb/trunk/scripts/swig_bot_lib/config.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/swig_bot_lib/config.py?rev=254339&view=auto
==============================================================================
--- lldb/trunk/scripts/swig_bot_lib/config.py (original)
+++ lldb/trunk/scripts/swig_bot_lib/config.py (removed)
@@ -1,31 +0,0 @@
-#!/usr/bin/env python
-
-"""
-Shared functionality used by `client` and `server` when dealing with
-configuration data
-"""
-
-# Future imports
-from __future__ import absolute_import
-from __future__ import print_function
-
-# Python modules
-import json
-import logging
-import os
-import socket
-import struct
-import sys
-
-# LLDB modules
-import use_lldb_suite
-
-# package imports
-from . import local
-
-def generate_config_json(options):
-    config = {"languages": options.languages}
-    return json.dumps(config)
-
-def parse_config_json(option_json):
-    return json.loads(option_json)

Modified: lldb/trunk/scripts/swig_bot_lib/local.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/swig_bot_lib/local.py?rev=254340&r1=254339&r2=254340&view=diff
==============================================================================
--- lldb/trunk/scripts/swig_bot_lib/local.py (original)
+++ lldb/trunk/scripts/swig_bot_lib/local.py Mon Nov 30 16:31:13 2015
@@ -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)

Copied: lldb/trunk/scripts/swig_bot_lib/remote.py (from r254338, lldb/trunk/scripts/swig_bot_lib/config.py)
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/swig_bot_lib/remote.py?p2=lldb/trunk/scripts/swig_bot_lib/remote.py&p1=lldb/trunk/scripts/swig_bot_lib/config.py&r1=254338&r2=254340&rev=254340&view=diff
==============================================================================
--- lldb/trunk/scripts/swig_bot_lib/config.py (original)
+++ lldb/trunk/scripts/swig_bot_lib/remote.py Mon Nov 30 16:31:13 2015
@@ -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

Modified: lldb/trunk/scripts/swig_bot_lib/server.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/swig_bot_lib/server.py?rev=254340&r1=254339&r2=254340&view=diff
==============================================================================
--- lldb/trunk/scripts/swig_bot_lib/server.py (original)
+++ lldb/trunk/scripts/swig_bot_lib/server.py Mon Nov 30 16:31:13 2015
@@ -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




More information about the lldb-commits mailing list