Skip to content

Commit f7fadf0

Browse files
committed
fix(openssl/windows): capture the VS environment instead of calling vcvars
Running vcvars in a child cmd did not help — the log gained '[bat] handing build to child cmd' and vcvars' own success banner, and then stopped again with no RESULT from the OUTER script either. Whatever vcvars does on exit here, it is not something a caller can survive, in this process or a child of it. So it is no longer called. It now runs in a cmd whose only job is to dump the environment it produced, and those variables are imported into the build script: cmd /c ""%MCPP_VCVARS%" & set" > vsenv.txt for /f "tokens=1* delims==" %%a in (vsenv.txt) do set "%%a=%%b" This is the standard way build systems capture a Visual Studio environment, and it removes the dependency on vcvars returning to anybody. `&` is deliberate rather than `&&`: `set` has to run whatever exit status vcvars leaves behind. The dump also becomes evidence in its own right — if the toolset is not really there, the file is missing or short, and that is now a named failure (13) rather than a silent stop.
1 parent bcbeb9c commit f7fadf0

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

pkgs/c/compat.openssl.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,21 @@ local function _install_windows_impl()
476476
local logw = tostring(logf):gsub("/", "\\")
477477
local prefw = tostring(prefix):gsub("/", "\\")
478478
local innerw = tostring(inner):gsub("/", "\\")
479+
local envdump = path.join(prefix, "mcpp_vsenv.txt")
480+
local envw = tostring(envdump):gsub("/", "\\")
479481
io.writefile(inner, table.concat({
480482
"@echo off",
481-
-- vcvars runs HERE, in a child cmd, so whatever it does to its caller
482-
-- cannot reach the outer script.
483-
'call "%MCPP_VCVARS%" >> "' .. logw .. '" 2>&1',
484-
'if errorlevel 1 exit /b 13',
483+
-- vcvars is never `call`ed. Three runs showed the caller vanishing the
484+
-- moment it finished — even from a child cmd — so instead it runs in a
485+
-- cmd whose only job is to dump the resulting environment, and those
486+
-- variables are imported here. This is the standard way build systems
487+
-- capture a VS environment, and it does not depend on vcvars returning
488+
-- to anyone. Note `&` rather than `&&`: `set` must run whatever exit
489+
-- status vcvars leaves behind.
490+
'echo [bat] capturing VS environment >> "' .. logw .. '" 2>&1',
491+
'cmd /c ""%MCPP_VCVARS%" & set" > "' .. envw .. '" 2>>"' .. logw .. '"',
492+
'if not exist "' .. envw .. '" ( echo [bat] no env dump produced >> "' .. logw .. '" & exit /b 13 )',
493+
'for /f "usebackq tokens=1* delims==" %%a in ("' .. envw .. '") do set "%%a=%%b"',
485494
'echo [bat] toolset ready >> "' .. logw .. '" 2>&1',
486495
'cd /d "' .. srcroot .. '"',
487496
'if errorlevel 1 exit /b 14',

0 commit comments

Comments
 (0)