Skip to content

Commit 398b6f3

Browse files
committed
Formatting/UI.
1 parent 7349cc2 commit 398b6f3

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

App/InjectionNext/AppDelegate.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
209209
}
210210

211211
@IBAction func showlastError(_ sender: NSMenuItem) {
212-
lastErrorField.string = MonitorXcode
213-
.runningXcode?.recompiler.lastError ?? "No error."
212+
lastErrorField.string = NextCompiler.lastError ?? "No error."
214213
lastErrorField.window?.makeKeyAndOrderFront(sender)
215214
NSApplication.shared.activate(ignoringOtherApps: true)
216215
}

App/InjectionNext/FrontendServer.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ class FrontendServer: SimpleSocket {
128128
}
129129
static func writeCache(platform: String = clientPlatform) {
130130
do {
131+
let encoder = JSONEncoder()
132+
encoder.outputFormatting = .prettyPrinted
133+
let data = try encoder.encode(frontendRecompiler().compilations)
131134
let cache = cacheURL(platform: clientPlatform)
132-
let data = try JSONEncoder().encode(frontendRecompiler().compilations)
133135
try data.write(to: cache, options: .atomic)
134136
if let error = Popen.system("gzip -f "+cache.path, errors: true) {
135137
InjectionServer.error("Unable to zip commands cache: \(error)")

App/InjectionNext/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>$(MARKETING_VERSION)</string>
2121
<key>CFBundleVersion</key>
22-
<string>11297</string>
22+
<string>11301</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.developer-tools</string>
2525
<key>LSMinimumSystemVersion</key>

App/InjectionNext/NextCompiler.swift

+22-16
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ class NextCompiler {
4141
var workingDir: String
4242
}
4343

44-
// One compilation at a time.
44+
/// Queue for one compilation at a time.
4545
static let compileQueue = DispatchQueue(label: "InjectionCompile")
46+
/// Last build error.
47+
static var lastError: String?
48+
4649
/// Base for temporary files
4750
let tmpbase = "/tmp/injectionNext"
48-
/// Injection pending if information was not available and last error
49-
var pendingSource: String?, lastError: String?
51+
/// Injection pending if information was not available
52+
var pendingSource: String?
5053
/// Information for compiling a file per source file.
5154
var compilations = [String: Compilation]()
5255
/// Last Injected
@@ -84,7 +87,7 @@ class NextCompiler {
8487
connected?.injectionNumber += 1
8588
AppDelegate.ui.setMenuIcon(.busy)
8689
compileNumber += 1
87-
lastError = nil
90+
Self.lastError = nil
8891

8992
// Support for https://github.com/johnno1962/Compilertron
9093
let isCompilertron = connected == nil && source.hasSuffix(".cpp")
@@ -220,20 +223,23 @@ class NextCompiler {
220223
["-c", source, "-Xclang", "-fno-validate-pch"]) + baseOptionsToAdd
221224

222225
// Call compiler process
223-
if let errors = Popen.task(exec: compiler,
226+
let compile = Topen(exec: compiler,
224227
arguments: stored.arguments + languageSpecific,
225-
cd: stored.workingDir, errors: nil) { // Always returns stdout
226-
if errors.contains(" error: ") {
227-
print(([compiler] + stored.arguments +
228-
languageSpecific).joined(separator: " "))
229-
_ = error("Recompile failed for: \(source)\n"+errors)
230-
lastError = errors
231-
return nil
232-
}
233-
for slow: String in errors[
228+
cd: stored.workingDir)
229+
var errors = ""
230+
while let line = compile.readLine() {
231+
if let slow: String = line[
234232
#"(?<=/)\w+\.swift:\d+:\d+: warning: expression took \d+ms to type-check.*"#] {
235233
log(slow)
236234
}
235+
errors += line+"\n"
236+
}
237+
if errors.contains(" error: ") {
238+
print(([compiler] + stored.arguments +
239+
languageSpecific).joined(separator: " "))
240+
_ = error("Recompile failed for: \(source)\n"+errors)
241+
Self.lastError = errors
242+
return nil
237243
}
238244

239245
return object
@@ -296,7 +302,7 @@ class NextCompiler {
296302

297303
if let errors = Popen.system(linkCommand, errors: true) {
298304
_ = error("Linking failed:\n\(linkCommand)\nerrors:\n"+errors)
299-
lastError = errors
305+
Self.lastError = errors
300306
return nil
301307
}
302308

@@ -319,7 +325,7 @@ class NextCompiler {
319325
"""
320326
if let errors = Popen.system(codesign, errors: true) {
321327
_ = error("Codesign failed \(codesign) errors:\n"+errors)
322-
lastError = errors
328+
Self.lastError = errors
323329
}
324330
}
325331
return try? Data(contentsOf: URL(fileURLWithPath: dylib))

0 commit comments

Comments
 (0)