Include config settings in the archive, and extract on the remote.
llvm-svn: 254025
This commit is contained in:
parent
cc3609362e
commit
9befc01064
|
@ -23,6 +23,7 @@ from lldbsuite.support import fs
|
|||
from lldbsuite.support import sockutil
|
||||
|
||||
# package imports
|
||||
from . import config
|
||||
from . import local
|
||||
|
||||
default_ip = "127.0.0.1"
|
||||
|
@ -151,11 +152,17 @@ def run(args):
|
|||
if not os.path.isfile(options.swig_executable):
|
||||
logging.error("Swig executable '{}' does not exist."
|
||||
.format(options.swig_executable))
|
||||
local.generate(options)
|
||||
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)
|
||||
else:
|
||||
logging.info("swig bot client using remote generation with server '{}'"
|
||||
.format(options.remote))
|
||||
packed_input = local.pack_input(options)
|
||||
config_json = config.generate_config_json(options)
|
||||
packed_input = local.pack_archive(config_json, options)
|
||||
connection = establish_remote_connection(options.remote)
|
||||
response = transmit_data(connection, packed_input)
|
||||
logging.debug("Received {} byte response.".format(len(response)))
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#!/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)
|
|
@ -17,12 +17,19 @@ import logging
|
|||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
# LLDB modules
|
||||
import use_lldb_suite
|
||||
|
||||
def pack_input(options):
|
||||
class GenOptions(object):
|
||||
src_root = None
|
||||
target_dir = None
|
||||
languages = None
|
||||
swig_executable = None
|
||||
|
||||
def pack_archive(config_json, options):
|
||||
logging.info("Creating input file package...")
|
||||
zip_data = io.BytesIO()
|
||||
zip_file = None
|
||||
|
@ -61,8 +68,26 @@ def pack_input(options):
|
|||
os.path.join(options.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()
|
||||
|
||||
def unpack_archive(subfolder, archive_bytes):
|
||||
tempfolder = os.path.join(tempfile.gettempdir(), subfolder)
|
||||
os.makedirs(tempfolder, exist_ok=True)
|
||||
|
||||
tempfolder = tempfile.mkdtemp(dir=tempfolder)
|
||||
logging.debug("Extracting archive to {}".format(tempfolder))
|
||||
|
||||
zip_data = io.BytesIO(archive_bytes)
|
||||
logging.debug("Opening zip archive...")
|
||||
zip_file = zipfile.ZipFile(zip_data, mode='r')
|
||||
zip_file.extractall(tempfolder)
|
||||
zip_file.close()
|
||||
return tempfolder
|
||||
|
||||
def generate(options):
|
||||
include_folder = os.path.join(options.src_root, "include")
|
||||
in_file = os.path.join(options.src_root, "scripts", "lldb.swig")
|
||||
|
|
|
@ -14,9 +14,11 @@ import argparse
|
|||
import logging
|
||||
import os
|
||||
import select
|
||||
import shutil
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import traceback
|
||||
|
||||
# LLDB modules
|
||||
|
@ -68,9 +70,19 @@ def accept_once(sock, options):
|
|||
logging.info("Received {} bytes of data from client"
|
||||
.format(len(data)))
|
||||
|
||||
logging.info("Sending {} byte response".format(len(data)))
|
||||
client.sendall(struct.pack("!I", len(data)))
|
||||
client.sendall(data)
|
||||
pack_location = None
|
||||
try:
|
||||
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)
|
||||
finally:
|
||||
if pack_location is not None:
|
||||
logging.debug("Removing temporary folder {}"
|
||||
.format(pack_location))
|
||||
shutil.rmtree(pack_location)
|
||||
|
||||
def accept_loop(sock, options):
|
||||
while True:
|
||||
|
|
Loading…
Reference in New Issue