Skip to content

Commit 6fdf286

Browse files
committed
fix(openssl/windows): report through the log, not through the exit code
Second windows run, with the instrumentation from the previous commit: [mcpp] call failed: path.absolute(srcroot) -> attempt to call a nil value [mcpp] wrote ...\mcpp_openssl_build.bat; running it [mcpp] batch returned; ok=true err=nil [mcpp] (no lib/ directory was produced) Two findings, both acted on: 1. path.absolute() is not in the xlings sandbox either — the `safe` helper caught it and fell back, which is what let the run continue at all. The call is now gone rather than guarded: pkginfo.install_file() already returns an absolute path, so srcroot derived from it is absolute too. What the path DOES need is separator normalisation — it arrives with '/' and '\' mixed, and cmd wants backslashes. 2. os.exec reported success for a batch that produced nothing and wrote nothing to the log. That channel cannot be trusted here, so the batch no longer communicates through its exit code: every step echoes into the log BEFORE running, and the script always exits 0 after recording RESULT=<code>, which Lua reads back and decides on. os.exec's return is kept but demoted to an advisory log line. The batch is also written with plain \n now. io.writefile already produces CRLF on windows, so emitting \r\n gave \r\r\n — a batch whose stray CR lands inside `set` values and breaks parsing in exactly the way observed: no output, no work, and a clean exit.
1 parent 37ae194 commit 6fdf286

1 file changed

Lines changed: 54 additions & 21 deletions

File tree

pkgs/c/compat.openssl.lua

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -447,41 +447,74 @@ local function _install_windows_impl()
447447
for _, f in ipairs(entries) do note(" " .. tostring(f)) end
448448
return false
449449
end
450-
srcroot = safe("path.absolute(srcroot)", function() return path.absolute(srcroot) end, srcroot)
450+
-- path.absolute() is NOT in the xlings sandbox (verified: "attempt to call
451+
-- a nil value"), and it is not needed — pkginfo.install_file() already
452+
-- returns an absolute path, so srcroot derived from it is absolute too.
453+
-- cmd wants backslashes; the path arrives with both separators mixed.
454+
srcroot = tostring(srcroot):gsub("/", "\\")
451455
note("srcroot=" .. tostring(srcroot))
452456

453457
-- vswhere is installed with every VS 2017+ at a fixed location, and is the
454458
-- supported way to find the toolset; hardcoding a VS path breaks on the
455459
-- next release. `-products *` is required or Build Tools-only machines
456460
-- (which is what CI images often are) report nothing.
461+
-- The batch reports through the LOG, not through its exit code: the first
462+
-- attempt came back ok=true from os.exec while having produced nothing and
463+
-- written nothing, so that channel cannot be trusted here. Every step
464+
-- announces itself into the log BEFORE running, and the script always
465+
-- exits 0 after recording RESULT=<code>, which is what Lua then reads.
466+
--
467+
-- Written with plain \n: io.writefile on windows already produces CRLF, and
468+
-- emitting \r\n here would give \r\r\n — a batch file whose stray CR ends
469+
-- up inside `set` values and breaks parsing in ways that look like nothing
470+
-- happened at all.
471+
local logw = tostring(logf):gsub("/", "\\")
472+
local prefw = tostring(prefix):gsub("/", "\\")
457473
io.writefile(bat, table.concat({
458474
"@echo off",
459-
"setlocal",
475+
'echo [bat] started >> "' .. logw .. '" 2>&1',
460476
'set "VSWHERE=%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe"',
461-
'if not exist "%VSWHERE%" exit /b 10',
462-
'for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * ' ..
463-
'-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ' ..
464-
'-property installationPath`) do set "VSPATH=%%i"',
465-
'if not defined VSPATH exit /b 11',
477+
'echo [bat] vswhere=%VSWHERE% >> "' .. logw .. '" 2>&1',
478+
'if not exist "%VSWHERE%" ( echo [bat] RESULT=10 vswhere missing >> "' .. logw .. '" & exit /b 0 )',
479+
'for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSPATH=%%i"',
480+
'echo [bat] vspath=%VSPATH% >> "' .. logw .. '" 2>&1',
481+
'if not defined VSPATH ( echo [bat] RESULT=11 no VC toolset >> "' .. logw .. '" & exit /b 0 )',
466482
'set "VCVARS=%VSPATH%\\VC\\Auxiliary\\Build\\vcvars64.bat"',
467-
'if not exist "%VCVARS%" exit /b 12',
468-
'call "%VCVARS%" >nul || exit /b 13',
469-
'cd /d "' .. srcroot .. '" || exit /b 14',
470-
'(perl --version && nmake /? ) >> "' .. logf .. '" 2>&1',
471-
'perl Configure VC-WIN64A no-shared no-tests no-apps no-engine no-dso ' ..
472-
'--prefix="' .. prefix .. '" --openssldir="' .. prefix .. '\\ssl" ' ..
473-
'>> "' .. logf .. '" 2>&1 || exit /b 20',
474-
'nmake >> "' .. logf .. '" 2>&1 || exit /b 21',
475-
'nmake install_sw >> "' .. logf .. '" 2>&1 || exit /b 22',
483+
'if not exist "%VCVARS%" ( echo [bat] RESULT=12 no vcvars64 >> "' .. logw .. '" & exit /b 0 )',
484+
'call "%VCVARS%" >> "' .. logw .. '" 2>&1',
485+
'if errorlevel 1 ( echo [bat] RESULT=13 vcvars failed >> "' .. logw .. '" & exit /b 0 )',
486+
'echo [bat] toolset ready >> "' .. logw .. '" 2>&1',
487+
'cd /d "' .. srcroot .. '"',
488+
'if errorlevel 1 ( echo [bat] RESULT=14 cd failed >> "' .. logw .. '" & exit /b 0 )',
489+
'where perl >> "' .. logw .. '" 2>&1',
490+
'where nmake >> "' .. logw .. '" 2>&1',
491+
'echo [bat] configuring >> "' .. logw .. '" 2>&1',
492+
'perl Configure VC-WIN64A no-shared no-tests no-apps no-engine no-dso --prefix="' .. prefw .. '" --openssldir="' .. prefw .. '\\ssl" >> "' .. logw .. '" 2>&1',
493+
'if errorlevel 1 ( echo [bat] RESULT=20 Configure failed >> "' .. logw .. '" & exit /b 0 )',
494+
'echo [bat] building >> "' .. logw .. '" 2>&1',
495+
'nmake >> "' .. logw .. '" 2>&1',
496+
'if errorlevel 1 ( echo [bat] RESULT=21 nmake failed >> "' .. logw .. '" & exit /b 0 )',
497+
'echo [bat] installing >> "' .. logw .. '" 2>&1',
498+
'nmake install_sw >> "' .. logw .. '" 2>&1',
499+
'if errorlevel 1 ( echo [bat] RESULT=22 nmake install_sw failed >> "' .. logw .. '" & exit /b 0 )',
500+
'echo [bat] RESULT=0 >> "' .. logw .. '" 2>&1',
476501
"exit /b 0",
477-
}, "\r\n") .. "\r\n")
502+
}, "\n") .. "\n")
478503

479504
note("wrote " .. bat .. "; running it")
480-
local ok, err = pcall(os.exec, string.format('cmd /c "%s"', bat))
481-
note("batch returned; ok=" .. tostring(ok) .. " err=" .. tostring(err))
482-
if not ok then
505+
local batw = tostring(bat):gsub("/", "\\")
506+
local ok, err = pcall(os.exec, string.format('cmd /c "%s"', batw))
507+
note("os.exec ok=" .. tostring(ok) .. " err=" .. tostring(err)
508+
.. " (advisory only -- RESULT= in this log decides)")
509+
510+
local content = ""
511+
local rok, rdata = pcall(io.readfile, logf)
512+
if rok and rdata then content = tostring(rdata) end
513+
local result = content:match("%[bat%] RESULT=(%d+)")
514+
note("batch RESULT=" .. tostring(result))
515+
if result ~= "0" then
483516
local tail = tail_lines(logf, 40) or "<no log; the failure was before the build started>"
484-
log.error("%s", "compat.openssl: windows build failed (" .. tostring(err) ..
517+
log.error("%s", "compat.openssl: windows build failed (RESULT=" .. tostring(result) ..
485518
")\nexit 10-13 = no Visual Studio C++ toolset found (vswhere/vcvars64), " ..
486519
"20-22 = Configure/nmake failed.\nHOST REQUIREMENTS on windows: perl " ..
487520
"(Strawberry Perl -- xim:perl has no windows build) and a Visual Studio " ..

0 commit comments

Comments
 (0)