Skip to content

Commit 43c849e

Browse files
committed
Refactoring.
1 parent e160b1e commit 43c849e

File tree

6 files changed

+25
-30
lines changed

6 files changed

+25
-30
lines changed

App/InjectionNext.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,8 @@
998998
isa = XCRemoteSwiftPackageReference;
999999
repositoryURL = "https://github.com/Quick/Nimble.git";
10001000
requirement = {
1001-
branch = main;
1002-
kind = branch;
1001+
kind = upToNextMinorVersion;
1002+
minimumVersion = 13.2.0;
10031003
};
10041004
};
10051005
BBEB87102C74FD930044578A /* XCRemoteSwiftPackageReference "Quick" */ = {

App/InjectionNext/FrontendServer.swift

+4-12
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class FrontendServer: InjectionServer {
137137

138138
static func processFrontendCommandFrom(feed: SimpleSocket) throws {
139139
guard feed.readString() == "1.0" else {
140-
return NSLog(APP_PREFIX+"Re-patch compiler to update script version")
140+
return _ = Self.frontendRecompiler()
141+
.error("Unpatch then repatch compiler to update script version")
141142
}
142143
guard let projectRoot = feed.readString(),
143144
let frontendPath = feed.readString(),
@@ -177,7 +178,7 @@ class FrontendServer: InjectionServer {
177178
}
178179
}
179180

180-
MonitorXcode.compileQueue.async {
181+
NextCompiler.compileQueue.async {
181182
let recompiler = Self.frontendRecompiler(platform: platform)
182183
FrontendServer.loggedFrontend = frontendPath
183184

@@ -205,16 +206,7 @@ class FrontendServer: InjectionServer {
205206
URL(fileURLWithPath: source).lastPathComponent)
206207
let update = NextCompiler.Compilation(arguments: args,
207208
swiftFiles: swiftFiles, workingDir: projectRoot)
208-
209-
recompiler.compilations[source] = update
210-
let clientRecompiler = FrontendServer.frontendRecompiler()
211-
if source == clientRecompiler.pendingSource {
212-
MonitorXcode.compileQueue.async {
213-
if FrontendServer.frontendRecompiler().inject(source: source) {
214-
clientRecompiler.pendingSource = nil
215-
}
216-
}
217-
}
209+
recompiler.store(compilation: update, for: source)
218210
}
219211
}
220212
}

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>10905</string>
22+
<string>10930</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.developer-tools</string>
2525
<key>LSMinimumSystemVersion</key>

App/InjectionNext/InjectionHybrid.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class InjectionHybrid: InjectionBase {
5252
return
5353
}
5454
Self.pendingInjections.append(source)
55-
MonitorXcode.compileQueue.async {
55+
NextCompiler.compileQueue.async {
5656
self.injectNext(fallback: recompiler)
5757
}
5858
}
@@ -62,7 +62,7 @@ class InjectionHybrid: InjectionBase {
6262
guard let source = Self.pendingInjections.first else { return nil }
6363
Self.pendingInjections.removeFirst()
6464
if !Self.pendingInjections.isEmpty {
65-
MonitorXcode.compileQueue.async {
65+
NextCompiler.compileQueue.async {
6666
self.injectNext(fallback: fallback)
6767
}
6868
}

App/InjectionNext/MonitorXcode.swift

+2-13
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class MonitorXcode {
2121

2222
// Currently running Xcode process
2323
static weak var runningXcode: MonitorXcode?
24-
// One compilation at a time.
25-
static let compileQueue = DispatchQueue(label: "InjectionCompile")
2624
// Trying to avoid fragmenting memory
2725
var lastFilelist: String?, lastArguments: [String]?, lastSource: String?
2826
// The service to recompile and inject a source file.
@@ -219,21 +217,12 @@ class MonitorXcode {
219217
let update = NextCompiler.Compilation(arguments: args,
220218
swiftFiles: swiftFiles, workingDir: workingDir)
221219

222-
// The folling line should be on the compileQueue
223-
// but it seems to provoke a Swift compiler bug.
224-
self.recompiler.compilations[source] = update
225-
Self.compileQueue.async {
226-
if source == self.recompiler.pendingSource {
227-
print("Delayed injection of "+source)
228-
self.recompiler.pendingSource = nil
229-
_ = self.recompiler.inject(source: source)
230-
}
231-
}
220+
recompiler.store(compilation: update, for: source)
232221
} else if line ==
233222
" key.request: source.request.indexer.editor-did-save-file,",
234223
let _ = xcodeStdout.readLine(), let source = readQuotedString() {
235224
print("Injecting saved file "+source)
236-
Self.compileQueue.async {
225+
NextCompiler.compileQueue.async {
237226
_ = self.recompiler.inject(source: source)
238227
}
239228
}

App/InjectionNext/NextCompiler.swift

+14
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class NextCompiler {
3636
var workingDir: String
3737
}
3838

39+
// One compilation at a time.
40+
static let compileQueue = DispatchQueue(label: "InjectionCompile")
3941
/// Base for temporary files
4042
let tmpbase = "/tmp/injectionNext"
4143
/// Injection pending if information was not available and last error
@@ -58,6 +60,18 @@ class NextCompiler {
5860
func error(_ err: Error) -> Bool {
5961
error("Internal app error: \(err)")
6062
}
63+
64+
func store(compilation: Compilation, for source: String) {
65+
Self.compileQueue.async {
66+
self.compilations[source] = compilation
67+
if source == self.pendingSource {
68+
print("Delayed injection of "+source)
69+
if self.inject(source: source) {
70+
self.pendingSource = nil
71+
}
72+
}
73+
}
74+
}
6175

6276
/// Main entry point called by MonitorXcode
6377
func inject(source: String) -> Bool {

0 commit comments

Comments
 (0)