Skip to content

Commit

Permalink
Merge pull request #3755 from xmake-io/package
Browse files Browse the repository at this point in the history
fix find_tool from xmake/packages
  • Loading branch information
waruqi authored May 18, 2023
2 parents 3bc9b2b + ebfbf35 commit 1644b24
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
2 changes: 2 additions & 0 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions xmake/core/sandbox/modules/import/lib/detect/find_program.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
--
Expand Down
11 changes: 3 additions & 8 deletions xmake/modules/detect/tools/find_python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -57,7 +54,5 @@ function main(opt)
end
version = find_programver(program, opt)
end

-- ok?
return program, version
end
16 changes: 1 addition & 15 deletions xmake/modules/lib/detect/find_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
--
Expand All @@ -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
Expand Down

0 comments on commit 1644b24

Please sign in to comment.