From ebfbf35f2057606e95c6526823849f3bcc857d53 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 May 2023 23:12:33 +0800 Subject: [PATCH] fix find_tool from xmake/packages --- xmake/core/package/package.lua | 2 ++ .../modules/import/lib/detect/find_program.lua | 10 ++++++++-- xmake/modules/detect/tools/find_python.lua | 11 +++-------- xmake/modules/lib/detect/find_tool.lua | 16 +--------------- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 7508b207fa7..ab7d01b886c 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1545,6 +1545,7 @@ function _instance:_fetch_tool(opt) fetchinfo = self:find_tool(self:name(), {require_version = opt.require_version, cachekey = "fetch_package_xmake", norun = true, -- we need not run it to check for xmake/packages, @see https://github.com/xmake-io/xmake-repo/issues/66 + system = false, -- we only find it from xmake/packages, @see https://github.com/xmake-io/xmake-repo/pull/2085 force = opt.force}) -- may be toolset, not single tool @@ -1641,6 +1642,7 @@ function _instance:find_tool(name, opt) version = true, -- we alway check version require_version = opt.require_version, norun = opt.norun, + system = opt.system, force = opt.force}) end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua index 2ac26e6601c..dad9dbdd40e 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -178,15 +178,20 @@ function sandbox_lib_detect_find_program._find(name, paths, opt) -- attempt to find it from the given directories local program_path = sandbox_lib_detect_find_program._find_from_paths(name, paths, opt) - if program_path then + if program_path and opt.system ~= false then return program_path end -- attempt to find it from the xmake packages - if opt.require_version and opt.buildhash then + if opt.require_version and opt.buildhash and opt.system ~= true then return sandbox_lib_detect_find_program._find_from_packages(name, opt) end + -- we will not continue to find system program + if opt.system == false then + return + end + -- attempt to find it from regists if os.host() == "windows" then local program_name = name:lower() @@ -250,6 +255,7 @@ end -- - opt.paths the program paths (e.g. dirs, paths, winreg paths, script paths) -- - opt.check the check script or command -- - opt.norun do not attempt to run program to check program fastly +-- - opt.system true: only find it from system, false: only find it from xmake/packages -- -- @return the program name or path -- diff --git a/xmake/modules/detect/tools/find_python.lua b/xmake/modules/detect/tools/find_python.lua index 38a28b3bb0b..5f394b5e6d0 100644 --- a/xmake/modules/detect/tools/find_python.lua +++ b/xmake/modules/detect/tools/find_python.lua @@ -38,17 +38,14 @@ import("detect.tools.find_python3") -- @endcode -- function main(opt) - - -- init options opt = opt or {} - - -- find program local program = find_program(opt.program or "python", opt) if not program then - program = find_python3() or find_python2() + local opt2 = table.clone(opt) + opt2.program = nil + program = find_python3(opt2) or find_python2(opt2) end - -- find program version local version = nil if program and opt.version then opt.command = function () @@ -57,7 +54,5 @@ function main(opt) end version = find_programver(program, opt) end - - -- ok? return program, version end diff --git a/xmake/modules/lib/detect/find_tool.lua b/xmake/modules/lib/detect/find_tool.lua index 02c9c03d110..e761cb9a7b8 100644 --- a/xmake/modules/lib/detect/find_tool.lua +++ b/xmake/modules/lib/detect/find_tool.lua @@ -26,8 +26,6 @@ import("core.base.semver") -- find tool from modules function _find_from_modules(name, opt) - - -- attempt to import "detect.tools.find_xxx" local find_tool = import("detect.tools.find_" .. name, {try = true}) if find_tool then local program, version, toolname = find_tool(opt) @@ -39,28 +37,20 @@ end -- find tool function _find_tool(name, opt) - - -- find tool name local toolname = find_toolname(name or opt.program) if toolname then - - -- attempt to find tool from modules first local tool = _find_from_modules(toolname, opt) if tool then return tool end end - -- init program opt.program = opt.program or name - - -- find program local program = find_program(opt.program, opt) if not program then return end - -- find tool version local version = nil if program and opt.version then version = find_programver(program, opt) @@ -73,7 +63,7 @@ end -- @param name the tool name -- @param opt the options, e.g. {program = "xcrun -sdk macosx clang", paths = {"/usr/bin"}, -- check = function (tool) os.run("%s -h", tool) end, version = true --- force = true, cachekey = "xxx", envs = {PATH = "xxx"}} +-- force = true, cachekey = "xxx", envs = {PATH = "xxx"}, system = false} -- -- @return {name = "", program = "", version = ""} or nil -- @@ -91,15 +81,11 @@ end -- @endcode -- function main(name, opt) - - -- do find opt = opt or {} if opt.require_version then opt.version = true end local result = _find_tool(name, opt) - - -- match version? if opt.require_version and opt.require_version:find('.', 1, true) and result then if not (result.version and (result.version == opt.require_version or semver.satisfies(result.version, opt.require_version))) then result = nil