concat, targetnamesof. deps is now handled more consistently (treated the same
as ins but not passed in as inputs).
This commit is contained in:
parent
f70c12fad5
commit
cdbd605803
|
@ -53,6 +53,16 @@ local function asstring(o)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function concat(...)
|
||||||
|
local r = {}
|
||||||
|
for _, t in ipairs({...}) do
|
||||||
|
for _, v in ipairs(t) do
|
||||||
|
r[#r+1] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
local function concatpath(...)
|
local function concatpath(...)
|
||||||
local p = table.concat({...}, "/")
|
local p = table.concat({...}, "/")
|
||||||
return p:gsub("/+", "/"):gsub("^%./", ""):gsub("/%./", "/")
|
return p:gsub("/+", "/"):gsub("^%./", ""):gsub("/%./", "/")
|
||||||
|
@ -85,6 +95,27 @@ local function filenamesof(targets, pattern)
|
||||||
return f
|
return f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function targetnamesof(targets)
|
||||||
|
local f = {}
|
||||||
|
if targets then
|
||||||
|
if targets.is then
|
||||||
|
targets = {targets}
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, r in pairs(targets) do
|
||||||
|
if (type(r) == "table") and r.is then
|
||||||
|
f[#f+1] = r.fullname
|
||||||
|
elseif (type(r) == "string") then
|
||||||
|
f[#f+1] = r
|
||||||
|
else
|
||||||
|
error(string.format("list of targets contains a %s which isn't a target",
|
||||||
|
type(r)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return f
|
||||||
|
end
|
||||||
|
|
||||||
local function dotocollection(collection, callback)
|
local function dotocollection(collection, callback)
|
||||||
if (type(collection) == "string") then
|
if (type(collection) == "string") then
|
||||||
return callback(collection)
|
return callback(collection)
|
||||||
|
@ -389,25 +420,28 @@ local function definerule(rulename, types, cb)
|
||||||
end
|
end
|
||||||
|
|
||||||
args.environment = environment
|
args.environment = environment
|
||||||
args.fullname = cwd.."+"..args.name
|
|
||||||
args.rulecwd = rulecwd
|
|
||||||
if not args.cwd then
|
if not args.cwd then
|
||||||
args.cwd = cwd
|
args.cwd = cwd
|
||||||
end
|
end
|
||||||
|
args.fullname = args.cwd.."+"..args.name
|
||||||
|
|
||||||
local oldcwd = cwd
|
|
||||||
cwd = rulecwd
|
|
||||||
local result = cb(args) or {}
|
local result = cb(args) or {}
|
||||||
cwd = oldcwd
|
|
||||||
|
|
||||||
result.is = result.is or {}
|
result.is = result.is or {}
|
||||||
result.is[rulename] = true
|
result.is[rulename] = true
|
||||||
result.fullname = args.fullname
|
result.fullname = args.fullname
|
||||||
|
|
||||||
|
if targets[arg.fullname] and (targets[arg.fullname] ~= result) then
|
||||||
|
error(string.format("target '%s' is already defined", args.fullname))
|
||||||
|
end
|
||||||
targets[result.fullname] = result
|
targets[result.fullname] = result
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
if rulename then
|
if rulename then
|
||||||
|
if rules[rulename] then
|
||||||
|
error(string.format("rule '%s' is already defined", rulename))
|
||||||
|
end
|
||||||
rules[rulename] = rule
|
rules[rulename] = rule
|
||||||
end
|
end
|
||||||
return rule
|
return rule
|
||||||
|
@ -498,12 +532,15 @@ definerule("simplerule",
|
||||||
{
|
{
|
||||||
ins = { type="targets" },
|
ins = { type="targets" },
|
||||||
outs = { type="strings" },
|
outs = { type="strings" },
|
||||||
|
deps = { type="targets", default={} },
|
||||||
label = { type="string", optional=true },
|
label = { type="string", optional=true },
|
||||||
commands = { type="strings" },
|
commands = { type="strings" },
|
||||||
vars = { type="table", default={} },
|
vars = { type="table", default={} },
|
||||||
},
|
},
|
||||||
function (e)
|
function (e)
|
||||||
e.environment:rule(e.fullname, filenamesof(e.ins), e.outs)
|
e.environment:rule(e.fullname,
|
||||||
|
concat(filenamesof(e.ins), filenamesof(e.deps)),
|
||||||
|
e.outs)
|
||||||
e.environment:label(e.fullname, " ", e.label or "")
|
e.environment:label(e.fullname, " ", e.label or "")
|
||||||
|
|
||||||
local vars = inherit(e.vars, {
|
local vars = inherit(e.vars, {
|
||||||
|
@ -611,6 +648,7 @@ globals = {
|
||||||
abspath = abspath,
|
abspath = abspath,
|
||||||
asstring = asstring,
|
asstring = asstring,
|
||||||
basename = basename,
|
basename = basename,
|
||||||
|
concat = concat,
|
||||||
concatpath = concatpath,
|
concatpath = concatpath,
|
||||||
cwd = function() return cwd end,
|
cwd = function() return cwd end,
|
||||||
definerule = definerule,
|
definerule = definerule,
|
||||||
|
@ -618,12 +656,13 @@ globals = {
|
||||||
emit = emit,
|
emit = emit,
|
||||||
environment = environment,
|
environment = environment,
|
||||||
filenamesof = filenamesof,
|
filenamesof = filenamesof,
|
||||||
|
fpairs = fpairs,
|
||||||
include = loadbuildfile,
|
include = loadbuildfile,
|
||||||
inherit = inherit,
|
inherit = inherit,
|
||||||
replace = replace,
|
replace = replace,
|
||||||
selectof = selectof,
|
selectof = selectof,
|
||||||
startswith = startswith,
|
startswith = startswith,
|
||||||
fpairs = fpairs,
|
targetnamesof = targetnamesof,
|
||||||
uniquify = uniquify,
|
uniquify = uniquify,
|
||||||
}
|
}
|
||||||
setmetatable(globals,
|
setmetatable(globals,
|
||||||
|
|
|
@ -5,6 +5,7 @@ end
|
||||||
definerule("normalrule",
|
definerule("normalrule",
|
||||||
{
|
{
|
||||||
ins = { type="targets" },
|
ins = { type="targets" },
|
||||||
|
deps = { type="targets", default={} },
|
||||||
outleaves = { type="strings" },
|
outleaves = { type="strings" },
|
||||||
label = { type="string", optional=true },
|
label = { type="string", optional=true },
|
||||||
objdir = { type="string", optional=true },
|
objdir = { type="string", optional=true },
|
||||||
|
@ -25,6 +26,7 @@ definerule("normalrule",
|
||||||
local result = simplerule {
|
local result = simplerule {
|
||||||
name = e.name,
|
name = e.name,
|
||||||
ins = e.ins,
|
ins = e.ins,
|
||||||
|
deps = e.deps,
|
||||||
outs = realouts,
|
outs = realouts,
|
||||||
label = e.label,
|
label = e.label,
|
||||||
commands = e.commands,
|
commands = e.commands,
|
||||||
|
@ -69,7 +71,8 @@ definerule("cfile",
|
||||||
return normalrule {
|
return normalrule {
|
||||||
name = e.name,
|
name = e.name,
|
||||||
cwd = e.cwd,
|
cwd = e.cwd,
|
||||||
ins = {csrcs[1], unpack(hsrcs)},
|
ins = {csrcs[1]},
|
||||||
|
deps = e.deps,
|
||||||
outleaves = {outleaf},
|
outleaves = {outleaf},
|
||||||
label = e.label,
|
label = e.label,
|
||||||
commands = e.commands,
|
commands = e.commands,
|
||||||
|
@ -127,7 +130,6 @@ definerule("clibrary",
|
||||||
},
|
},
|
||||||
function (e)
|
function (e)
|
||||||
local csrcs = filenamesof(e.srcs, "%.c$")
|
local csrcs = filenamesof(e.srcs, "%.c$")
|
||||||
|
|
||||||
local hsrcs = filenamesof(e.srcs, "%.h$")
|
local hsrcs = filenamesof(e.srcs, "%.h$")
|
||||||
|
|
||||||
local ins = {}
|
local ins = {}
|
||||||
|
@ -203,6 +205,7 @@ definerule("cprogram",
|
||||||
return normalrule {
|
return normalrule {
|
||||||
name = e.name,
|
name = e.name,
|
||||||
cwd = e.cwd,
|
cwd = e.cwd,
|
||||||
|
deps = e.deps,
|
||||||
ins = libs,
|
ins = libs,
|
||||||
outleaves = { e.name },
|
outleaves = { e.name },
|
||||||
commands = e.commands,
|
commands = e.commands,
|
||||||
|
|
Loading…
Reference in a new issue