From 9d01da2a9127f8400e231cfc38e80fa7320b6ef0 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 26 Jan 2024 23:50:30 +0800 Subject: [PATCH 1/2] remove PATH in xmake --- xmake/actions/build/cleaner.lua | 2 +- xmake/actions/update/main.lua | 4 ++-- xmake/core/main.lua | 8 -------- xmake/modules/package/tools/xmake.lua | 8 ++++---- xmake/modules/private/service/remote_build/action.lua | 2 +- xmake/modules/private/utils/completer.lua | 2 +- xmake/modules/private/utils/statistics.lua | 2 +- xmake/modules/private/xrepo/action/add-repo.lua | 4 ++-- xmake/modules/private/xrepo/action/clean.lua | 6 +++--- xmake/modules/private/xrepo/action/env.lua | 4 ++-- xmake/modules/private/xrepo/action/export.lua | 6 +++--- xmake/modules/private/xrepo/action/fetch.lua | 6 +++--- xmake/modules/private/xrepo/action/import.lua | 6 +++--- xmake/modules/private/xrepo/action/info.lua | 6 +++--- xmake/modules/private/xrepo/action/install.lua | 6 +++--- xmake/modules/private/xrepo/action/list-repo.lua | 4 ++-- xmake/modules/private/xrepo/action/remove.lua | 6 +++--- xmake/modules/private/xrepo/action/rm-repo.lua | 8 ++++---- xmake/modules/private/xrepo/action/scan.lua | 6 +++--- xmake/modules/private/xrepo/action/search.lua | 6 +++--- xmake/modules/private/xrepo/action/update-repo.lua | 4 ++-- 21 files changed, 49 insertions(+), 57 deletions(-) diff --git a/xmake/actions/build/cleaner.lua b/xmake/actions/build/cleaner.lua index 7c1eaed4b37..552cde98765 100644 --- a/xmake/actions/build/cleaner.lua +++ b/xmake/actions/build/cleaner.lua @@ -54,7 +54,7 @@ function cleanup() try { function () - process.openv("xmake", argv, {stdout = path.join(os.tmpdir(), "cleaner.log"), detach = true}):close() + process.openv(os.programfile(), argv, {stdout = path.join(os.tmpdir(), "cleaner.log"), detach = true}):close() end } end diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 4638151324f..43ef974a515 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -149,10 +149,10 @@ function _uninstall() end else if os.programdir():startswith("/usr/") then - _sudo_v("xmake", {"lua", "rm", os.programdir()}) + _sudo_v(os.programfile(), {"lua", "rm", os.programdir()}) for _, f in ipairs({"/usr/local/bin/xmake", "/usr/local/bin/xrepo", "/usr/bin/xmake", "/usr/bin/xrepo"}) do if os.isfile(f) then - _sudo_v("xmake", {"lua", "rm", f}) + _sudo_v(os.programfile(), {"lua", "rm", f}) end end else diff --git a/xmake/core/main.lua b/xmake/core/main.lua index e813c849a14..478f0181f34 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -202,14 +202,6 @@ function main._init() xmake._PROJECT_DIR = path.join(os.tmpdir(), "local") xmake._PROJECT_FILE = path.join(xmake._PROJECT_DIR, xmake._NAME .. ".lua") end - - -- add the directory of the program file (xmake) to $PATH environment - local programfile = os.programfile() - if programfile and os.isfile(programfile) then - os.addenv("PATH", path.directory(programfile)) - else - os.addenv("PATH", os.programdir()) - end return true end diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 379a46d1987..6112b9e5ba2 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -467,7 +467,7 @@ function install(package, configs, opt) local repo_argv = {"repo"} _set_builtin_argv(package, repo_argv) table.join2(repo_argv, {"--add", repo:name(), repo:directory()}) - os.vrunv("xmake", repo_argv, {envs = envs}) + os.vrunv(os.programfile(), repo_argv, {envs = envs}) end -- pass configurations @@ -488,7 +488,7 @@ function install(package, configs, opt) end -- do configure - os.vrunv("xmake", argv, {envs = envs}) + os.vrunv(os.programfile(), argv, {envs = envs}) -- do build argv = {"build"} @@ -500,7 +500,7 @@ function install(package, configs, opt) if njob then table.insert(argv, "--jobs=" .. njob) end - os.vrunv("xmake", argv, {envs = envs}) + os.vrunv(os.programfile(), argv, {envs = envs}) -- do install argv = {"install", "-y", "--nopkgs", "-o", package:installdir()} @@ -508,5 +508,5 @@ function install(package, configs, opt) if opt.target then table.insert(argv, opt.target) end - os.vrunv("xmake", argv, {envs = envs}) + os.vrunv(os.programfile(), argv, {envs = envs}) end diff --git a/xmake/modules/private/service/remote_build/action.lua b/xmake/modules/private/service/remote_build/action.lua index fcf3fff8936..f3a919f14e7 100644 --- a/xmake/modules/private/service/remote_build/action.lua +++ b/xmake/modules/private/service/remote_build/action.lua @@ -29,5 +29,5 @@ end function main() config.load() - remote_build_client.singleton():runcmd("xmake", xmake.argv()) + remote_build_client.singleton():runcmd(os.programfile(), xmake.argv()) end diff --git a/xmake/modules/private/utils/completer.lua b/xmake/modules/private/utils/completer.lua index 3dc01422722..f205ba86578 100644 --- a/xmake/modules/private/utils/completer.lua +++ b/xmake/modules/private/utils/completer.lua @@ -272,7 +272,7 @@ function completer:_complete_option(options, segs, completing) if current_options.project then table.insert(args, 2, "--project=" .. current_options.project) end - os.execv("xmake", args) + os.execv(os.programfile(), args) return true end diff --git a/xmake/modules/private/utils/statistics.lua b/xmake/modules/private/utils/statistics.lua index 615cfce7992..6ebe20c1391 100644 --- a/xmake/modules/private/utils/statistics.lua +++ b/xmake/modules/private/utils/statistics.lua @@ -86,7 +86,7 @@ function post() try { function () - process.openv("xmake", argv, {stdout = path.join(os.tmpdir(), projectname .. ".stats.log"), detach = true}):close() + process.openv(os.programfile(), argv, {stdout = path.join(os.tmpdir(), projectname .. ".stats.log"), detach = true}):close() end } diff --git a/xmake/modules/private/xrepo/action/add-repo.lua b/xmake/modules/private/xrepo/action/add-repo.lua index d2aef26e640..ecbd50aa330 100644 --- a/xmake/modules/private/xrepo/action/add-repo.lua +++ b/xmake/modules/private/xrepo/action/add-repo.lua @@ -59,7 +59,7 @@ function _add_repository(name, url, branch) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -77,7 +77,7 @@ function _add_repository(name, url, branch) if branch then table.insert(repo_argv, branch) end - os.vexecv("xmake", repo_argv) + os.vexecv(os.programfile(), repo_argv) end -- main entry diff --git a/xmake/modules/private/xrepo/action/clean.lua b/xmake/modules/private/xrepo/action/clean.lua index 25e44db39d1..9336455df80 100644 --- a/xmake/modules/private/xrepo/action/clean.lua +++ b/xmake/modules/private/xrepo/action/clean.lua @@ -62,7 +62,7 @@ function _clean_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -72,7 +72,7 @@ function _clean_packages(packages) if option.get("diagnosis") then table.insert(config_argv, "-vD") end - os.vrunv("xmake", config_argv) + os.vrunv(os.programfile(), config_argv) -- do clean local require_argv = {"require", "--clean"} @@ -91,7 +91,7 @@ function _clean_packages(packages) if packages then table.join2(require_argv, packages) end - os.vexecv("xmake", require_argv) + os.vexecv(os.programfile(), require_argv) end -- main entry diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 5a934792263..0919da2999b 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -102,11 +102,11 @@ function _enter_project() if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) os.rm("*") - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) end project.chdir(workdir) end diff --git a/xmake/modules/private/xrepo/action/export.lua b/xmake/modules/private/xrepo/action/export.lua index 551d978a3f5..9547351e8ce 100644 --- a/xmake/modules/private/xrepo/action/export.lua +++ b/xmake/modules/private/xrepo/action/export.lua @@ -104,7 +104,7 @@ function _export_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -143,7 +143,7 @@ function _export_packages(packages) if #rcfiles > 0 then envs.XMAKE_RCFILES = path.joinenv(rcfiles) end - os.vrunv("xmake", config_argv, {envs = envs}) + os.vrunv(os.programfile(), config_argv, {envs = envs}) -- do export local require_argv = {"require", "--export"} @@ -191,7 +191,7 @@ function _export_packages(packages) end table.join2(require_argv, packages) end - os.vexecv("xmake", require_argv, {envs = envs}) + os.vexecv(os.programfile(), require_argv, {envs = envs}) end -- export packages in current project diff --git a/xmake/modules/private/xrepo/action/fetch.lua b/xmake/modules/private/xrepo/action/fetch.lua index b54294a6865..8753b9cb5f3 100644 --- a/xmake/modules/private/xrepo/action/fetch.lua +++ b/xmake/modules/private/xrepo/action/fetch.lua @@ -113,7 +113,7 @@ function _fetch_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -152,7 +152,7 @@ function _fetch_packages(packages) if #rcfiles > 0 then envs.XMAKE_RCFILES = path.joinenv(rcfiles) end - os.vrunv("xmake", config_argv, {envs = envs}) + os.vrunv(os.programfile(), config_argv, {envs = envs}) -- do fetch local require_argv = {"require", "--fetch"} @@ -210,7 +210,7 @@ function _fetch_packages(packages) end table.join2(require_argv, packages) end - os.vexecv("xmake", require_argv, {envs = envs}) + os.vexecv(os.programfile(), require_argv, {envs = envs}) end -- main entry diff --git a/xmake/modules/private/xrepo/action/import.lua b/xmake/modules/private/xrepo/action/import.lua index 8c32e2c0f51..91c71cfe389 100644 --- a/xmake/modules/private/xrepo/action/import.lua +++ b/xmake/modules/private/xrepo/action/import.lua @@ -77,7 +77,7 @@ function _import_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -105,7 +105,7 @@ function _import_packages(packages) table.insert(config_argv, "-k") table.insert(config_argv, kind) end - os.vrunv("xmake", config_argv) + os.vrunv(os.programfile(), config_argv) -- do import local require_argv = {"require", "--import"} @@ -148,7 +148,7 @@ function _import_packages(packages) table.insert(require_argv, "--extra=" .. extra_str) end table.join2(require_argv, packages) - os.vexecv("xmake", require_argv) + os.vexecv(os.programfile(), require_argv) end -- import packages in current project diff --git a/xmake/modules/private/xrepo/action/info.lua b/xmake/modules/private/xrepo/action/info.lua index 3bc547b9476..f801621a2ff 100644 --- a/xmake/modules/private/xrepo/action/info.lua +++ b/xmake/modules/private/xrepo/action/info.lua @@ -70,7 +70,7 @@ function _info_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -98,7 +98,7 @@ function _info_packages(packages) table.insert(config_argv, "-k") table.insert(config_argv, kind) end - os.vrunv("xmake", config_argv) + os.vrunv(os.programfile(), config_argv) -- show info local require_argv = {"require", "--info"} @@ -131,7 +131,7 @@ function _info_packages(packages) table.insert(require_argv, "--extra=" .. extra_str) end table.join2(require_argv, packages) - os.vexecv("xmake", require_argv) + os.vexecv(os.programfile(), require_argv) end -- main entry diff --git a/xmake/modules/private/xrepo/action/install.lua b/xmake/modules/private/xrepo/action/install.lua index dfcaadf80ac..38515a8d421 100644 --- a/xmake/modules/private/xrepo/action/install.lua +++ b/xmake/modules/private/xrepo/action/install.lua @@ -143,7 +143,7 @@ function _install_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -235,7 +235,7 @@ function _install_packages(packages) if #rcfiles > 0 then envs.XMAKE_RCFILES = path.joinenv(rcfiles) end - os.vrunv("xmake", config_argv, {envs = envs}) + os.vrunv(os.programfile(), config_argv, {envs = envs}) -- do install local require_argv = {"require"} @@ -297,7 +297,7 @@ function _install_packages(packages) end table.join2(require_argv, packages) end - os.vexecv("xmake", require_argv, {envs = envs}) + os.vexecv(os.programfile(), require_argv, {envs = envs}) end -- main entry diff --git a/xmake/modules/private/xrepo/action/list-repo.lua b/xmake/modules/private/xrepo/action/list-repo.lua index 15861cad893..e9054beb7da 100644 --- a/xmake/modules/private/xrepo/action/list-repo.lua +++ b/xmake/modules/private/xrepo/action/list-repo.lua @@ -54,7 +54,7 @@ function list_repository() if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -67,7 +67,7 @@ function list_repository() if option.get("diagnosis") then table.insert(repo_argv, "-D") end - os.vexecv("xmake", repo_argv) + os.vexecv(os.programfile(), repo_argv) end -- main entry diff --git a/xmake/modules/private/xrepo/action/remove.lua b/xmake/modules/private/xrepo/action/remove.lua index dd850deb689..5a661d416a4 100644 --- a/xmake/modules/private/xrepo/action/remove.lua +++ b/xmake/modules/private/xrepo/action/remove.lua @@ -106,7 +106,7 @@ function _remove_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -145,7 +145,7 @@ function _remove_packages(packages) if #rcfiles > 0 then envs.XMAKE_RCFILES = path.joinenv(rcfiles) end - os.vrunv("xmake", config_argv, {envs = envs}) + os.vrunv(os.programfile(), config_argv, {envs = envs}) -- do remove local require_argv = {"require", "--uninstall"} @@ -184,7 +184,7 @@ function _remove_packages(packages) end table.join2(require_argv, packages) end - os.vexecv("xmake", require_argv) + os.vexecv(os.programfile(), require_argv) end -- main entry diff --git a/xmake/modules/private/xrepo/action/rm-repo.lua b/xmake/modules/private/xrepo/action/rm-repo.lua index 14040b7e5ab..2f5fd7ded9c 100644 --- a/xmake/modules/private/xrepo/action/rm-repo.lua +++ b/xmake/modules/private/xrepo/action/rm-repo.lua @@ -58,7 +58,7 @@ function remove_repository(name) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -72,7 +72,7 @@ function remove_repository(name) table.insert(repo_argv, "-D") end table.insert(repo_argv, name) - os.vexecv("xmake", repo_argv) + os.vexecv(os.programfile(), repo_argv) end -- clear repository @@ -83,7 +83,7 @@ function clear_repository() if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -96,7 +96,7 @@ function clear_repository() if option.get("diagnosis") then table.insert(repo_argv, "-D") end - os.vexecv("xmake", repo_argv) + os.vexecv(os.programfile(), repo_argv) end -- main entry diff --git a/xmake/modules/private/xrepo/action/scan.lua b/xmake/modules/private/xrepo/action/scan.lua index a156d6c6580..b5d55a9b694 100644 --- a/xmake/modules/private/xrepo/action/scan.lua +++ b/xmake/modules/private/xrepo/action/scan.lua @@ -61,7 +61,7 @@ function _scan_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -71,7 +71,7 @@ function _scan_packages(packages) if option.get("diagnosis") then table.insert(config_argv, "-vD") end - os.vrunv("xmake", config_argv) + os.vrunv(os.programfile(), config_argv) -- do scan local require_argv = {"require", "--scan"} @@ -87,7 +87,7 @@ function _scan_packages(packages) if packages then table.join2(require_argv, packages) end - os.vexecv("xmake", require_argv) + os.vexecv(os.programfile(), require_argv) end -- main entry diff --git a/xmake/modules/private/xrepo/action/search.lua b/xmake/modules/private/xrepo/action/search.lua index e30cbe01ad6..a40adf62094 100644 --- a/xmake/modules/private/xrepo/action/search.lua +++ b/xmake/modules/private/xrepo/action/search.lua @@ -60,7 +60,7 @@ function _search_packages(packages) if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -70,7 +70,7 @@ function _search_packages(packages) if option.get("diagnosis") then table.insert(config_argv, "-vD") end - os.vrunv("xmake", config_argv) + os.vrunv(os.programfile(), config_argv) -- do search local require_argv = {"require", "--search"} @@ -81,7 +81,7 @@ function _search_packages(packages) table.insert(require_argv, "-D") end table.join2(require_argv, packages) - os.vexecv("xmake", require_argv) + os.vexecv(os.programfile(), require_argv) end -- main entry diff --git a/xmake/modules/private/xrepo/action/update-repo.lua b/xmake/modules/private/xrepo/action/update-repo.lua index b79e13b4d7d..8746a91be42 100644 --- a/xmake/modules/private/xrepo/action/update-repo.lua +++ b/xmake/modules/private/xrepo/action/update-repo.lua @@ -54,7 +54,7 @@ function update_repository() if not os.isdir(workdir) then os.mkdir(workdir) os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) + os.vrunv(os.programfile(), {"create", "-P", "."}) else os.cd(workdir) end @@ -67,7 +67,7 @@ function update_repository() if option.get("diagnosis") then table.insert(repo_argv, "-D") end - os.vexecv("xmake", repo_argv) + os.vexecv(os.programfile(), repo_argv) end -- main entry From c4e9dcda21240b9683273a771d4c79446d706d91 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 26 Jan 2024 23:51:21 +0800 Subject: [PATCH 2/2] improve sudo lua --- xmake/modules/privilege/sudo.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/privilege/sudo.lua b/xmake/modules/privilege/sudo.lua index d1fd93b7648..ac872ac6721 100644 --- a/xmake/modules/privilege/sudo.lua +++ b/xmake/modules/privilege/sudo.lua @@ -85,7 +85,7 @@ function _lua(runner, luafile, luaargv) end -- run it with administrator permission - _sudov(runner, "xmake", table.join(argv, luafile, luaargv)) + _sudov(runner, os.programfile(), table.join(argv, luafile, luaargv)) end -- has sudo?