46 lines
1.4 KiB
Lua
46 lines
1.4 KiB
Lua
|
|
import("core.project.depend")
|
||
|
|
function cmd_compile(genfile, sourcefile)
|
||
|
|
print(os.programdir())
|
||
|
|
import("find_sdk")
|
||
|
|
local meta = find_sdk.find_my_program("refl")
|
||
|
|
argv = {"build", sourcefile, "--output=" .. genfile}
|
||
|
|
print("cmd_compile", genfile)
|
||
|
|
os.execv(meta.program, argv, {envs = {PATH = meta.sdkdir}})
|
||
|
|
return argv
|
||
|
|
end
|
||
|
|
|
||
|
|
function _listen_gen_file(target, batch)
|
||
|
|
genfile, sourcefile = batch[1], batch[2]
|
||
|
|
local dependfile = target:dependfile(genfile)
|
||
|
|
depend.on_changed(
|
||
|
|
function()
|
||
|
|
cmd_compile(genfile, sourcefile)
|
||
|
|
end,
|
||
|
|
{dependfile = dependfile, files = sourcefile}
|
||
|
|
)
|
||
|
|
end
|
||
|
|
function gen(target)
|
||
|
|
local gen_batch = target:data("codegen.batch")
|
||
|
|
if not gen_batch then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
for _, batch in ipairs(gen_batch) do
|
||
|
|
if batch[2] then
|
||
|
|
_listen_gen_file(target, batch)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function main(target, headerfiles)
|
||
|
|
local sourcedir = path.join(target:autogendir({root = true}), target:plat(), "inl")
|
||
|
|
target:add("includedirs", sourcedir, {public = true})
|
||
|
|
local gen_batch = {}
|
||
|
|
for idx, headerfile in pairs(headerfiles) do
|
||
|
|
-- batch
|
||
|
|
sourcefile = path.join(sourcedir, "meta_" .. path.basename(headerfile) .. ".inl")
|
||
|
|
table.insert(gen_batch, {sourcefile, headerfile})
|
||
|
|
end
|
||
|
|
-- save unit batch
|
||
|
|
target:data_set("codegen.batch", gen_batch)
|
||
|
|
end
|