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,9 @@ extension Driver {
1425
1426
if firstArg == " repl " {
1426
1427
updatedArgs. remove ( at: 1 )
1427
1428
updatedArgs. append ( " -repl " )
1429
+ #if os(Windows)
1430
+ checkIfMatchingPythonArch ( )
1431
+ #endif
1428
1432
return ( . normal( isRepl: true ) , updatedArgs)
1429
1433
}
1430
1434
@@ -1434,6 +1438,42 @@ extension Driver {
1434
1438
1435
1439
return ( . subcommand( subcommand) , updatedArgs)
1436
1440
}
1441
+
1442
+ private static func checkIfMatchingPythonArch( ) {
1443
+ #if arch(arm64)
1444
+ let arch = " arm64 "
1445
+ #elseif arch(x86_64)
1446
+ let arch = " amd64 "
1447
+ #elseif arch(x86)
1448
+ let arch = " x86 "
1449
+ #else
1450
+ return ;
1451
+ #endif
1452
+ let process = Process ( )
1453
+ process. executableURL = URL ( fileURLWithPath: " C: \\ Windows \\ System32 \\ cmd.exe " )
1454
+ process. arguments = [ " /c " , " python.exe " , " -c " , " import platform; print(platform.machine()) " ]
1455
+
1456
+ let pipe = Pipe ( )
1457
+ process. standardOutput = pipe
1458
+ do {
1459
+ try process. run ( )
1460
+ process. waitUntilExit ( )
1461
+
1462
+ let data = pipe. fileHandleForReading. readDataToEndOfFile ( )
1463
+ guard let output = String ( data: data, encoding: . utf8) else {
1464
+ return ;
1465
+ }
1466
+ if !output. lowercased ( ) . contains ( arch) {
1467
+ stderrStream. send ( " There is an architecture mismatch between the installed toolchain and the resolved Python's architecture: \n " )
1468
+ stderrStream. send ( " Toolchain: \( arch) \n " )
1469
+ stderrStream. send ( " Python: \( output) \n " )
1470
+ }
1471
+ } catch {
1472
+ stderrStream. flush ( )
1473
+ return
1474
+ }
1475
+ stderrStream. flush ( )
1476
+ }
1437
1477
}
1438
1478
1439
1479
extension Driver {
0 commit comments