@@ -35,8 +35,19 @@ class MonitorXcode {
3535 #if DEBUG
3636 args += " | tee \( recompiler. tmpbase) .log "
3737 #endif
38- if let xcodeStdout = Popen ( cmd: " export SOURCEKIT_LOGGING=1; " +
39- " ' \( Defaults . xcodePath) /Contents/MacOS/Xcode' 2>&1 \( args) " ) {
38+ if !FileManager. default. fileExists ( atPath: Defaults . xcodePath) {
39+ InjectionServer . error ( """
40+ No valid Xcode at path:
41+ \( Defaults . xcodePath)
42+ Use menu item " Select Xcode "
43+ to select a valid path.
44+ """ )
45+ }
46+ else if let xcodeStdout = Popen ( cmd: """
47+ export SOURCEKIT_LOGGING=1
48+ export RUNNING_VIA_INJECTION_NEXT=1
49+ ' \( Defaults . xcodePath) /Contents/MacOS/Xcode' 2>&1 \( args)
50+ """ ) {
4051 Self . runningXcode = self
4152 AppDelegate . ui. launchXcodeItem. state = . on
4253 DispatchQueue . global ( ) . async {
@@ -55,7 +66,7 @@ class MonitorXcode {
5566 break // break on clean exit and EOF.
5667 } catch {
5768 // Continue processing on error
58- _ = self . recompiler. error ( error)
69+ self . recompiler. error ( error)
5970 }
6071 }
6172 }
@@ -105,6 +116,7 @@ class MonitorXcode {
105116 }
106117
107118 let indexBuild = " /Index.noindex/Build/ "
119+ let productDir = " - " + FrontendServer. clientPlatform. lowercased ( )
108120 while let line = xcodeStdout. readLine ( ) {
109121// debug(">>"+line+"<<")
110122 if line. hasPrefix ( " key.request: source.request. " ) &&
@@ -115,33 +127,35 @@ class MonitorXcode {
115127 xcodeStdout. readLine ( ) == " key.compilerargs: [ " ||
116128 line == " key.compilerargs: [ " {
117129 var swiftFiles = " " , args = [ String] ( ) , fileCount = 0 ,
118- workingDir = " /tmp " , configDirs = Set < String > ( )
130+ workingDir = " /tmp "
119131
120132 while var arg = readQuotedString ( ) {
133+ /// Used if injecting the Swift compiler.
121134 let llvmIncs = " /llvm-macosx-arm64/lib "
122135 if arg. hasPrefix ( " -I " ) , arg. contains ( llvmIncs) {
123136 arg = arg. replacingOccurrences ( of: llvmIncs,
124137 with: " /../buildbot_osx " + llvmIncs)
125138 }
126- if args. last == " -F " && arg. hasSuffix ( " /PackageFrameworks " ) {
127- Unhider . packageFrameworks = arg
128- #if DEFAULTS_PACKAGE_PROBLEM || false
129- let frameworksURL = URL ( fileURLWithPath: arg)
130- let derivedData = frameworksURL. deletingLastPathComponent ( )
131- . deletingLastPathComponent ( ) . deletingLastPathComponent ( )
132- . deletingLastPathComponent ( ) . deletingLastPathComponent ( )
133- let productsDir =
134- derivedData. appendingPathComponent ( " Build/Products " )
135- let platform = InjectionServer
136- . currentClient? . platform ?? " iPhoneSimulator "
137- if let configs = Glob ( pattern: productsDir. path +
138- " /*- " + platform. lowercased ( ) ) {
139- for other in configs
140- where configDirs. insert ( other) . inserted {
141- args += [ other, " -F " ]
142- }
139+
140+ /// Arguments received from SourceKit while syntax highlighting the editor
141+ /// have their own "Intermediates" directory. Map it back to the main one.
142+ let alt = arg [ indexBuild, " /Build/ " ]
143+ if !arg. hasSuffix ( " .yaml " ) , alt != arg,
144+ !arg. contains ( " /Intermediates.noindex/ " ) ,
145+ let path: String = alt [ #"(?:-I)?(.*)"# ] ,
146+ FileManager . default. fileExists ( atPath: path) {
147+ arg = alt
148+ }
149+
150+ /// Determine path to DerivedData for "unhiding".
151+ if args. last == " -F " {
152+ if arg. hasSuffix ( " /PackageFrameworks " ) {
153+ Unhider . packageFrameworks = arg
154+ }
155+ else if Unhider . packageFrameworks == nil ,
156+ arg. hasSuffix ( productDir) {
157+ Unhider . packageFrameworks = arg+ " /PackageFrameworks "
143158 }
144- #endif
145159 }
146160
147161 if arg. hasSuffix ( " .swift " ) && args. last != " -F " {
@@ -159,35 +173,7 @@ class MonitorXcode {
159173 arg. contains ( indexBuild) {
160174 // injecting tests without having run tests
161175 args. removeLast ( )
162- // Xcode seems to maintain two sets of "build inputs"
163- // i.e. .swiftmodule, .modulemap etc. files and it
164- // seems the main build allows you to avoid "unhiding"
165- // whereas the paths provided to SourceKit are for the
166- // Index.noindex/Build tree of inputs. Switch them.
167- } else if /*(args.last == "-I" || args.last == "-F" ||
168- args.last == "-Xcc" && (arg.hasPrefix("-I") ||
169- arg.hasPrefix("-fmodule-map-file="))) &&*/
170- arg. contains ( indexBuild) &&
171- !arg. contains ( " /Intermediates.noindex/ " ) ,
172- let _ = args. last {
173- // expands out default argument generators
174- let alt = arg. replacingOccurrences (
175- of: indexBuild, with: " /Build/ " )
176- var change = [ alt]
177- // alternate fix of Defaults problem
178- // hopefully without causing unhides
179- // InjectionNext/issues/#40 c.f. #78
180- if let path: String = alt [ #"(?:-I)?(.*)"# ] ,
181- !FileManager. default. fileExists ( atPath: path) {
182- // change += (arg.hasPrefix("-") ? [arg] :
183- // option.hasPrefix("-") ? [option, arg] :
184- // [])
185- change = [ arg]
186- }
187- // debug("CHANGE", change)
188- args += change
189- } else if !( arg == " -F " && args. last == " -F " ) &&
190- arg != " -Xfrontend " && !arg. hasPrefix ( " -driver- " ) {
176+ } else if arg != " -Xfrontend " && !arg. hasPrefix ( " -driver- " ) {
191177 args. append ( arg)
192178 }
193179 }
0 commit comments