mirror of
https://codeberg.org/1414codeforge/crush.git
synced 2025-01-28 18:20:28 +01:00
[crush] Use actual Lua files for .lovedeps.
This commit is contained in:
parent
0bee25794c
commit
ffd72490f7
69
crush.lua
69
crush.lua
@ -7,29 +7,7 @@
|
|||||||
local io = require 'io'
|
local io = require 'io'
|
||||||
local os = require 'os'
|
local os = require 'os'
|
||||||
|
|
||||||
-- Utility functions
|
-- System specific functions
|
||||||
|
|
||||||
local function split(sep, s)
|
|
||||||
local t = {}
|
|
||||||
|
|
||||||
for i in s:gmatch("([^"..sep.."]+)") do
|
|
||||||
t[#t+1] = i
|
|
||||||
end
|
|
||||||
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
local function startswith(s, prefix)
|
|
||||||
return s:sub(1, #prefix) == prefix
|
|
||||||
end
|
|
||||||
|
|
||||||
local function trim(s)
|
|
||||||
local from = s:match("^%s*()")
|
|
||||||
|
|
||||||
return from > #s and "" or s:match(".*%S", from)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- System specific
|
|
||||||
--
|
--
|
||||||
-- Portions of this code are based on work from the LuaRocks project.
|
-- Portions of this code are based on work from the LuaRocks project.
|
||||||
-- LuaRocks is free software and uses the MIT license.
|
-- LuaRocks is free software and uses the MIT license.
|
||||||
@ -207,33 +185,54 @@ end
|
|||||||
|
|
||||||
-- .lovedeps file scan
|
-- .lovedeps file scan
|
||||||
|
|
||||||
|
local function map_file(name)
|
||||||
|
local fh = io.open(name, 'r')
|
||||||
|
if fh == nil then
|
||||||
|
error(name..": can't read file.")
|
||||||
|
end
|
||||||
|
|
||||||
|
local contents = fh:read('*all')
|
||||||
|
fh:close()
|
||||||
|
|
||||||
|
return contents
|
||||||
|
end
|
||||||
|
|
||||||
local function scandeps(manifest, mode, deps)
|
local function scandeps(manifest, mode, deps)
|
||||||
mode = mode or 'nodups'
|
mode = mode or 'nodups'
|
||||||
deps = deps or {}
|
deps = deps or {}
|
||||||
|
|
||||||
local i = 0
|
local contents = map_file(manifest)
|
||||||
|
contents = "return "..contents
|
||||||
|
|
||||||
for line in io.lines(manifest) do
|
local fun, res = load(contents, manifest, 't', {})
|
||||||
line = trim(line)
|
if not fun then
|
||||||
i = i + 1
|
error(res)
|
||||||
|
|
||||||
if line == "" or startswith(line, "#") then
|
|
||||||
goto skip
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local fields = split(' ', line)
|
local ok, def = pcall(fun)
|
||||||
if #fields ~= 2 then
|
if not ok then
|
||||||
error(manifest..":"..i..": Syntax error, line must be in 'name url' form.")
|
error(def) -- def is now pcall()'s error message
|
||||||
|
end
|
||||||
|
if type(def) ~= 'table' then
|
||||||
|
error("[\""..manifest.."\"] loading file resulted in a '"..type(def).."', 'table' expected.")
|
||||||
|
end
|
||||||
|
|
||||||
|
for name,url in pairs(def) do
|
||||||
|
if type(url) == 'function' then
|
||||||
|
goto skip -- ignore functions
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(url) ~= 'string' then
|
||||||
|
error(manifest..": unexpected type "..type(dep).." as "..name.." git repository URL.")
|
||||||
end
|
end
|
||||||
|
|
||||||
local name, url = fields[1], fields[2]
|
|
||||||
for i in ipairs(deps) do
|
for i in ipairs(deps) do
|
||||||
if name == deps[i].name then
|
if name == deps[i].name then
|
||||||
if mode == 'skipdups' then
|
if mode == 'skipdups' then
|
||||||
goto skip
|
goto skip
|
||||||
end
|
end
|
||||||
|
|
||||||
error(manifest..":"..i..": Duplicate dependency '"..name.."'.")
|
error(manifest..": Duplicate dependency '"..name.."'.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user