forked from rrthomas/lrexlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkrockspecs.lua
72 lines (63 loc) · 1.69 KB
/
mkrockspecs.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- Generate the rockspecs
if select ("#", ...) < 1 then
io.stderr:write "Usage: mkrockspecs [-d<path>] VERSION\n"
os.exit ()
end
local dir
version = select (1, ...)
if version:sub(1,2) == "-d" then
dir = version:sub(3)
version = select (2, ...)
end
if not version then
error ("you must supply the VERSION argument")
end
if dir then
dir = dir:gsub("[/\\]+$", "")
for _, ext in ipairs {"lua"} do
if package.path:match ("%?%." .. ext) then
local path = dir .. "/?." .. ext .. ";"
if package.path:sub(1, #path) ~= path then
package.path = path .. package.path
end
break
end
end
end
require "std"
function format (x, indent)
indent = indent or ""
if type (x) == "table" then
local s = "{\n"
for i, v in pairs (x) do
if type (i) ~= "number" then
s = s..indent..i.." = "..format (v, indent.." ")..",\n"
end
end
for i, v in ipairs (x) do
s = s..indent..format (v, indent.." ")..",\n"
end
return s..indent:sub(1, -3).."}"
elseif type (x) == "string" then
return string.format ("%q", x)
else
return tostring (x)
end
end
for f, spec in pairs (loadfile ("rockspecs.lua") ()) do
if f ~= "default" then
local specfile = "lrexlib-"..f:lower ().."-"..version.."-1.rockspec"
h = io.open (specfile, "w")
assert (h)
flavour = f -- a global, visible in loadfile
local specs = loadfile ("rockspecs.lua") () -- reload to get current flavour interpolated
local spec = table.merge (specs.default, specs[f])
local s = ""
for i, v in pairs (spec) do
s = s..i.." = "..format (v, " ").."\n"
end
h:write (s)
h:close ()
os.execute ("luarocks lint " .. specfile)
end
end