bliss

KISS in Lua
git clone git://bvnf.space/bliss.git
Log | Files | Refs | README | LICENSE

commit aea84049683cb0c92abb1f29dad3a662a5270f8f
parent ffb747b8b5c7a877d3f0846833942f0f1340a4e0
Author: aabacchus <ben@bvnf.space>
Date:   Thu, 15 Jun 2023 18:14:05 +0100

add functions to resolve cache locations

Diffstat:
Mbliss/pkg.lua | 42+++++++++++++++++++++++++++++++++++++++---
1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/bliss/pkg.lua b/bliss/pkg.lua @@ -34,18 +34,54 @@ local function find_version(pkg, path) return ver[1] end -local function find_sources(pkg, path) - local pkgpath = find(pkg, path) - local p = pkgpath .. "/sources" +local function find_sources(pkg, repo_dir) + local p = repo_dir .. "/sources" local s = read_lines(p) if #s == 0 then utils.log(pkg, "no sources found") end return s end +local function resolve_git(pkg, source, env) + local fp = string.match(source[1], '/([^/]+)$') + if not fp then utils.die(pkg, "can't parse source '"..source[1].."'") end + fp = string.match(fp, '(.*)[@#]') or fp -- this follows kiss, but should it be (.-) (ie. shortest match)? + return env.src_dir .. '/' .. pkg .. '/' .. (source[2] and source[2] .. '/' or '') .. fp .. '/' +end + +local function resolve_http(pkg, source, env) + -- get file part of URL + local fp = string.match(source[1], '/([^/]+)$') + if not fp then utils.die(pkg, "can't parse source '" .. source[1] .. "'") end + return env.src_dir .. '/' .. pkg .. '/' .. (source[2] and source[2] .. '/' or '') .. fp +end + +local function resolve_file(pkg, source, env, repo_dir) + local f = repo_dir .. '/' .. source[1] + if not sys_stat.stat(f) then utils.die(pkg, "source '"..source[1].."' not found") end + return f +end + +-- returns an array of the cache locations corresponding to each source +local function resolve(pkg, sources, env, repo_dir) + local map = { + ["git+"] = resolve_git, + ["http"] = resolve_http, + } + local caches = {} + + for _, v in ipairs(sources) do + local f = map[v[1]:sub(1, 4)] or resolve_file + local c = f(pkg, v, env, repo_dir) + if c then table.insert(caches, c) end + end + return caches +end + local M = { find = find, find_version = find_version, find_sources = find_sources, + resolve = resolve, } return M