bliss

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

commit d78ac344955aedfba49e57fe900b2b4cb501cad5
parent cf39eb26924ee43da9ecc0987fcffc1a8144e40b
Author: phoebos <ben@bvnf.space>
Date:   Sun, 18 Jun 2023 01:44:26 +0100

barebones build

Diffstat:
Abliss/archive.lua | 30++++++++++++++++++++++++++++++
Abliss/build.lua | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mbliss/init.lua | 2+-
Mbliss/utils.lua | 9++++++++-
4 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/bliss/archive.lua b/bliss/archive.lua @@ -0,0 +1,30 @@ +local utils = require 'bliss.utils' +local dirent = require 'posix.dirent' +local stdio = require 'posix.stdio' + +-- extracts tarball to PWD +local function tar_extract(tarball) + if not utils.run("tar xf '" .. tarball .. "'") then + utils.die("failed to extract "..tarball) + end + + local top = dirent.dir() + if #top > 3 then utils.die("more than 1 top-level directory in tarball " .. tarball) end + for _,v in ipairs(top) do if v ~= '.' and v ~= '..' then top = v break end end + + local d = dirent.dir(top) + for _,file in ipairs(d) do + if file ~= '.' and file ~= '..' then + assert(file:sub(1,1) ~= '/') + local ok, e = stdio.rename(top..'/'..file, file) + if not ok then + utils.die("couldn't rename " .. file .. ": " .. e) + end + end + end +end + +local M = { + tar_extract = tar_extract, +} +return M diff --git a/bliss/build.lua b/bliss/build.lua @@ -0,0 +1,83 @@ +local utils = require 'bliss.utils' +local archive = require 'bliss.archive' +local pkg = require 'bliss.pkg' +local download = require 'bliss.download' +local checksum = require 'bliss.checksum' + +--[[ +-- These functions use a table containing cached package variables: +-- p = { +-- pkg, +-- repo_dir, +-- sources, +-- caches +-- } +--]] + +local function build_extract(env, p) + if #p.caches == 0 then return end + utils.log(p.pkg, "Extracting sources") + + for k,v in ipairs(p.caches) do + utils.mkcd(env.mak_dir..'/'..p.pkg..'/'..(p.sources[k][2] or '')) + local r = p.sources[k][1] + if r:match("^git%+") then + utils.run("cp -PRf '" .. v .. "/.' .") + elseif r:match("%.tar$") + or r:match("%.tar%...$") + or r:match("%.tar%....$") + or r:match("%.tar%.....$") + or r:match("%.t.z") then + archive.tar_extract(v) + else + utils.run("cp -PRf '" .. v .. "' .") + end + end +end + +local function build_build(env, p) + utils.mkcd(env.mak_dir..'/'..p.pkg, env.pkg_dir..'/'..p.pkg..'/'..env.pkg_db) + utils.log(p.pkg, "Starting build") + + local f = p.repo_dir .. '/build' + if not utils.run(f .. " " ..env.pkg_dir..'/'..p.pkg) then + utils.die(p.pkg, "Build failed") + end +end + +local function build(env, arg) + if #arg == 0 then end -- TODO + + local db = {} + + -- TODO: depends, order, check cache + + -- First, download and verify sources + for _,p in ipairs(arg) do + -- append sys_db + local path = utils.shallowcopy(env.PATH) + table.insert(path, env.sys_db) + + local repo_dir = pkg.find(p, path) + local sources = pkg.find_sources(p, repo_dir) + local caches = pkg.resolve(p, sources, env, repo_dir) + + download.download_sources(env, p, sources, caches) + checksum.verify_checksums(p, repo_dir, caches) + + table.insert(db, {pkg = p, repo_dir = repo_dir, sources = sources, caches = caches}) + end + + -- Now build + for _,p in ipairs(db) do + build_extract(env, p) + build_build(env, p) + + --local mani = manifest(env.pkg_dir, p) + end +end + +local M = { + build = build, +} +return M diff --git a/bliss/init.lua b/bliss/init.lua @@ -3,7 +3,7 @@ local cwd = (...):gsub('%.init$', '') local M = {} -- merge these into the toplevel bliss module -local names = {'utils', 'search', 'list', 'pkg', 'download', 'checksum'} +local names = {'utils', 'search', 'list', 'pkg', 'download', 'checksum', 'build'} for _, name in ipairs(names) do local t = require(cwd .. '.' .. name) for k, v in pairs(t) do diff --git a/bliss/utils.lua b/bliss/utils.lua @@ -4,7 +4,7 @@ local unistd = require 'posix.unistd' local signal = require 'posix.signal' local colors = {"", "", ""} -local setup, setup_colors, check_execute, get_available, get_pkg_clean, trap_on, trap_off, split, mkdirp, rm_rf, log, warn, die, prompt, run, capture, shallowcopy +local setup, setup_colors, check_execute, get_available, get_pkg_clean, trap_on, trap_off, split, mkdirp, mkcd, rm_rf, log, warn, die, prompt, run, capture, shallowcopy function setup() colors = setup_colors() @@ -137,6 +137,12 @@ function mkdirp(...) end end +function mkcd(...) + mkdirp(...) + local first = select(1, ...) + unistd.chdir(first) +end + function rm_rf(path) os.execute("rm -rf \"" .. path .. "\"") end @@ -198,6 +204,7 @@ local M = { trap_off = trap_off, split = split, mkdirp = mkdirp, + mkcd = mkcd, rm_rf = rm_rf, log = log, warn = warn,