Skip to content

Commit

Permalink
Inject lowmad folder into lldb init script
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Thorell committed Dec 16, 2021
1 parent 5fe96d9 commit 2e234b3
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions Sources/LowmadKit/Lowmad.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2e234b3

Please sign in to comment.