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 /xmake/modules/package/manager | |
| parent | 6eea080650bdf56d01384eb735f76a4aa56676f5 (diff) | |
support search packages from vcpkg
Diffstat (limited to 'xmake/modules/package/manager')
| -rw-r--r-- | xmake/modules/package/manager/vcpkg/search_package.lua | 57 | ||||
| -rw-r--r-- | xmake/modules/package/manager/xmake/search_package.lua | 40 |
2 files changed, 97 insertions, 0 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 |
