@@ -339,7 +339,8 @@ public final class UserToolchain: Toolchain {
339339 useXcrun: Bool ,
340340 environment: Environment ,
341341 searchPaths: [ AbsolutePath ] ,
342- fileSystem: any FileSystem
342+ fileSystem: any FileSystem ,
343+ observabilityScope: ObservabilityScope ? = nil
343344 ) throws -> SwiftCompilers {
344345 func validateCompiler( at path: AbsolutePath ? ) throws {
345346 guard let path else { return }
@@ -351,10 +352,37 @@ public final class UserToolchain: Toolchain {
351352 }
352353
353354 let lookup = { UserToolchain . lookup ( variable: $0, searchPaths: searchPaths, environment: environment) }
355+
356+ // Warn if SWIFT_EXEC or SWIFT_EXEC_MANIFEST is set but points to a non-existent or non-executable path
357+ func warnIfInvalid( envVar: String , value: String , resolved: AbsolutePath ? ) {
358+ guard resolved == nil else { return }
359+
360+ let message : String
361+ if let absolutePath = try ? AbsolutePath ( validating: value) {
362+ if fileSystem. exists ( absolutePath) {
363+ message = " \( envVar) is set to ' \( value) ' which exists but is not executable; ignoring "
364+ } else {
365+ message = " \( envVar) is set to ' \( value) ' but the file does not exist; ignoring "
366+ }
367+ } else {
368+ message = " \( envVar) is set to ' \( value) ' but no executable was found in search paths; ignoring "
369+ }
370+
371+ observabilityScope? . emit ( warning: message)
372+ }
373+
354374 // Get overrides.
355375 let SWIFT_EXEC_MANIFEST = lookup ( " SWIFT_EXEC_MANIFEST " )
356376 let SWIFT_EXEC = lookup ( " SWIFT_EXEC " )
357377
378+ // Emit warnings if environment variables are set but lookup failed
379+ if let swiftExecValue = environment [ " SWIFT_EXEC " ] , !swiftExecValue. isEmpty {
380+ warnIfInvalid ( envVar: " SWIFT_EXEC " , value: swiftExecValue, resolved: SWIFT_EXEC)
381+ }
382+ if let swiftExecManifestValue = environment [ " SWIFT_EXEC_MANIFEST " ] , !swiftExecManifestValue. isEmpty {
383+ warnIfInvalid ( envVar: " SWIFT_EXEC_MANIFEST " , value: swiftExecManifestValue, resolved: SWIFT_EXEC_MANIFEST)
384+ }
385+
358386 // Validate the overrides.
359387 try validateCompiler ( at: SWIFT_EXEC)
360388 try validateCompiler ( at: SWIFT_EXEC_MANIFEST)
@@ -693,6 +721,7 @@ public final class UserToolchain: Toolchain {
693721 customTargetInfo: JSON ? = nil ,
694722 customLibrariesLocation: ToolchainConfiguration . SwiftPMLibrariesLocation ? = nil ,
695723 customInstalledSwiftPMConfiguration: InstalledSwiftPMConfiguration ? = nil ,
724+ observabilityScope: ObservabilityScope ? = nil ,
696725 fileSystem: any FileSystem = localFileSystem
697726 ) throws {
698727 self . swiftSDK = swiftSDK
@@ -716,7 +745,8 @@ public final class UserToolchain: Toolchain {
716745 useXcrun: self . useXcrun,
717746 environment: environment,
718747 searchPaths: self . envSearchPaths,
719- fileSystem: fileSystem
748+ fileSystem: fileSystem,
749+ observabilityScope: observabilityScope
720750 )
721751 self . swiftCompilerPath = swiftCompilers. compile
722752 self . architectures = swiftSDK. architectures
0 commit comments