diff options
| author | ruki <[email protected]> | 2026-02-07 00:52:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-02-07 00:52:20 +0800 |
| commit | 791292f2ee65a4ca8566c3e7a38cbcbf965ddd08 (patch) | |
| tree | b3d1bd6944c3e704828d904a0698fb8e44bf328d /xmake/core/base | |
| parent | 6007059c47a51d5847772fb68e357e4869ba85b3 (diff) | |
improve run policy and missing dll
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/os.lua | 5 | ||||
| -rw-r--r-- | xmake/core/base/process.lua | 43 |
2 files changed, 47 insertions, 1 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index ae730738e..d20cd671a 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -1020,6 +1020,9 @@ function os.execv(program, argv, opt) local waitok, status = proc:wait(opt.timeout or -1) if waitok > 0 then ok = status + if ok and ok ~= 0 then + errors = process.get_exit_errors(filename, ok) + end elseif waitok == 0 and opt.timeout then proc:kill() waitok, status = proc:wait(-1) @@ -1093,7 +1096,7 @@ function os.iorunv(program, argv, opt) if argv then cmd = cmd .. " " .. os.args(argv) end - errors = string.format("cannot runv(%s), %s", cmd, errors and errors or "unknown reason") + errors = string.format("cannot runv(%s), %s", cmd, errors or "unknown reason") end -- get output and error data diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua index 5436115ed..bea469346 100644 --- a/xmake/core/base/process.lua +++ b/xmake/core/base/process.lua @@ -271,5 +271,48 @@ function process.openv(program, argv, opt) end end +-- get missing dlls +function process._get_missing_dlls(program) + + -- get paths + local pathenv = os.getenv("PATH") or "" + local paths = path.splitenv(pathenv) + table.insert(paths, 1, path.directory(program)) + + -- find missing dlls + local missing = {} + local binutils = require("base/binutils") + local imports = binutils.deplibs(program) or {} + for _, dll in ipairs(imports) do + local found = false + for _, p in ipairs(paths) do + if os.isfile(path.join(p, dll)) then + found = true + break + end + end + if not found then + table.insert(missing, dll) + end + end + return missing +end + +-- get process exit errors +function process.get_exit_errors(program, exitcode) + if is_host("windows") then + -- DLL is missing, 0xC0000135 + if exitcode == -1073741515 and os.isexec(program) then + local missing_dlls = process._get_missing_dlls(program) + if #missing_dlls > 0 then + errors = string.format("system error 0xC0000135 (STATUS_DLL_NOT_FOUND).\nThe application failed to start because the following DLLs were not found:\n - %s\nPlease check your PATH environment variable or copy the missing DLLs to the executable directory.", table.concat(missing_dlls, "\n - ")) + else + errors = string.format("system error 0xC0000135 (STATUS_DLL_NOT_FOUND).\nThe application failed to start because a dependent DLL was not found.\nPlease check your PATH environment variable or copy the missing DLL to the executable directory.") + end + end + end +end + + -- return module: process return process |
