@@ -109,7 +109,11 @@ def find_vcvarsall(env: EnvMapping) -> pathlib.Path | None:
109109 vs_path = result .stdout .strip ()
110110 if vs_path :
111111 candidate = (
112- pathlib .Path (vs_path ) / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"
112+ pathlib .Path (vs_path )
113+ / "VC"
114+ / "Auxiliary"
115+ / "Build"
116+ / "vcvarsall.bat"
113117 )
114118 if candidate .exists ():
115119 return candidate
@@ -371,28 +375,39 @@ def update_openssl(dirs: Dirs, env: EnvMapping) -> None:
371375 ref_loc = f"cpe:2.3:a:openssl:openssl:{ version } :*:*:*:*:*:*:*"
372376
373377 is_binary = "cpython-bin-deps" in url
374- target_dir = dirs .source / "externals" / f"openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} "
378+ target_dir = (
379+ dirs .source / "externals" / f"openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} "
380+ )
375381
376- update_props (dirs .source , r"openssl-\d+(\.\d+)*[a-z]*" , f"openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} " )
382+ update_props (
383+ dirs .source ,
384+ r"openssl-\d+(\.\d+)*[a-z]*" ,
385+ f"openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} " ,
386+ )
377387 # Binary deps tarball from cpython-bin-deps includes both source and binaries
378388 # We need to ensure openssl-bin-<version> is also pointed to the same place if needed
379389 update_props (
380- dirs .source , r"openssl-bin-\d+(\.\d+)*[a-z]*" , f"openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} "
390+ dirs .source ,
391+ r"openssl-bin-\d+(\.\d+)*[a-z]*" ,
392+ f"openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} " ,
381393 )
382394
383395 if not target_dir .exists ():
384396 get_externals_source (externals_dir = dirs .source / "externals" , url = url )
385397 # flatten_externals(dirs, "openssl", version) would move it to openssl-<version>
386- # but we want openssl-<version>-<arch>.
398+ # but we want openssl-<version>-<arch>.
387399 # We'll find it and move it ourselves.
388400 for d in (dirs .source / "externals" ).iterdir ():
389- if d .is_dir () and (d .name == f"openssl-{ version } " or d .name .startswith (f"openssl-{ version } " )):
401+ if d .is_dir () and (
402+ d .name == f"openssl-{ version } "
403+ or d .name .startswith (f"openssl-{ version } " )
404+ ):
390405 if d != target_dir :
391406 if target_dir .exists ():
392407 shutil .rmtree (str (target_dir ))
393408 shutil .move (str (d ), str (target_dir ))
394409 break
395-
410+
396411 # Now flatten if it's nested
397412 subdirs = [x for x in target_dir .iterdir () if x .is_dir ()]
398413 if len (subdirs ) == 1 and subdirs [0 ].name .startswith ("openssl" ):
@@ -404,90 +419,106 @@ def update_openssl(dirs: Dirs, env: EnvMapping) -> None:
404419
405420 if not is_binary :
406421 # Build from source
407- log .info ("Building OpenSSL %s (%s) from source" , version , env ["RELENV_HOST_ARCH" ])
422+ log .info (
423+ "Building OpenSSL %s (%s) from source" , version , env ["RELENV_HOST_ARCH" ]
424+ )
408425 perl_dir = update_perl (dirs , env )
409426 perl_bin = perl_dir / "perl" / "bin" / "perl.exe"
410-
427+
411428 nasm_info = get_dependency_version ("nasm" , "win32" )
412429 nasm_version = nasm_info ["version" ]
413430 nasm_dir = dirs .source / "externals" / f"nasm-{ nasm_version } "
414-
431+
415432 # Find nasm.exe
416433 nasm_exe = list (nasm_dir .glob ("**/nasm.exe" ))
417434 if not nasm_exe :
418435 log .error ("Could not find nasm.exe in %s" , nasm_dir )
419436 return
420-
437+
421438 arch_map = {
422439 "amd64" : "VC-WIN64A" ,
423440 "x86" : "VC-WIN32" ,
424441 "arm64" : "VC-WIN64-ARM" ,
425442 }
426443 target = arch_map .get (env ["RELENV_HOST_ARCH" ], "VC-WIN64A" )
427-
444+
428445 vcvars = find_vcvarsall (env )
429446 if not vcvars :
430447 log .warning ("Could not find vcvarsall.bat, build may fail" )
431448 vcvars_cmd = "echo"
432449 else :
433- vcvars_arch = "x64" if env ["RELENV_HOST_ARCH" ] == "amd64" else env ["RELENV_HOST_ARCH" ]
450+ vcvars_arch = (
451+ "x64"
452+ if env ["RELENV_HOST_ARCH" ] == "amd64"
453+ else env ["RELENV_HOST_ARCH" ]
454+ )
434455 vcvars_cmd = f'call "{ vcvars } " { vcvars_arch } '
435456
436457 env_path = os .environ .get ("PATH" , "" )
437458 build_env = env .copy ()
438459 build_env ["PATH" ] = f"{ perl_bin .parent } ;{ nasm_exe [0 ].parent } ;{ env_path } "
439-
460+
440461 prefix = target_dir / "build"
441462 openssldir = prefix / "ssl"
442-
463+
443464 # Create a temporary batch file to run the build
444465 # This is more robust than passing a long string to cmd /c
445466 build_bat = target_dir / "relenv_build_openssl.bat"
446467 with open (str (build_bat ), "w" ) as f :
447468 f .write ("@echo off\n " )
448- f .write (f' { vcvars_cmd } \n ' )
449- f .write (f' if %errorlevel% neq 0 exit /b %errorlevel%\n ' )
469+ f .write (f" { vcvars_cmd } \n " )
470+ f .write (" if %errorlevel% neq 0 exit /b %errorlevel%\n " )
450471 f .write (f'cd /d "{ target_dir } "\n ' )
451- f .write (f'"{ perl_bin } " Configure { target } --prefix="{ prefix } " --openssldir="{ openssldir } " no-unit-test no-tests\n ' )
452- f .write (f'if %errorlevel% neq 0 exit /b %errorlevel%\n ' )
453- f .write (f'nmake\n ' )
454- f .write (f'if %errorlevel% neq 0 exit /b %errorlevel%\n ' )
455- f .write (f'nmake install_sw\n ' )
456- f .write (f'if %errorlevel% neq 0 exit /b %errorlevel%\n ' )
472+ f .write (
473+ f'"{ perl_bin } " Configure { target } --prefix="{ prefix } " '
474+ f'--openssldir="{ openssldir } " no-unit-test no-tests\n '
475+ )
476+ f .write ("if %errorlevel% neq 0 exit /b %errorlevel%\n " )
477+ f .write ("nmake\n " )
478+ f .write ("if %errorlevel% neq 0 exit /b %errorlevel%\n " )
479+ f .write ("nmake install_sw\n " )
480+ f .write ("if %errorlevel% neq 0 exit /b %errorlevel%\n " )
457481
458482 log .info ("Running OpenSSL build batch file" )
459483 runcmd ([str (build_bat )], env = build_env )
460484
461485 # CPython expects binaries in a specific structure
462486 # opensslOutDir = $(ExternalsDir)openssl-bin-<version)\$(ArchName)\
463487 # We'll move them to match.
464- out_dir = target_dir / env ["RELENV_HOST_ARCH" ]
488+ arch_to_archname = {
489+ "amd64" : "amd64" ,
490+ "x86" : "win32" ,
491+ "arm64" : "arm64" ,
492+ "arm" : "arm32" ,
493+ }
494+ arch_name = arch_to_archname .get (env ["RELENV_HOST_ARCH" ], env ["RELENV_HOST_ARCH" ])
495+ out_dir = target_dir / arch_name
465496 out_dir .mkdir (parents = True , exist_ok = True )
466-
497+
467498 prefix = target_dir / "build"
468499 bin_dir = prefix / "bin"
469500 lib_dir = prefix / "lib"
470501 inc_dir = prefix / "include"
471-
502+
472503 if prefix .exists ():
473504 for f in bin_dir .glob ("*.dll" ):
474505 shutil .copy (str (f ), str (out_dir ))
475506 for f in bin_dir .glob ("*.pdb" ):
476507 shutil .copy (str (f ), str (out_dir ))
477508 for f in lib_dir .glob ("*.lib" ):
478509 shutil .copy (str (f ), str (out_dir ))
479-
510+
480511 # CPython expects headers in $(opensslOutDir)include
481512 (out_dir / "include" ).mkdir (parents = True , exist_ok = True )
482513 shutil .copytree (str (inc_dir ), str (out_dir / "include" ), dirs_exist_ok = True )
483-
514+
484515 # CPython specifically looks for applink.c in the include directory
485516 if (target_dir / "ms" / "applink.c" ).exists ():
486517 shutil .copy (
487518 target_dir / "ms" / "applink.c" ,
488519 out_dir / "include" / "applink.c" ,
489520 )
490-
521+
491522 # Copy LICENSE file to out_dir to satisfy CPython build
492523 for license_file in ["LICENSE" , "LICENSE.txt" , "COPYING" ]:
493524 if (target_dir / license_file ).exists ():
@@ -502,7 +533,9 @@ def update_openssl(dirs: Dirs, env: EnvMapping) -> None:
502533 for h in target_dir .glob ("**/opensslv.h" ):
503534 if h .parent .name == "openssl" :
504535 # Found it, move its parent to include/
505- shutil .copytree (str (h .parent ), str (inc_openssl_dir ), dirs_exist_ok = True )
536+ shutil .copytree (
537+ str (h .parent ), str (inc_openssl_dir ), dirs_exist_ok = True
538+ )
506539 break
507540
508541 # Ensure applink.c is in include/
@@ -513,18 +546,33 @@ def update_openssl(dirs: Dirs, env: EnvMapping) -> None:
513546
514547 if not is_binary :
515548 # Update props to point to our custom build
516- update_props (dirs .source , r"openssl-bin-\d+(\.\d+)*[a-z]*" , f"openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} \\ \\ { env ['RELENV_HOST_ARCH' ]} " )
517- # And opensslOutDir needs to be just the folder containing include
518- patch_file (dirs .source / "PCbuild" / "python.props" ,
519- rf"<opensslOutDir Condition=\"\$\(opensslOutDir\) == ''\">\$\(ExternalsDir\)openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} \\ \\ { env ['RELENV_HOST_ARCH' ]} \\\$\(ArchName\)\\\</opensslOutDir>" ,
520- f"<opensslOutDir Condition=\" $(opensslOutDir) == ''\" >$(ExternalsDir)openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} \\ \\ { env ['RELENV_HOST_ARCH' ]} \\ \\ </opensslOutDir>" )
549+ # opensslDir is the base directory
550+ update_props (
551+ dirs .source ,
552+ r"<opensslDir.*>.*</opensslDir>" ,
553+ (
554+ f"<opensslDir Condition=\" $(opensslDir) == ''\" >"
555+ f"$(ExternalsDir)openssl-{ version } -{ env ['RELENV_HOST_ARCH' ]} \\ "
556+ f"</opensslDir>"
557+ ),
558+ )
559+ # opensslOutDir is where the binaries and include folder are
560+ update_props (
561+ dirs .source ,
562+ r"<opensslOutDir.*>.*</opensslOutDir>" ,
563+ (
564+ f"<opensslOutDir Condition=\" $(opensslOutDir) == ''\" >"
565+ f"$(opensslDir){ arch_name } \\ "
566+ f"</opensslOutDir>"
567+ ),
568+ )
521569
522570 # Patch openssl.props to use correct DLL suffix for OpenSSL 3.x
523571 if version .startswith ("3." ):
524572 suffix = "-3"
525573 if not is_binary and env ["RELENV_HOST_ARCH" ] == "amd64" :
526574 suffix = "-3-x64"
527-
575+
528576 log .info ("Patching openssl.props DLL suffix to %s" , suffix )
529577 patch_file (
530578 dirs .source / "PCbuild" / "openssl.props" ,
@@ -681,7 +729,6 @@ def update_mpdecimal(dirs: Dirs, env: EnvMapping) -> None:
681729
682730 version = mpdecimal_info ["version" ]
683731 url = mpdecimal_info ["url" ].format (version = version )
684- sha256 = mpdecimal_info ["sha256" ]
685732
686733 target_dir = dirs .source / "externals" / f"mpdecimal-{ version } "
687734 update_props (dirs .source , r"mpdecimal-\d+(\.\d+)*" , f"mpdecimal-{ version } " )
@@ -700,7 +747,6 @@ def update_nasm(dirs: Dirs, env: EnvMapping) -> None:
700747
701748 version = nasm_info ["version" ]
702749 url = nasm_info ["url" ].format (version = version )
703- sha256 = nasm_info ["sha256" ]
704750
705751 target_dir = dirs .source / "externals" / f"nasm-{ version } "
706752 update_props (dirs .source , r"nasm-\d+(\.\d+)*" , f"nasm-{ version } " )
@@ -719,7 +765,6 @@ def update_perl(dirs: Dirs, env: EnvMapping) -> pathlib.Path:
719765
720766 version = perl_info ["version" ]
721767 url = perl_info ["url" ].format (version = version )
722- sha256 = perl_info ["sha256" ]
723768
724769 target_dir = dirs .source / "externals" / f"perl-{ version } "
725770 if not target_dir .exists ():
0 commit comments