summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValleyKnight <[email protected]>2021-05-12 11:38:31 -0400
committerValleyKnight <[email protected]>2021-05-12 11:38:31 -0400
commitf031538aaa4be4c41d260388ead0d62d5cfdbb4a (patch)
treef8271cb9b00461bc33b4c3d641d44f8cd0257fe6
parent5f81bca5ec084de72556ec40656cbade7a90cf27 (diff)
remove gentoolkit dep, initial implementation of getting package files in pure lua
-rwxr-xr-xscripts/get.sh4
-rw-r--r--xmake/modules/package/manager/portage/find_package.lua38
2 files changed, 32 insertions, 10 deletions
diff --git a/scripts/get.sh b/scripts/get.sh
index fc049b519..8363b4499 100755
--- a/scripts/get.sh
+++ b/scripts/get.sh
@@ -153,12 +153,12 @@ install_tools()
{ yum --version >/dev/null 2>&1 && $sudoprefix yum install -y git readline-devel ccache && $sudoprefix yum groupinstall -y 'Development Tools'; } ||
{ zypper --version >/dev/null 2>&1 && $sudoprefix zypper --non-interactive install git readline-devel ccache && $sudoprefix zypper --non-interactive install -t pattern devel_C_C++; } ||
{ pacman -V >/dev/null 2>&1 && $sudoprefix pacman -S --noconfirm --needed git base-devel ccache; } ||
- { emerge -V >/dev/null 2>&1 && $sudoprefix emerge -atv dev-vcs/git ccache gentoolkit; } ||
+ { emerge -V >/dev/null 2>&1 && $sudoprefix emerge -atv dev-vcs/git ccache; } ||
{ pkg list-installed >/dev/null 2>&1 && $sudoprefix pkg install -y git getconf build-essential readline ccache; } || # termux
{ pkg help >/dev/null 2>&1 && $sudoprefix pkg install -y git readline ccache ncurses; } || # freebsd
{ apk --version >/dev/null 2>&1 && $sudoprefix apk add git gcc g++ make readline-dev ncurses-dev libc-dev linux-headers; }
}
-test_tools || { install_tools && test_tools; } || my_exit "$(echo -e 'Dependencies Installation Fail\nThe getter currently only support these package managers\n\t* apt\n\t* yum\n\t* zypper\n\t* pacman\n\t* portage\nPlease install following dependencies manually:\n\t* git\n\t* build essential like `make`, `gcc`, etc\n\t* libreadline-dev (readline-devel)\n\t* ccache (optional)\n\t* gentoolkit (only for Portage if on Gentoo)')" 1
+test_tools || { install_tools && test_tools; } || my_exit "$(echo -e 'Dependencies Installation Fail\nThe getter currently only support these package managers\n\t* apt\n\t* yum\n\t* zypper\n\t* pacman\n\t* portage\nPlease install following dependencies manually:\n\t* git\n\t* build essential like `make`, `gcc`, etc\n\t* libreadline-dev (readline-devel)\n\t* ccache (optional)')" 1
projectdir=$tmpdir
if [ 'x__local__' = "x$branch" ]; then
if [ -d '.git' ]; then
diff --git a/xmake/modules/package/manager/portage/find_package.lua b/xmake/modules/package/manager/portage/find_package.lua
index f4b08a482..c10b079ee 100644
--- a/xmake/modules/package/manager/portage/find_package.lua
+++ b/xmake/modules/package/manager/portage/find_package.lua
@@ -20,6 +20,7 @@
-- imports
import("core.base.option")
+import("lib.detect.find_file")
import("lib.detect.find_tool")
import("package.manager.pkgconfig.find_package", {alias = "find_package_from_pkgconfig"})
@@ -33,20 +34,41 @@ function main(name, opt)
-- init options
opt = opt or {}
- -- find equery
- local equery = find_tool("equery")
- if not equery then
- return
- end
-
-- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx
if opt.plat == "mingw" then
name = "mingw64-runtime" -- there is only one package for mingw
end
-- get package files list
- -- gentoolkit package is required until I can do what it does in pure lua
- local list = try { function() return os.iorunv(equery.program, {"f", name}) end }
+ local file_path = "/var/db/pkg/*/" .. name .. "-*/"
+ local file = find_file("CONTENTS", file_path)
+ local file_contents = try { function() return io.readfile(file) end }
+
+ -- if the file contents couldn't be obtained, the package isn't installed
+ if not file_contents then
+ return
+ end
+
+ -- create a table for the list
+ local list_table = {}
+ -- split entries based on newlines
+ for entry in file_contents:gmatch("(.-)\n") do
+ -- then split those entries based on spaces
+ for split_entry in entry:gmatch("(.-) ") do
+ -- then append to the table if the entry contains a `/`
+ if string.match(split_entry, "/") then
+ table.insert(list_table, split_entry)
+ end
+ end
+ end
+
+ -- create an initial empty string for the list
+ local list = ""
+ for _, value in pairs(list_table) do
+ -- append the values of the table elements to the string along with a newline
+ list = list .. value .. "\n"
+ end
+
if not list then
return
end