From 295be7fc8d16ebd3faadcf44aeb37a0913a943d6 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Fri, 14 Feb 2025 11:43:25 +1100 Subject: [PATCH 1/5] add deactivation script --- recipe/activate.bat | 17 +++++++++++++++++ recipe/deactivate.bat | 17 +++++++++++++++++ recipe/meta.yaml | 2 +- recipe/vc_repack.py | 6 ++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 recipe/deactivate.bat diff --git a/recipe/activate.bat b/recipe/activate.bat index 9af95ff..345969d 100755 --- a/recipe/activate.bat +++ b/recipe/activate.bat @@ -1,3 +1,20 @@ +@@echo off +setlocal enabledelayedexpansion + +:: save existing variables for deactivation script; initialize all backups to a placeholder +:: (empty is the same as undefined), and only overwrite them if a value exists +for %%X in ( + CC CXX CMAKE_ARGS CMAKE_GEN CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET + CMAKE_PLAT CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE LATEST_VS + LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL NEWER_VS_WITH_OLDER_VC PY_VCRUNTIME_REDIST + USE_NEW_CMAKE_GEN_SYNTAX VCVARSBAT VSINSTALLDIR VS_MAJOR VS_VERSION VS_YEAR WindowsSDKVer +) do ( + set "_CONDA_BACKUP_%%X=placeholder" + if defined %%X ( + set "_CONDA_BACKUP_%%X=!%%X!" + ) +) + @@echo on :: Set env vars that tell distutils to use the compiler that we put on path diff --git a/recipe/deactivate.bat b/recipe/deactivate.bat new file mode 100644 index 0000000..b956e0e --- /dev/null +++ b/recipe/deactivate.bat @@ -0,0 +1,17 @@ +@@echo off +setlocal enabledelayedexpansion + +:: restore variables (if they existed prior to activation, they have a value that's not "placeholder") +for %%X in ( + CC CXX CMAKE_ARGS CMAKE_GEN CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET + CMAKE_PLAT CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE LATEST_VS + LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL NEWER_VS_WITH_OLDER_VC PY_VCRUNTIME_REDIST + USE_NEW_CMAKE_GEN_SYNTAX VCVARSBAT VSINSTALLDIR VS_MAJOR VS_VERSION VS_YEAR WindowsSDKVer +) do ( + if "!_CONDA_BACKUP_%%X!" == "placeholder" ( + set "%%X=" + ) else ( + set "%%X=!_CONDA_BACKUP_%%X!" + ) + set "_CONDA_BACKUP_%%X=" +) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index b0cefb3..9e55feb 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -18,7 +18,7 @@ {% set vcvars_ver_maj = cl_version.split(".")[0]|int - 5 %} {% set vcvars_ver_min = cl_version.split(".")[1]|int %} {% set vcvars_ver = vcvars_ver_maj ~ "." ~ vcvars_ver_min %} -{% set build_num = 24 %} +{% set build_num = 25 %} package: name: vs{{ vsyear }} diff --git a/recipe/vc_repack.py b/recipe/vc_repack.py index 5b257a5..8cf396e 100644 --- a/recipe/vc_repack.py +++ b/recipe/vc_repack.py @@ -371,6 +371,12 @@ def main(): ) as w: for line in r: w.write(subs(line, args)) + targetdir = os.path.join(env.prefix, "etc", "conda", "deactivate.d") + os.makedirs(targetdir) + shutil.copyfile( + os.path.join(env.recipe_dir, "deactivate.bat"), + os.path.join(targetdir, f"vs{args.activate_year}_compiler_vars.bat"), + ) if __name__ == "__main__": From 39eec1093883c65079484e14c0538457527d022a Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Tue, 4 Mar 2025 16:11:29 +1100 Subject: [PATCH 2/5] directly unset variables local to activate.bat at the end of activation --- recipe/activate.bat | 14 +++++++++++--- recipe/deactivate.bat | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/recipe/activate.bat b/recipe/activate.bat index 345969d..53a3d10 100755 --- a/recipe/activate.bat +++ b/recipe/activate.bat @@ -5,9 +5,9 @@ setlocal enabledelayedexpansion :: (empty is the same as undefined), and only overwrite them if a value exists for %%X in ( CC CXX CMAKE_ARGS CMAKE_GEN CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET - CMAKE_PLAT CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE LATEST_VS - LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL NEWER_VS_WITH_OLDER_VC PY_VCRUNTIME_REDIST - USE_NEW_CMAKE_GEN_SYNTAX VCVARSBAT VSINSTALLDIR VS_MAJOR VS_VERSION VS_YEAR WindowsSDKVer + CMAKE_PLAT CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE + LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL PY_VCRUNTIME_REDIST + VS_MAJOR VS_VERSION VS_YEAR ) do ( set "_CONDA_BACKUP_%%X=placeholder" if defined %%X ( @@ -173,6 +173,14 @@ if %ERRORLEVEL% neq 0 ( ) popd +:: unset auxiliary variables +set "LATEST_VS=" +set "NEWER_VS_WITH_OLDER_VC=" +set "USE_NEW_CMAKE_GEN_SYNTAX=" +set "VCVARSBAT=" +set "VSINSTALLDIR=" +set "WindowsSDKVer=" + :GetWin10SdkDir call :GetWin10SdkDirHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 diff --git a/recipe/deactivate.bat b/recipe/deactivate.bat index b956e0e..0c7dd0b 100644 --- a/recipe/deactivate.bat +++ b/recipe/deactivate.bat @@ -4,9 +4,9 @@ setlocal enabledelayedexpansion :: restore variables (if they existed prior to activation, they have a value that's not "placeholder") for %%X in ( CC CXX CMAKE_ARGS CMAKE_GEN CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET - CMAKE_PLAT CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE LATEST_VS - LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL NEWER_VS_WITH_OLDER_VC PY_VCRUNTIME_REDIST - USE_NEW_CMAKE_GEN_SYNTAX VCVARSBAT VSINSTALLDIR VS_MAJOR VS_VERSION VS_YEAR WindowsSDKVer + CMAKE_PLAT CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE + LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL PY_VCRUNTIME_REDIST + VS_MAJOR VS_VERSION VS_YEAR ) do ( if "!_CONDA_BACKUP_%%X!" == "placeholder" ( set "%%X=" From 34bdafc5a1a5a81078d0c1add30502bf0c4075fc Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Tue, 4 Mar 2025 16:39:44 +1100 Subject: [PATCH 3/5] unset more auxiliary variables that are local to activate.bat --- recipe/activate.bat | 6 ++++-- recipe/deactivate.bat | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/recipe/activate.bat b/recipe/activate.bat index 53a3d10..09ea79a 100755 --- a/recipe/activate.bat +++ b/recipe/activate.bat @@ -4,8 +4,8 @@ setlocal enabledelayedexpansion :: save existing variables for deactivation script; initialize all backups to a placeholder :: (empty is the same as undefined), and only overwrite them if a value exists for %%X in ( - CC CXX CMAKE_ARGS CMAKE_GEN CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET - CMAKE_PLAT CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE + CC CXX CMAKE_ARGS CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET + CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL PY_VCRUNTIME_REDIST VS_MAJOR VS_VERSION VS_YEAR ) do ( @@ -174,6 +174,8 @@ if %ERRORLEVEL% neq 0 ( popd :: unset auxiliary variables +set "CMAKE_GEN=" +set "CMAKE_PLAT=" set "LATEST_VS=" set "NEWER_VS_WITH_OLDER_VC=" set "USE_NEW_CMAKE_GEN_SYNTAX=" diff --git a/recipe/deactivate.bat b/recipe/deactivate.bat index 0c7dd0b..776c540 100644 --- a/recipe/deactivate.bat +++ b/recipe/deactivate.bat @@ -3,8 +3,8 @@ setlocal enabledelayedexpansion :: restore variables (if they existed prior to activation, they have a value that's not "placeholder") for %%X in ( - CC CXX CMAKE_ARGS CMAKE_GEN CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET - CMAKE_PLAT CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE + CC CXX CMAKE_ARGS CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET + CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL PY_VCRUNTIME_REDIST VS_MAJOR VS_VERSION VS_YEAR ) do ( From 6ef8a68c0a15f9c12c41a08d1a14e233200a1da3 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Fri, 28 Mar 2025 10:44:17 +1100 Subject: [PATCH 4/5] avoid placeholder values --- recipe/activate.bat | 4 +--- recipe/deactivate.bat | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/recipe/activate.bat b/recipe/activate.bat index 09ea79a..94f3a21 100755 --- a/recipe/activate.bat +++ b/recipe/activate.bat @@ -1,15 +1,13 @@ @@echo off setlocal enabledelayedexpansion -:: save existing variables for deactivation script; initialize all backups to a placeholder -:: (empty is the same as undefined), and only overwrite them if a value exists +:: save existing variables for deactivation script for %%X in ( CC CXX CMAKE_ARGS CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL PY_VCRUNTIME_REDIST VS_MAJOR VS_VERSION VS_YEAR ) do ( - set "_CONDA_BACKUP_%%X=placeholder" if defined %%X ( set "_CONDA_BACKUP_%%X=!%%X!" ) diff --git a/recipe/deactivate.bat b/recipe/deactivate.bat index 776c540..55f5da7 100644 --- a/recipe/deactivate.bat +++ b/recipe/deactivate.bat @@ -1,17 +1,15 @@ @@echo off setlocal enabledelayedexpansion -:: restore variables (if they existed prior to activation, they have a value that's not "placeholder") +:: restore variables for %%X in ( CC CXX CMAKE_ARGS CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET CMAKE_PREFIX_PATH CONDA_BUILD_CROSS_COMPILATION DISTUTILS_USE_SDK INCLUDE LIB MSSdk MSYS2_ARG_CONV_EXCL MSYS2_ENV_CONV_EXCL PY_VCRUNTIME_REDIST VS_MAJOR VS_VERSION VS_YEAR ) do ( - if "!_CONDA_BACKUP_%%X!" == "placeholder" ( - set "%%X=" - ) else ( + if defined _CONDA_BACKUP_%%X ( set "%%X=!_CONDA_BACKUP_%%X!" + set "_CONDA_BACKUP_%%X=" ) - set "_CONDA_BACKUP_%%X=" ) From b1d65e166eacb64bb926f31f865fb576711c1e7f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 27 Mar 2025 18:52:01 -0500 Subject: [PATCH 5/5] Fix logic --- recipe/deactivate.bat | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipe/deactivate.bat b/recipe/deactivate.bat index 55f5da7..572f7c8 100644 --- a/recipe/deactivate.bat +++ b/recipe/deactivate.bat @@ -11,5 +11,7 @@ for %%X in ( if defined _CONDA_BACKUP_%%X ( set "%%X=!_CONDA_BACKUP_%%X!" set "_CONDA_BACKUP_%%X=" + ) else ( + set "%%X=" ) )