zturner updated this revision to Diff 40852.
zturner added a comment.

Fixed a few minor issues


http://reviews.llvm.org/D14896

Files:
  scripts/swig_bot.py
  scripts/swig_bot_lib/__init__.py
  scripts/swig_bot_lib/client.py
  scripts/swig_bot_lib/local.py
  scripts/swig_bot_lib/server.py

Index: scripts/swig_bot_lib/server.py
===================================================================
--- /dev/null
+++ scripts/swig_bot_lib/server.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+# Future imports
+from __future__ import absolute_import
+from __future__ import print_function
+
Index: scripts/swig_bot_lib/local.py
===================================================================
--- /dev/null
+++ scripts/swig_bot_lib/local.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+
+# Future imports
+from __future__ import absolute_import
+from __future__ import print_function
+
+# Python modules
+import argparse
+import imp
+import logging
+import os
+import subprocess
+import sys
+
+# LLDB modules
+import use_lldb_suite
+
+def generate(options):
+    include_folder = os.path.join(options.src_root, "include")
+    in_file = os.path.join(options.src_root, "scripts", "lldb.swig")
+    include_folder = os.path.normcase(include_folder)
+
+    for lang in options.languages:
+        lang = lang.lower()
+        out_dir = os.path.join(options.target_dir, lang.title())
+        if not os.path.exists(out_dir):
+            os.makedirs(out_dir)
+        out_file = os.path.join(out_dir, "LLDBWrap{}".format(lang.title()))
+        swig_command = [
+            options.swig_executable,
+            "-c++",
+        ]
+        swig_command.append("-" + lang)
+        if lang == "python":
+            swig_command.append("-threads")
+
+        swig_command.extend([
+            "-I" + include_folder,
+            "-D__STDC_LIMIT_MACROS",
+            "-D__STDC_CONSTANT_MACROS",
+            "-outdir", out_dir,
+            "-o", out_file,
+            in_file
+        ])
+
+        logging.info("generating swig {} bindings into {}".format(lang, out_dir))
+        logging.debug("swig command line: {}".format(swig_command))
+        try:
+            # Execute swig
+            swig_output = subprocess.check_output(
+                swig_command, stderr=subprocess.STDOUT, universal_newlines=True)
+
+            logging.info("swig generation succeeded")
+            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(e.output)
Index: scripts/swig_bot_lib/client.py
===================================================================
--- /dev/null
+++ scripts/swig_bot_lib/client.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+
+# Future imports
+from __future__ import absolute_import
+from __future__ import print_function
+
+# Python modules
+import argparse
+import logging
+import os
+import sys
+
+# LLDB modules
+import use_lldb_suite
+from lldbsuite.support import fs
+
+def process_args(args):
+    """Returns options processed from the provided command line.
+
+    @param args the command line to process.
+    """
+
+    class FindLocalSwigAction(argparse.Action):
+        def __init__(self, option_strings, dest, **kwargs):
+            super(FindLocalSwigAction, self).__init__(option_strings, dest, nargs='?', **kwargs)
+        def __call__(self, parser, namespace, values, option_string=None):
+            swig_exe = None
+            if values is None:
+                swig_exe = fs.find_executable('swig')
+            else:
+                swig_exe = values
+            setattr(namespace, self.dest, os.path.normpath(swig_exe))
+
+    # Setup the parser arguments that are accepted.
+    parser = argparse.ArgumentParser(
+        description='Generate SWIG bindings.')
+
+    # Arguments to control logging verbosity.
+    parser.add_argument(
+        "--verbose", "-v",
+        action="store_true",
+        default=False,
+        help="Increase logging verbosity level.")
+
+    parser.add_argument(
+        "--local",
+        action=FindLocalSwigAction,
+        dest="swig_executable",
+        help=(
+            "Run the copy of swig at the specified location, or search PATH"
+            "if the location is omitted"))
+
+    parser.add_argument(
+        "--remote",
+        action="store",
+        help=(
+            "Use the given connection string to connect to a remote "
+            "generation service"))
+
+    parser.add_argument(
+        "--src-root",
+        required=True,
+        help="The root folder of the LLDB source tree.")
+
+    parser.add_argument(
+        "--target-dir",
+        default=os.getcwd(),
+        help=(
+            "Specifies the build dir where the language binding "
+            "should be placed"))
+
+    parser.add_argument(
+        "--language",
+        dest="languages",
+        action="append",
+        help="Specifies the language to generate bindings for")
+
+    # Process args.
+    options = parser.parse_args(args)
+
+    if options.languages is None:
+        options.languages = ['python']
+
+    if options.remote is None and options.swig_executable is None:
+        logging.error("Must specify either --local or --remote")
+        sys.exit(-3)
+
+    # Set logging level based on verbosity count.
+    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)
+
+    return options
+
+
+def run(args):
+    options = process_args(args)
+
+    if options.remote is None:
+        if not os.path.isfile(options.swig_executable):
+            logging.error("Swig executable '%s' does not exist." % options.swig_executable)
+        from . import local
+        local.generate(options)
+    else:
+        logging.error("Remote path is not yet implemented!")
Index: scripts/swig_bot.py
===================================================================
--- /dev/null
+++ scripts/swig_bot.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+# Python modules
+import sys
+
+# LLDB modules
+import use_lldb_suite
+
+if __name__ == "__main__":
+    from swig_bot_lib import client
+    client.run(sys.argv[1:])
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to