@@ -865,6 +865,14 @@ public struct Driver {
865
865
if case . subcommand = try Self . invocationRunMode ( forArgs: args) . mode {
866
866
throw Error . subcommandPassedToDriver
867
867
}
868
+
869
+ #if os(Windows)
870
+ if args [ 1 ] == " -repl " { // a `-` gets automatically added to `swift repl`.
871
+ try Driver . checkIfMatchingPythonArch (
872
+ executor: executor, env: env, diagnosticsEngine: diagnosticsEngine)
873
+ }
874
+ #endif
875
+
868
876
var args = args
869
877
if let additional = env [ " ADDITIONAL_SWIFT_DRIVER_FLAGS " ] {
870
878
args. append ( contentsOf: additional. components ( separatedBy: " " ) )
@@ -1426,9 +1434,6 @@ extension Driver {
1426
1434
if firstArg == " repl " {
1427
1435
updatedArgs. remove ( at: 1 )
1428
1436
updatedArgs. append ( " -repl " )
1429
- #if os(Windows)
1430
- checkIfMatchingPythonArch ( )
1431
- #endif
1432
1437
return ( . normal( isRepl: true ) , updatedArgs)
1433
1438
}
1434
1439
@@ -1446,40 +1451,33 @@ extension Driver {
1446
1451
/// install an x86 version of Python, they will get acryptic error message
1447
1452
/// when running lldb (`0xC000007B`). Calling this function before invoking
1448
1453
/// lldb gives them a warning to help troublshoot the issue.
1449
- private static func checkIfMatchingPythonArch( ) {
1454
+ public static func checkIfMatchingPythonArch(
1455
+ executor: DriverExecutor , env: [ String : String ] , diagnosticsEngine: DiagnosticsEngine
1456
+ ) throws {
1450
1457
#if arch(arm64)
1451
- let arch = " arm64 "
1458
+ let toolchainArchitecture = " arm64 "
1452
1459
#elseif arch(x86_64)
1453
- let arch = " amd64 "
1460
+ let toolchainArchitecture = " amd64 "
1454
1461
#elseif arch(x86)
1455
- let arch = " x86 "
1462
+ let toolchainArchitecture = " x86 "
1456
1463
#else
1457
- return ;
1464
+ return ;
1458
1465
#endif
1459
- let process = Process ( )
1460
- process. executableURL = URL ( fileURLWithPath: " C: \\ Windows \\ System32 \\ cmd.exe " )
1461
- process. arguments = [ " /c " , " python.exe " , " -c " , " import platform; print(platform.machine()) " ]
1462
-
1463
- let pipe = Pipe ( )
1464
- process. standardOutput = pipe
1465
- do {
1466
- try process. run ( )
1467
- process. waitUntilExit ( )
1468
-
1469
- let data = pipe. fileHandleForReading. readDataToEndOfFile ( )
1470
- guard let output = String ( data: data, encoding: . utf8) else {
1471
- return ;
1472
- }
1473
- if !output. lowercased ( ) . contains ( arch) {
1474
- stderrStream. send ( " There is an architecture mismatch between the installed toolchain and the resolved Python's architecture: \n " )
1475
- stderrStream. send ( " Toolchain: \( arch) \n " )
1476
- stderrStream. send ( " Python: \( output) \n " )
1477
- }
1478
- } catch {
1479
- stderrStream. flush ( )
1480
- return
1466
+ let pythonArchitecture = try executor. checkNonZeroExit (
1467
+ args: " python.exe " , " -c " , " import platform; print(platform.machine()) " ,
1468
+ environment: env
1469
+ ) . trimmingCharacters ( in: . whitespacesAndNewlines)
1470
+ . lowercased ( )
1471
+
1472
+ if !pythonArchitecture. contains ( toolchainArchitecture) {
1473
+ diagnosticsEngine. emit (
1474
+ . warning(
1475
+ """
1476
+ There is an architecture mismatch between the installed toolchain and the resolved Python's architecture:
1477
+ Toolchain: \( toolchainArchitecture)
1478
+ Python: \( pythonArchitecture)
1479
+ """ ) )
1481
1480
}
1482
- stderrStream. flush ( )
1483
1481
}
1484
1482
}
1485
1483
0 commit comments