Skip to content

Commit 3359c08

Browse files
authored
Pch problems (#44)
* Frameworks named *.swift
1 parent 50d8af7 commit 3359c08

14 files changed

+90
-85
lines changed

App/InjectionNext/AppDelegate.swift

+13-10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class AppDelegate : NSObject, NSApplicationDelegate {
3939
// Place to display last error that occured
4040
@IBOutlet var lastErrorField: NSTextView!
4141
// Restart XCode if crashed.
42+
@IBOutlet weak var launchXcodeItem: NSMenuItem!
43+
@IBOutlet weak var selectXcodeItem: NSMenuItem!
4244
@IBOutlet weak var restartDeviceItem: NSMenuItem!
4345
@IBOutlet weak var patchCompilerItem: NSMenuItem!
4446

@@ -82,7 +84,7 @@ class AppDelegate : NSObject, NSApplicationDelegate {
8284
quit.toolTip = "Quit (build #\(build))"
8385
}
8486
}
85-
87+
8688
if !updatePatchUnpatch() && NSRunningApplication.runningApplications(
8789
withBundleIdentifier: "com.apple.dt.Xcode").first != nil {
8890
InjectionServer.error("""
@@ -95,13 +97,14 @@ class AppDelegate : NSObject, NSApplicationDelegate {
9597
librariesField.stringValue = Defaults.deviceLibraries
9698
InjectionServer.startServer(INJECTION_ADDRESS)
9799
setupCodeSigningComboBox()
98-
restartDeviceItem.state = Defaults.xcodeRestart == true ? .on : .off
99-
100+
restartDeviceItem.state = Defaults.xcodeRestart ? .on : .off
101+
selectXcodeItem.toolTip = Defaults.xcodePath
102+
100103
if let project = Defaults.projectPath {
101104
_ = MonitorXcode(args: " '\(project)'")
102105
}
103106
}
104-
107+
105108
func setMenuIcon(_ state: InjectionState) {
106109
DispatchQueue.main.async {
107110
let tiffName = "Injection"+state.rawValue
@@ -119,7 +122,7 @@ class AppDelegate : NSObject, NSApplicationDelegate {
119122
_ = MonitorXcode()
120123
}
121124
}
122-
125+
123126
@IBAction func selectXcode(_ sender: NSMenuItem) {
124127
let open = NSOpenPanel()
125128
open.prompt = "Select Xcode"
@@ -128,20 +131,20 @@ class AppDelegate : NSObject, NSApplicationDelegate {
128131
open.canChooseDirectories = false
129132
open.canChooseFiles = true
130133
if open.runModal() == .OK, let path = open.url?.path {
134+
selectXcodeItem.toolTip = path
131135
Defaults.xcodePath = path
132-
sender.toolTip = path
133136
updatePatchUnpatch()
134137
if Defaults.xcodeRestart {
135138
runXcode(sender)
136139
}
137140
}
138141
}
139-
142+
140143
lazy var startHostLocatingServerOnce: () = {
141144
InjectionServer.broadcastServe(HOTRELOADING_MULTICAST,
142145
port: HOTRELOADING_PORT)
143146
}()
144-
147+
145148
@IBAction func deviceEnable(_ sender: NSMenuItem) {
146149
var openPort = ""
147150
if sender.state.toggle() == .on {
@@ -153,7 +156,7 @@ class AppDelegate : NSObject, NSApplicationDelegate {
153156
InjectionServer.stopServer()
154157
InjectionServer.startServer(openPort+INJECTION_ADDRESS)
155158
}
156-
159+
157160
@IBAction func testingEnable(_ sender: NSButton) {
158161
if sender.state == .on, let script = Bundle.main
159162
.url(forResource: "copy_bundle", withExtension: "sh") {
@@ -179,7 +182,7 @@ class AppDelegate : NSObject, NSApplicationDelegate {
179182
@IBAction func updateXcodeRestart(_ sender: NSMenuItem) {
180183
Defaults.xcodeRestart = sender.state.toggle() == .on
181184
}
182-
185+
183186
@IBAction func unhideSymbols(_ sender: NSMenuItem) {
184187
Unhider.startUnhide()
185188
}

App/InjectionNext/Base.lproj/MainMenu.xib

+10-8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
<outlet property="codeSignBox" destination="iKZ-P7-T7T" id="KiT-vS-8mL"/>
1919
<outlet property="deviceTesting" destination="SQv-Cq-gPC" id="wzU-n5-tvW"/>
2020
<outlet property="lastErrorField" destination="yfA-aU-ldx" id="oxQ-Xy-ugr"/>
21+
<outlet property="launchXcodeItem" destination="B7f-B2-5ZH" id="7Pb-Cs-Q9n"/>
2122
<outlet property="librariesField" destination="rw0-Sb-xW5" id="iLm-Qn-E1h"/>
2223
<outlet property="patchCompilerItem" destination="cw9-XM-GH8" id="uKH-nc-2sg"/>
2324
<outlet property="restartDeviceItem" destination="6cM-gd-Yoh" id="vaG-Ug-i8f"/>
25+
<outlet property="selectXcodeItem" destination="XlL-4Y-oKk" id="lAe-fa-JsE"/>
2426
<outlet property="statusMenu" destination="V8Q-mq-A2f" id="Epo-HD-J21"/>
2527
</connections>
2628
</customObject>
@@ -753,7 +755,7 @@
753755
<rect key="frame" x="0.0" y="0.0" width="737" height="204"/>
754756
<autoresizingMask key="autoresizingMask"/>
755757
<subviews>
756-
<textField focusRingType="none" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rw0-Sb-xW5">
758+
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rw0-Sb-xW5">
757759
<rect key="frame" x="20" y="20" width="697" height="80"/>
758760
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
759761
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" title="-framework XCTest -lXCTestSwiftSupport" drawsBackground="YES" id="XCE-C6-jqh">
@@ -765,7 +767,7 @@
765767
<action selector="updateLibraries:" target="Voe-Tx-rLC" id="Rcu-9B-dga"/>
766768
</connections>
767769
</textField>
768-
<comboBox focusRingType="none" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iKZ-P7-T7T">
770+
<comboBox verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iKZ-P7-T7T">
769771
<rect key="frame" x="19" y="138" width="701" height="23"/>
770772
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
771773
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="A2I-vj-Z1G">
@@ -779,7 +781,7 @@
779781
</objectValues>
780782
</comboBoxCell>
781783
</comboBox>
782-
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="haQ-Mn-2en">
784+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="haQ-Mn-2en">
783785
<rect key="frame" x="18" y="168" width="169" height="16"/>
784786
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
785787
<textFieldCell key="cell" lineBreakMode="clipping" title="Select codesigning identity" id="9V5-ch-7QQ">
@@ -816,24 +818,24 @@
816818
<rect key="frame" x="8" y="10" width="670" height="251"/>
817819
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
818820
<clipView key="contentView" drawsBackground="NO" id="Jya-oY-Tsg">
819-
<rect key="frame" x="0.0" y="0.0" width="655" height="251"/>
821+
<rect key="frame" x="0.0" y="0.0" width="670" height="251"/>
820822
<autoresizingMask key="autoresizingMask"/>
821823
<subviews>
822824
<textView wantsLayer="YES" editable="NO" importsGraphics="NO" richText="NO" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="yfA-aU-ldx">
823-
<rect key="frame" x="0.0" y="0.0" width="655" height="251"/>
825+
<rect key="frame" x="0.0" y="0.0" width="670" height="251"/>
824826
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
825827
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
826828
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
827-
<size key="minSize" width="655" height="251"/>
829+
<size key="minSize" width="670" height="251"/>
828830
<size key="maxSize" width="675" height="10000000"/>
829831
</textView>
830832
</subviews>
831833
</clipView>
832-
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="xKv-Ny-an6">
834+
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="xKv-Ny-an6">
833835
<rect key="frame" x="-100" y="-100" width="225" height="15"/>
834836
<autoresizingMask key="autoresizingMask"/>
835837
</scroller>
836-
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="cCD-KO-rn7">
838+
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="cCD-KO-rn7">
837839
<rect key="frame" x="655" y="0.0" width="15" height="251"/>
838840
<autoresizingMask key="autoresizingMask"/>
839841
</scroller>

App/InjectionNext/Experimental.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Cocoa
1313
import SwiftRegex
1414

1515
extension AppDelegate {
16-
16+
1717
/// Prepare the SwiftUI source file currently being edited for injection.
1818
@IBAction func prepareSource(_ sender: NSMenuItem) {
1919
if let lastSource = MonitorXcode.runningXcode?.lastSource ??
@@ -36,7 +36,7 @@ extension AppDelegate {
3636
let s = changes == 1 ? "" : "s"
3737
InjectionServer.error("\(changes) automatic edit\(s) made to \(edited) files")
3838
}
39-
39+
4040
/// Use regular expresssions to patch .enableInjection() and @ObserveInject into a source
4141
func prepare(source: String, changes: UnsafeMutablePointer<Int>? = nil) {
4242
let fileURL = URL(fileURLWithPath: source)

App/InjectionNext/FrontendServer.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension AppDelegate {
4343
""")
4444
}
4545
} else if fm.fileExists(atPath: FrontendServer.patched) {
46-
try fm.removeItem(at: FrontendServer.unpatchedURL)
46+
try? fm.removeItem(at: FrontendServer.unpatchedURL)
4747
try fm.moveItem(at: FrontendServer.patchedURL,
4848
to: FrontendServer.unpatchedURL)
4949
for binary in linksToMove {
@@ -82,7 +82,7 @@ class FrontendServer: InjectionServer {
8282
case unpatched = "Intercept Compiler"
8383
case patched = "Unpatch Compiler"
8484
}
85-
85+
8686
static var binURL: URL = URL(fileURLWithPath: Defaults.xcodePath +
8787
"/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin")
8888
static var unpatchedURL: URL = binURL.appendingPathComponent("swift-frontend")
@@ -137,7 +137,7 @@ class FrontendServer: InjectionServer {
137137
var swiftFiles = "", args = [String](), platform = "iPhoneSimulator",
138138
sourceFiles = [String](), workingDir = "/tmp"
139139
let frontendPath = feed.readString()
140-
140+
141141
while let arg = feed.readString(), arg != COMMANDS_END {
142142
switch arg {
143143
case "-filelist":
@@ -159,12 +159,12 @@ class FrontendServer: InjectionServer {
159159
if let sdkPlatform: String = arg[#"/([A-Za-z]+)[\d\.]+\.sdk$"#] {
160160
platform = sdkPlatform
161161
}
162-
if arg.hasSuffix(".swift") {
162+
if arg.hasSuffix(".swift") && args.last != "-F" {
163163
swiftFiles += arg+"\n"
164-
} else if arg[
165-
#"(-(pch-output-dir|supplementary-output-file-map|emit-(reference-)?dependencies|serialize-diagnostics|index-(store|unit-output))(-path)?|(-validate-clang-modules-once )?-clang-build-session-file|-Xcc -ivfsstatcache -Xcc)"#] {
164+
} else if arg[Recompiler.optionsToRemove] {
166165
_ = feed.readString()
167-
} else if !arg["-validate-clang-modules-once|-frontend-parseable-output"] {
166+
} else if !(arg == "-F" && args.last == "-F") && !arg[
167+
"-validate-clang-modules-once|-frontend-parseable-output"] {
168168
args.append(arg)
169169
}
170170
}
@@ -198,7 +198,7 @@ class FrontendServer: InjectionServer {
198198
URL(fileURLWithPath: source).lastPathComponent)
199199
let update = NextCompiler.Compilation(arguments: args,
200200
swiftFiles: swiftFiles, workingDir: workingDir)
201-
201+
202202
recompiler.compilations[source] = update
203203
if source == FrontendServer.frontendRecompiler().pendingSource {
204204
recompiler.pendingSource = nil

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

App/InjectionNext/InjectionHybrid.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class InjectionHybrid: InjectionBase {
4242
/// Called from file watcher when file is edited.
4343
override func inject(source: String) {
4444
var recompiler: NextCompiler = liteRecompiler
45-
if FrontendServer.loggedFrontend != nil {
45+
if FrontendServer.loggedFrontend != nil && source.hasSuffix(".swift") {
4646
recompiler = FrontendServer.frontendRecompiler()
4747
FrontendServer.lastInjected = source
4848
}
@@ -56,7 +56,7 @@ class InjectionHybrid: InjectionBase {
5656
self.injectNext(fallback: recompiler)
5757
}
5858
}
59-
59+
6060
func injectNext(fallback: NextCompiler) {
6161
guard let source = DispatchQueue.main.sync(execute: { () -> String? in
6262
guard let source = Self.pendingInjections.first else { return nil }
@@ -73,7 +73,7 @@ class InjectionHybrid: InjectionBase {
7373
running.recompiler.inject(source: source) else {
7474
if !fallback.inject(source: source) {
7575
fallback.pendingSource = source
76-
} else {
76+
} else if FrontendServer.loggedFrontend != nil {
7777
FrontendServer.writeCache()
7878
}
7979
return

App/InjectionNext/InjectionServer.swift

+11-12
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import Fortify
1717
import Popen
1818

1919
class InjectionServer: SimpleSocket {
20-
20+
2121
/// So commands from differnt threads don't get mixed up
2222
static let commandQueue = DispatchQueue(label: "InjectionCommand")
2323
/// Current connection to client app. There can be only one.
2424
static weak var currentClient: InjectionServer?
25-
25+
2626
/// Sorted last symbols exported by source.
2727
var exports = [String: [String]]()
2828
/// Keeps dynamic library file names unique.
@@ -31,7 +31,7 @@ class InjectionServer: SimpleSocket {
3131
var platform = "iPhoneSimulator"
3232
var arch = "arm64"
3333
var tmpPath = "/unset"
34-
34+
3535
/// Pops up an alert panel for networking
3636
@discardableResult
3737
override public class func error(_ message: String) -> Int32 {
@@ -113,7 +113,7 @@ class InjectionServer: SimpleSocket {
113113
error("Connection did not validate.")
114114
return
115115
}
116-
116+
117117
if magic == COMMANDS_VERSION {
118118
do {
119119
try FrontendServer.processFrontendCommandFrom(feed: self)
@@ -122,7 +122,7 @@ class InjectionServer: SimpleSocket {
122122
}
123123
return
124124
}
125-
125+
126126
DispatchQueue.main.async {
127127
InjectionHybrid.pendingInjections.removeAll()
128128
}
@@ -138,20 +138,19 @@ class InjectionServer: SimpleSocket {
138138
}
139139

140140
func processResponses() {
141-
guard MonitorXcode.runningXcode != nil ||
142-
!AppDelegate.watchers.isEmpty ||
143-
FrontendServer.loggedFrontend != nil else {
141+
if MonitorXcode.runningXcode == nil &&
142+
AppDelegate.watchers.isEmpty &&
143+
FrontendServer.loggedFrontend == nil {
144144
error("""
145145
Xcode not launched via app. Injection will not be possible \
146146
unless you file watch a project and Xcode logs are available.
147147
""")
148-
return
149148
}
150-
149+
151150
sendCommand(.xcodePath, with: Defaults.xcodePath)
152-
151+
153152
AppDelegate.watchers.last?.watcher?.restart()
154-
153+
155154
while true {
156155
let responseInt = readInt()
157156
guard let response = InjectionResponse(rawValue: responseInt) else {

0 commit comments

Comments
 (0)