diff options
| author | ruki <[email protected]> | 2021-05-21 23:10:19 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-05-21 23:10:19 +0800 |
| commit | f1c8144ef2a1461defedfedea4ed331eba5dc5e6 (patch) | |
| tree | c8a5ebfb92e088b80a3f021161473976aa0282ac | |
| parent | 6eea080650bdf56d01384eb735f76a4aa56676f5 (diff) | |
support search packages from vcpkg
4 files changed, 116 insertions, 12 deletions
diff --git a/xmake/modules/package/manager/vcpkg/search_package.lua b/xmake/modules/package/manager/vcpkg/search_package.lua new file mode 100644 index 000000000..09bf65eef --- /dev/null +++ b/xmake/modules/package/manager/vcpkg/search_package.lua @@ -0,0 +1,57 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file search_package.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- search package using the vcpkg package manager +-- +-- @param name the package name with pattern +-- +function main(name) + + -- attempt to find vcpkg + local vcpkg = find_tool("vcpkg") + if not vcpkg then + raise("vcpkg not found!") + end + + -- search packages + local results = {} + local searchdata = os.iorunv(vcpkg.program, {"search", name}) + for _, line in ipairs(searchdata:split("\n", {plain = true})) do + local version + local splitinfo = line:split("%s+", {limit = 2}) + local packagename = splitinfo[1] + local description = splitinfo[2] + if description then + splitinfo = description:split("%s+", {limit = 2}) + if #splitinfo == 2 and splitinfo[1]:find('.', 1, true) then + version = splitinfo[1] + description = splitinfo[2] + end + end + if packagename:find(name) and not packagename:find('%[.*' .. name .. '.*%]') then + table.insert(results, {name = packagename, version = version, description = description}) + end + end + return results +end diff --git a/xmake/modules/package/manager/xmake/search_package.lua b/xmake/modules/package/manager/xmake/search_package.lua new file mode 100644 index 000000000..5b633852c --- /dev/null +++ b/xmake/modules/package/manager/xmake/search_package.lua @@ -0,0 +1,40 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file search_package.lua +-- + +-- imports +import("core.package.package", {alias = "core_package"}) +import("private.action.require.impl.repository") + +-- search package using the xmake package manager +-- +-- @param name the package name with pattern +-- +function main(name) + local results = {} + for _, packageinfo in ipairs(repository.searchdirs(name)) do + local package = core_package.load_from_repository(packageinfo.name, packageinfo.repo, packageinfo.packagedir) + if package then + local repo = package:repo() + local versions = package:versions() + table.insert(results, {name = package:name(), version = versions and versions[1], description = package:get("description"), reponame = repo and repo:name()}) + end + end + return results +end diff --git a/xmake/modules/private/action/require/impl/search_packages.lua b/xmake/modules/private/action/require/impl/search_packages.lua index 49183a6cc..00cf1ffbf 100644 --- a/xmake/modules/private/action/require/impl/search_packages.lua +++ b/xmake/modules/private/action/require/impl/search_packages.lua @@ -18,19 +18,23 @@ -- @file search_packages.lua -- --- imports -import("core.package.package", {alias = "core_package"}) -import("private.action.require.impl.repository") - -- search packages from repositories function _search_packages(name) + -- get package manager name + local manager_name, package_name = unpack(name:split("::", {plain = true, strict = true})) + if package_name == nil then + package_name = manager_name + manager_name = "xmake" + else + manager_name = manager_name:lower():trim() + end + + -- search packages local packages = {} - for _, packageinfo in ipairs(repository.searchdirs(name)) do - local package = core_package.load_from_repository(packageinfo.name, packageinfo.repo, packageinfo.packagedir) - if package then - table.insert(packages, package) - end + local result = import("package.manager." .. manager_name .. ".search_package", {anonymous = true})(package_name) + if result then + table.join2(packages, result) end return packages end diff --git a/xmake/modules/private/action/require/search.lua b/xmake/modules/private/action/require/search.lua index dc3bdd892..3d8fb573c 100644 --- a/xmake/modules/private/action/require/search.lua +++ b/xmake/modules/private/action/require/search.lua @@ -52,9 +52,12 @@ function main(names) print(" %s: ", name) -- show packages - for _, instance in ipairs(packages) do - local repo = instance:repo() - cprint(" -> ${color.dump.string}%s${clear}: %s %s", instance:name(), instance:get("description") or "", repo and ("(in " .. repo:name() .. ")") or "") + for _, result in ipairs(packages) do + local name = result.name + local version = result.version + local reponame = result.reponame + local description = result.description + cprint(" -> ${color.dump.string}%s%s${clear}: %s %s", name, version and ("-" .. version) or "", description or "", reponame and ("(in " .. reponame .. ")") or "") end end end |
