From 2e234b3046df73cb801034e716a4633aaa122303 Mon Sep 17 00:00:00 2001 From: Johan Thorell Date: Thu, 16 Dec 2021 08:58:41 +0100 Subject: [PATCH] Inject lowmad folder into lldb init script --- Sources/LowmadKit/Lowmad.swift | 67 ++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/Sources/LowmadKit/Lowmad.swift b/Sources/LowmadKit/Lowmad.swift index 8266c1c..aeb5228 100644 --- a/Sources/LowmadKit/Lowmad.swift +++ b/Sources/LowmadKit/Lowmad.swift @@ -50,37 +50,6 @@ public class Lowmad { } public func runInit() throws { - let lldbInitScript = """ - import lldb - import os - import json - - def __lldb_init_module(debugger, internal_dict): - file_path = os.path.realpath(__file__) - dir_name = os.path.dirname(file_path) - load_python_scripts_dir(dir_name) - try: - with open('/usr/local/lib/lowmad/environment.json') as json_file: - data = json.load(json_file) - commandsPath = os.path.realpath(data['ownCommandsPath']) - if not dir_name in commandsPath: - load_python_scripts_dir(commandsPath) - except IOError: - print("environment.json not accessible") - - def load_python_scripts_dir(dir_name): - this_files_basename = os.path.basename(__file__) - cmd = '' - for r, d, f in os.walk(dir_name): - for file in f: - if '.py' in file: - cmd = 'command script import ' - else: - continue - if file != this_files_basename: - fullpath = os.path.join(r, file) - lldb.debugger.HandleCommand(cmd + fullpath) - """ let homeFolder = Current.homeFolder() @@ -91,6 +60,7 @@ public class Lowmad { Print.info("Creating \(Lowmad.name) import file...") let lowmadFile = try lowmadFolder.createFile(named: "\(Lowmad.name).py") + let lldbInitScript = try makeLLDBInitScript() try lowmadFile.write(lldbInitScript) if !homeFolder.containsSubfolder(at: Lowmad.name) { @@ -331,6 +301,41 @@ public class Lowmad { Print.done("Content has been synced 💯") } + + private func makeLLDBInitScript() throws -> String { + let path = try Current.lowmadFolder().path + return """ + import lldb + import os + import json + + def __lldb_init_module(debugger, internal_dict): + file_path = os.path.realpath(__file__) + dir_name = os.path.dirname(file_path) + load_python_scripts_dir(dir_name) + try: + with open('\(path)environment.json') as json_file: + data = json.load(json_file) + commandsPath = os.path.realpath(data['ownCommandsPath']) + if not dir_name in commandsPath: + load_python_scripts_dir(commandsPath) + except IOError: + print("environment.json not accessible") + + def load_python_scripts_dir(dir_name): + this_files_basename = os.path.basename(__file__) + cmd = '' + for r, d, f in os.walk(dir_name): + for file in f: + if '.py' in file: + cmd = 'command script import ' + else: + continue + if file != this_files_basename: + fullpath = os.path.join(r, file) + lldb.debugger.HandleCommand(cmd + fullpath) + """ + } private func deleteCommandsFromManifest(subset: [String]) throws { let folders = try getCommandFolders()