diff options
| author | Saikari <[email protected]> | 2026-02-05 22:48:58 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-02-05 22:48:58 +0300 |
| commit | bb7879934dca1ef7b26584f4dfadc29462d5a059 (patch) | |
| tree | 3cdb88086027d96f6d3e12dea0038ae361709df4 | |
| parent | 728ead07ff58cd9d8330075414cfe21b1034b757 (diff) | |
create policy besides pe parser
| -rw-r--r-- | core/src/xmake/engine.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/winos/set_error_mode.c | 7 | ||||
| -rw-r--r-- | projects/test_windows_links/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/run/main.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/policy.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 19 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/winos.lua | 1 |
7 files changed, 34 insertions, 1 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 9c02d8487..ccd77e7e5 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -279,6 +279,7 @@ tb_int_t xm_winos_registry_keys(lua_State *lua); tb_int_t xm_winos_registry_values(lua_State *lua); tb_int_t xm_winos_short_path(lua_State *lua); tb_int_t xm_winos_processes(lua_State* lua); +tb_int_t xm_winos_set_error_mode(lua_State *lua); #endif // the utf8 functions @@ -485,6 +486,7 @@ static luaL_Reg const g_winos_functions[] = { { "registry_values", xm_winos_registry_values }, { "short_path", xm_winos_short_path }, { "processes", xm_winos_processes }, + { "seterrormode", xm_winos_set_error_mode }, { tb_null, tb_null }, }; #endif diff --git a/core/src/xmake/winos/set_error_mode.c b/core/src/xmake/winos/set_error_mode.c new file mode 100644 index 000000000..43131d2e2 --- /dev/null +++ b/core/src/xmake/winos/set_error_mode.c @@ -0,0 +1,7 @@ +#include "prefix.h" + +tb_int_t xm_winos_set_error_mode(lua_State *lua) { + tb_size_t mode = (tb_size_t)luaL_checkinteger(lua, 1); + lua_pushinteger(lua, (tb_int_t)SetErrorMode((UINT)mode)); + return 1; +} diff --git a/projects/test_windows_links/xmake.lua b/projects/test_windows_links/xmake.lua index 5d8c0d984..e856892d3 100644 --- a/projects/test_windows_links/xmake.lua +++ b/projects/test_windows_links/xmake.lua @@ -1,5 +1,7 @@ add_rules("mode.debug", "mode.release")
+set_policy("run.gui_error_dialogs", true)
+
target("foo")
set_kind("shared")
add_files("src/foo.c")
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 6cfe09d3a..899df8d61 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -63,7 +63,7 @@ function _do_run_target(target) if option.get("debug") then debugger.run(targetfile, args, {curdir = rundir, addenvs = addenvs, setenvs = setenvs}) else - os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach"), addenvs = addenvs, setenvs = setenvs}) + os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach"), addenvs = addenvs, setenvs = setenvs, winos_error_mode_gui = target:policy("run.gui_error_dialogs")}) end end diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 5123f0a5c..3f24d9a0f 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -34,6 +34,8 @@ function policy.policies() local policies = policy._POLICIES if not policies then policies = { + -- Enable/Disable Windows Error Reporting Dialogs + ["run.gui_error_dialogs"] = {description = "Enable Windows Error Reporting Dialogs during execution.", default = false, type = "boolean"}, -- We will check and ignore all unsupported flags by default, but we can also pass `{force = true}` to force to set flags, e.g. add_ldflags("-static", {force = true}) ["check.auto_ignore_flags"] = {description = "Enable check and ignore unsupported flags automatically.", default = true, type = "boolean"}, -- We will map gcc flags to the current compiler and linker by default. diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 197356ffa..5718f8dec 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -494,7 +494,24 @@ function sandbox_os.execv(program, argv, opt) -- run it opt = opt or {} + + -- check policy for GUI error dialogs (Windows only) + local old_mode + local winos + if os.is_host("windows") and opt.winos_error_mode_gui then + winos = require("sandbox/modules/winos") + if winos.seterrormode then + old_mode = winos.seterrormode(0) + end + end + local ok, errors = os.execv(program, argv, opt) + + -- restore error mode + if old_mode then + winos.seterrormode(old_mode) + end + if ok ~= 0 and not opt.try then -- get command @@ -509,6 +526,8 @@ function sandbox_os.execv(program, argv, opt) local missing_dlls = _get_missing_dlls(program) if #missing_dlls > 0 then errors = string.format("execv(%s) failed(%d): 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.", cmd, ok, table.concat(missing_dlls, "\n - ")) + else + errors = string.format("execv(%s) failed(%d): 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.", cmd, ok) end else errors = string.format("execv(%s) failed(%d)", cmd, ok) diff --git a/xmake/core/sandbox/modules/winos.lua b/xmake/core/sandbox/modules/winos.lua index eddcf91d4..862ed9a8b 100644 --- a/xmake/core/sandbox/modules/winos.lua +++ b/xmake/core/sandbox/modules/winos.lua @@ -35,6 +35,7 @@ sandbox_winos.logical_drives = winos.logical_drives sandbox_winos.cmdargv = winos.cmdargv sandbox_winos.processes = winos.processes sandbox_winos.inherit_handles_safely = winos.inherit_handles_safely +sandbox_winos.seterrormode = winos.seterrormode -- get windows system version function sandbox_winos.version() |
