summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-05-18 23:12:33 +0800
committerruki <[email protected]>2023-05-18 23:12:33 +0800
commitebfbf35f2057606e95c6526823849f3bcc857d53 (patch)
tree2b61fe52cdd7fea965d37fa350b3203c223d1a95
parent3bc9b2b0a6344201baf2ffa0662df23c03a8cdf2 (diff)
fix find_tool from xmake/packages
-rw-r--r--xmake/core/package/package.lua2
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua10
-rw-r--r--xmake/modules/detect/tools/find_python.lua11
-rw-r--r--xmake/modules/lib/detect/find_tool.lua16
4 files changed, 14 insertions, 25 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 7508b207f..ab7d01b88 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 2ac26e660..dad9dbdd4 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 38a28b3bb..5f394b5e6 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 02c9c03d1..e761cb9a7 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