9
9
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
10
//
11
11
//===----------------------------------------------------------------------===//
12
+ import Foundation
12
13
import SwiftOptions
13
14
14
15
import class Dispatch. DispatchQueue
@@ -955,7 +956,7 @@ public struct Driver {
955
956
negative: . disableIncrementalFileHashing,
956
957
default: false )
957
958
self . recordedInputMetadata = . init( uniqueKeysWithValues:
958
- Set ( inputFiles) . compactMap { inputFile -> ( TypedVirtualPath , FileMetadata ) ? in
959
+ Set ( inputFiles) . compactMap { inputFile -> ( TypedVirtualPath , FileMetadata ) ? in
959
960
guard let modTime = try ? fileSystem. lastModificationTime ( for: inputFile. file) else { return nil }
960
961
if incrementalFileHashes {
961
962
guard let data = try ? fileSystem. readFileContents ( inputFile. file) else { return nil }
@@ -1425,6 +1426,12 @@ extension Driver {
1425
1426
if firstArg == " repl " {
1426
1427
updatedArgs. remove ( at: 1 )
1427
1428
updatedArgs. append ( " -repl " )
1429
+ #if os(Windows)
1430
+ if !hasMatchingPythonArch( ) {
1431
+ stderrStream. send ( " There is an architecture mismatch between the installed toolchain and the resolved Python's architecture. " )
1432
+ stderrStream. flush ( )
1433
+ }
1434
+ #endif
1428
1435
return ( . normal( isRepl: true ) , updatedArgs)
1429
1436
}
1430
1437
@@ -1434,6 +1441,37 @@ extension Driver {
1434
1441
1435
1442
return ( . subcommand( subcommand) , updatedArgs)
1436
1443
}
1444
+
1445
+ private static func hasMatchingPythonArch( ) -> Bool {
1446
+ #if arch(arm64)
1447
+ let arch = " arm64 "
1448
+ #elseif arch(x86_64)
1449
+ let arch = " amd64 "
1450
+ #elseif arch(x86)
1451
+ let arch = " x86 "
1452
+ #else
1453
+ return false ;
1454
+ #endif
1455
+ let process = Process ( )
1456
+ process. executableURL = URL ( fileURLWithPath: " python " )
1457
+ process. arguments = [ " -c " , " import platform; print(platform.machine()) " ]
1458
+
1459
+ let pipe = Pipe ( )
1460
+ process. standardOutput = pipe
1461
+
1462
+ do {
1463
+ try process. run ( )
1464
+ process. waitUntilExit ( )
1465
+
1466
+ let data = pipe. fileHandleForReading. readDataToEndOfFile ( )
1467
+ guard let output = String ( data: data, encoding: . utf8) else {
1468
+ return false ;
1469
+ }
1470
+ return output. lowercased ( ) . contains ( arch)
1471
+ } catch {
1472
+ return false
1473
+ }
1474
+ }
1437
1475
}
1438
1476
1439
1477
extension Driver {
0 commit comments