commit 4dcbd333bfe0449584a22838c3874b6c692bfe46
parent cd6f67772e58915ef46c15dcd80d740dd45bd6b7
Author: phoebos <ben@bvnf.space>
Date: Thu, 29 Jun 2023 20:48:48 +0100
meta: prefer " over ' for Lua strings
Yes, they're equivalent but this is just for consistency. I only chose "
because I'm used to C.
Diffstat:
12 files changed, 97 insertions(+), 97 deletions(-)
diff --git a/bliss/archive.lua b/bliss/archive.lua
@@ -1,7 +1,7 @@
-local utils = require 'bliss.utils'
-local dirent = require 'posix.dirent'
-local stdio = require 'posix.stdio'
-local unistd = require 'posix.unistd'
+local utils = require "bliss.utils"
+local dirent = require "posix.dirent"
+local stdio = require "posix.stdio"
+local unistd = require "posix.unistd"
-- extracts tarball to PWD
local function tar_extract(tarball)
@@ -11,13 +11,13 @@ local function tar_extract(tarball)
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
+ 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 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
@@ -28,9 +28,9 @@ end
-- p is a package table as in bliss.build
local function tar_create(env, p)
utils.log(p.pkg, "Creating tarball")
- unistd.chdir(env.pkg_dir .. '/' .. p.pkg)
+ unistd.chdir(env.pkg_dir .. "/" .. p.pkg)
- local _tar_file = env.bin_dir .. '/' .. p.pkg .. '@' .. p.ver .. '-' .. p.rel .. '.tar.' .. env.COMPRESS
+ local _tar_file = env.bin_dir .. "/" .. p.pkg .. "@" .. p.ver .. "-" .. p.rel .. ".tar." .. env.COMPRESS
-- env.COMPRESS is definitely one of the below (checked in utils.setup)
local compress_map = {
diff --git a/bliss/build.lua b/bliss/build.lua
@@ -1,10 +1,10 @@
-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'
-local glob = require 'posix.glob'
-local libgen = require 'posix.libgen'
+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"
+local glob = require "posix.glob"
+local libgen = require "posix.libgen"
--[[
-- These functions use a table containing cached package variables:
@@ -23,7 +23,7 @@ local function build_extract(env, p)
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 ''))
+ 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.."/.", "."})
@@ -40,13 +40,13 @@ local function build_extract(env, p)
end
local function build_build(env, p)
- local destdir = env.pkg_dir .. '/' .. p.pkg
- utils.mkcd(env.mak_dir..'/'..p.pkg, destdir..'/'..env.pkg_db)
+ local destdir = env.pkg_dir .. "/" .. p.pkg
+ utils.mkcd(env.mak_dir.."/"..p.pkg, destdir.."/"..env.pkg_db)
utils.log(p.pkg, "Starting build")
-- TODO: tee log
- local f = p.repo_dir .. '/build'
+ local f = p.repo_dir .. "/build"
-- TODO: env
if not utils.run(f, {destdir, p.ver}) then
utils.die(p.pkg, "Build failed")
@@ -69,10 +69,10 @@ local function gen_manifest(env, p)
local t = glob.glob(dir, glob.GLOB_MARK)
for _,v in ipairs(t) do
- if libgen.basename(v) ~= 'charset.alias' and v:sub(-3) ~= '.la' then
+ if libgen.basename(v) ~= "charset.alias" and v:sub(-3) ~= ".la" then
table.insert(mani, v)
- if v:sub(-1) == '/' then
- local m = recurse_find(v .. '*')
+ if v:sub(-1) == "/" then
+ local m = recurse_find(v .. "*")
-- join this result to mani.
for i=1,#m do
@@ -85,10 +85,10 @@ local function gen_manifest(env, p)
return mani
end
- local destdir = env.pkg_dir .. '/' .. p.pkg
- local manifest_file = destdir .. '/' .. env.pkg_db .. '/' .. p.pkg .. '/manifest'
+ local destdir = env.pkg_dir .. "/" .. p.pkg
+ local manifest_file = destdir .. "/" .. env.pkg_db .. "/" .. p.pkg .. "/manifest"
- local mani = recurse_find(destdir .. '/*')
+ local mani = recurse_find(destdir .. "/*")
table.insert(mani, manifest_file)
-- TODO: etcsums
@@ -97,11 +97,11 @@ local function gen_manifest(env, p)
table.sort(mani, function (a,b) return b < a end)
-- Remove the prefix from each line and write to the manifest file.
- local f = io.open(manifest_file, 'w')
+ local f = io.open(manifest_file, "w")
local prefix_len = string.len(destdir)
for _,v in ipairs(mani) do
- f:write(v:sub(prefix_len + 1) .. '\n')
+ f:write(v:sub(prefix_len + 1) .. "\n")
end
f:close()
diff --git a/bliss/checksum.lua b/bliss/checksum.lua
@@ -1,7 +1,7 @@
-local utils = require 'bliss.utils'
-local b3sum = require 'bliss.b3sum'
-local pkg = require 'bliss.pkg'
-local download = require 'bliss.download'
+local utils = require "bliss.utils"
+local b3sum = require "bliss.b3sum"
+local pkg = require "bliss.pkg"
+local download = require "bliss.download"
-- returns a string of the BLAKE3 checksum of the contents of filename
local function checksum_file(filename)
@@ -25,15 +25,15 @@ local function checksum(env, arg)
download.download_sources(env, p, sources, cache)
- local f = assert(io.open(repo_dir .. '/checksums', 'w'))
+ local f = assert(io.open(repo_dir .. "/checksums", "w"))
- local sums = ''
+ local sums = ""
for i, v in ipairs(cache) do
- local map = {['git+'] = 1, ['http'] = 2}
+ local map = {["git+"] = 1, ["http"] = 2}
local t = map[string.sub(sources[i][1], 1, 4)] or 3
if t ~= 1 then
local sum = checksum_file(v)
- sums = sums .. sum .. '\n'
+ sums = sums .. sum .. "\n"
end
end
if #sums ~= 0 then
diff --git a/bliss/download.lua b/bliss/download.lua
@@ -1,7 +1,7 @@
-local utils = require 'bliss.utils'
-local pkg = require 'bliss.pkg'
-local sys_stat = require 'posix.sys.stat'
-local libgen = require 'posix.libgen'
+local utils = require "bliss.utils"
+local pkg = require "bliss.pkg"
+local sys_stat = require "posix.sys.stat"
+local libgen = require "posix.libgen"
local function git(env, p, source, dest)
utils.die("git is not yet supported")
@@ -15,11 +15,11 @@ local function http(env, p, source, dest)
-- TODO: use a library?
if not env.GET then utils.die("No http download utility available") end
local args_map = {
- aria2c = {'-d', '/', '-o'},
- axel = {'-o'},
- curl = {'-fLo'},
- wget = {'-O'},
- wget2 = {'-O'},
+ aria2c = {"-d", "/", "-o"},
+ axel = {"-o"},
+ curl = {"-fLo"},
+ wget = {"-O"},
+ wget2 = {"-O"},
}
local args = args_map[libgen.basename(env.GET)] or utils.die("'"..env.GET.."' is unsupported as KISS_GET")
@@ -45,7 +45,7 @@ end
local function download_sources(env, p, sources, dests)
assert(#dests == #sources)
- local map = {['git+'] = git, ['http'] = http}
+ local map = {["git+"] = git, ["http"] = http}
for k,v in ipairs(sources) do
local f = map[string.sub(v[1], 1, 4)] or file
diff --git a/bliss/init.lua b/bliss/init.lua
@@ -1,20 +1,20 @@
-local cwd = (...):gsub('%.init$', '')
+local cwd = (...):gsub("%.init$", "")
local M = {}
-- merge these into the toplevel bliss module
-local names = {'utils', 'search', 'list', 'pkg', 'download', 'checksum', 'build'}
+local names = {"utils", "search", "list", "pkg", "download", "checksum", "build"}
for _, name in ipairs(names) do
- local t = require(cwd .. '.' .. name)
+ local t = require(cwd .. "." .. name)
for k, v in pairs(t) do
M[k] = v
end
end
-- add these into submodules
-names = {'b3sum'}
+names = {"b3sum"}
for _, name in ipairs(names) do
- M[name] = require(cwd .. '.' .. name)
+ M[name] = require(cwd .. "." .. name)
end
return M
diff --git a/bliss/list.lua b/bliss/list.lua
@@ -1,17 +1,17 @@
-local pkg = require 'bliss.pkg'
-local dirent = require 'posix.dirent'
+local pkg = require "bliss.pkg"
+local dirent = require "posix.dirent"
local function list(env, arg)
if #arg == 0 then
for file in dirent.files(env.sys_db) do
- if string.sub(file, 1, 1) ~= '.' then
+ if string.sub(file, 1, 1) ~= "." then
table.insert(arg, file)
end
end
table.sort(arg)
end
for _,a in ipairs(arg) do
- local repo_dir = env.sys_db .. '/' .. a
+ local repo_dir = env.sys_db .. "/" .. a
local ver = pkg.find_version(a, repo_dir)
io.write(string.format("%s %s-%s\n", a, ver[1], ver[2]))
diff --git a/bliss/pkg.lua b/bliss/pkg.lua
@@ -1,12 +1,12 @@
-local utils = require 'bliss.utils'
-local sys_stat = require 'posix.sys.stat'
+local utils = require "bliss.utils"
+local sys_stat = require "posix.sys.stat"
local function read_lines(file)
local t = {}
local f = io.open(file)
if not f then return {} end
for line in f:lines() do
- table.insert(t, utils.split(line, ' '))
+ table.insert(t, utils.split(line, " "))
end
f:close()
return t
@@ -14,7 +14,7 @@ end
local function find(name, path)
for _, repo in ipairs(path) do
- local g = repo .. '/' .. name
+ local g = repo .. "/" .. name
local sb = sys_stat.stat(g)
if sb and sys_stat.S_ISDIR(sb.st_mode) ~= 0 then
return g
@@ -46,21 +46,21 @@ local function find_sources(pkg, repo_dir)
end
local function resolve_git(pkg, source, env)
- local fp = string.match(source[1], '/([^/]+)$')
+ 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 .. '/'
+ 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], '/([^/]+)$')
+ 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
+ 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]
+ 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
diff --git a/bliss/search.lua b/bliss/search.lua
@@ -1,6 +1,6 @@
-local utils = require 'bliss.utils'
-local glob = require 'posix.glob'
-local sys_stat = require 'posix.sys.stat'
+local utils = require "bliss.utils"
+local glob = require "posix.glob"
+local sys_stat = require "posix.sys.stat"
local function search(env, arg)
@@ -11,7 +11,7 @@ local function search(env, arg)
for _, a in ipairs(arg) do
local res = {}
for _, repo in ipairs(path) do
- local g = glob.glob(repo .. '/' .. a, 0)
+ local g = glob.glob(repo .. "/" .. a, 0)
for _, i in pairs(g or {}) do
local sb = sys_stat.stat(i)
diff --git a/bliss/utils.lua b/bliss/utils.lua
@@ -1,9 +1,9 @@
-- Copyright 2023 phoebos
-local sys_stat = require 'posix.sys.stat'
-local sys_wait = require 'posix.sys.wait'
-local unistd = require 'posix.unistd'
-local stdlib = require 'posix.stdlib'
-local signal = require 'posix.signal'
+local sys_stat = require "posix.sys.stat"
+local sys_wait = require "posix.sys.wait"
+local unistd = require "posix.unistd"
+local stdlib = require "posix.stdlib"
+local signal = require "posix.signal"
local colors = {"", "", ""}
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_shell, run, capture, shallowcopy
@@ -23,9 +23,9 @@ function setup()
GET = os.getenv("KISS_GET")
or get_available("aria2c", "axel", "curl", "wget", "wget2")
or warn("No download utility found (aria2c, axel, curl, wget, wget2"),
- HOOK = split(os.getenv("KISS_HOOK"), ':'),
+ HOOK = split(os.getenv("KISS_HOOK"), ":"),
KEEPLOG = os.getenv("KISS_KEEPLOG") or 0,
- PATH = split(os.getenv("KISS_PATH"), ':'),
+ PATH = split(os.getenv("KISS_PATH"), ":"),
PID = os.getenv("KISS_PID") or unistd.getpid(),
PROMPT = os.getenv("KISS_PROMPT") or 1,
ROOT = os.getenv("KISS_ROOT") or "",
@@ -51,14 +51,14 @@ function setup()
env.bin_dir = env.cac_dir .. "/bin"
env.TMPDIR = env.TMPDIR or (env.cac_dir .. "/proc")
- env.proc = env.TMPDIR .. '/' .. env.PID
+ env.proc = env.TMPDIR .. "/" .. env.PID
env.mak_dir = env.proc .. "/build"
env.pkg_dir = env.proc .. "/pkg"
env.tar_dir = env.proc .. "/extract"
env.tmp_dir = env.proc .. "/tmp"
- mkdirp(env.ROOT .. '/')
+ mkdirp(env.ROOT .. "/")
mkdirp(env.src_dir, env.log_dir, env.bin_dir,
env.mak_dir, env.pkg_dir, env.tar_dir, env.tmp_dir)
@@ -86,7 +86,7 @@ end
function get_available(...)
local x, res
- for i = 1, select('#', ...) do
+ for i = 1, select("#", ...) do
x = select(i, ...)
res = capture("command -v " .. x)
if res[1] then return res[1] end
@@ -128,13 +128,13 @@ function split(s, sep)
end
function mkdirp(...)
- for i = 1, select('#', ...) do
+ for i = 1, select("#", ...) do
local path = select(i, ...)
- assert(string.sub(path, 1, 1) == '/')
- local t = split(path, '/')
- local p = ''
+ assert(string.sub(path, 1, 1) == "/")
+ local t = split(path, "/")
+ local p = ""
for _, v in ipairs(t) do
- p = p .. '/' .. v
+ p = p .. "/" .. v
local sb = sys_stat.stat(p)
if not sb then
@@ -160,7 +160,7 @@ function log(name, msg, category)
io.stderr:write(string.format("%s%s %s%s%s %s\n",
colors[1],
category or "->",
- colors[3] .. (msg and colors[2] or ''),
+ colors[3] .. (msg and colors[2] or ""),
name,
colors[3],
msg or ""))
@@ -193,7 +193,7 @@ end
-- path is a string, cmd is an array, env is a table
-- Despite the variable name, path doesn't have to be absolute because execp is used.
function run(path, cmd, env)
- io.stderr:write(path .. ' ' .. table.concat(cmd, ' ', 1) .. '\n')
+ io.stderr:write(path .. " " .. table.concat(cmd, " ", 1) .. "\n")
local pid = unistd.fork()
@@ -218,7 +218,7 @@ end
-- Returns an array of lines printed by cmd
function capture(cmd)
- local p = io.popen(cmd, 'r')
+ local p = io.popen(cmd, "r")
local res = {}
for line in p:lines() do
table.insert(res, line)
diff --git a/doc.txt b/doc.txt
@@ -5,7 +5,7 @@ bliss/ contains the library, main.lua provides an interface to the library.
The library is split into multiple files, but bliss/init.lua collects them all
together so that the whole library is loaded if you run:
- local bliss = require 'bliss'
+ local bliss = require "bliss"
Most of the library functions are put directly into the bliss table (eg bliss.setup)
but some are put into a subtable:
@@ -44,8 +44,8 @@ MISC
If writing a library using bliss, you may prefer to require each submodule individually, like this:
- local pkg = require 'bliss.pkg'
- local utils = require 'bliss.utils'
+ local pkg = require "bliss.pkg"
+ local utils = require "bliss.utils"
utils.setup()
...
diff --git a/main.lua b/main.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env lua
-local bliss = require 'bliss'
+local bliss = require "bliss"
local function version()
print("0.0.0")
@@ -41,7 +41,7 @@ local function args(env, arg)
if #arg < 1 then usage() end
local char = string.sub(arg[1], 1, 1)
- if arg[1] == "upgrade" then char = 'U' end
+ if arg[1] == "upgrade" then char = "U" end
-- shift
table.remove(arg, 1)
diff --git a/test.lua b/test.lua
@@ -1,6 +1,6 @@
bliss = require "bliss"
-function tts(t) local s = "{ " local sep = "" for k,v in pairs(t) do s = s..sep..k.."="..v sep = ', ' end return s .. ' }' end
+function tts(t) local s = "{ " local sep = "" for k,v in pairs(t) do s = s..sep..k.."="..v sep = ", " end return s .. " }" end
env = bliss.setup()
for k,v in pairs(env) do
@@ -12,14 +12,14 @@ for k,v in pairs(env) do
end
local ctx = bliss.b3sum.init()
-bliss.b3sum.update(ctx, 'test\n')
+bliss.b3sum.update(ctx, "test\n")
local obs = bliss.b3sum.finalize(ctx)
local exp = bliss.capture("echo test | b3sum")
-local exp_ = bliss.split(exp[1], ' ')[1]
+local exp_ = bliss.split(exp[1], " ")[1]
assert(exp_ == obs)
-local p = 'feh'
+local p = "feh"
local repo_dir = bliss.find(p, env.PATH)
local sources = bliss.find_sources(p, repo_dir)
local caches = bliss.resolve(p, sources, env, repo_dir)