Only write scripts.c if modified by embed action

This commit is contained in:
Jason Perkins 2013-12-01 15:24:25 -05:00
parent 2774e7796a
commit 7d77ec8a1a

View File

@ -78,27 +78,54 @@
function doembed()
local srcdir = path.join(basedir, "src")
-- load the manifest of script files
scripts = dofile(path.join(srcdir, "_manifest.lua"))
-- Find and run the manifest file. Checks the normal search paths to
-- allow for manifest and _premake_main customizations, then falls
-- back to the canonical version at ../src if not found.
-- main script always goes first
local dir = os.pathsearch("_manifest.lua", _OPTIONS["scripts"], os.getenv("PREMAKE_PATH"))
if not dir then
dir = path.join(basedir, "src")
end
scripts = dofile(path.join(dir, "_manifest.lua"))
-- Main script always goes first
table.insert(scripts, 1, "_premake_main.lua")
-- open scripts.c and write the file header
local out = io.open(path.join(srcdir, "host/scripts.c"), "w+b")
-- Embed all the scripts to a temporary file first
local out = io.tmpfile()
out:write("/* Premake's Lua scripts, as static data buffers for release mode builds */\n")
out:write("/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */\n")
out:write("/* To regenerate this file, run: premake5 embed */ \n\n")
out:write("const char* builtin_scripts[] = {\n")
for i,fn in ipairs(scripts) do
print(fn)
local s = stripfile(path.join(srcdir, fn))
local s = stripfile(path.join(dir, fn))
writefile(out, fn, s)
end
out:write("\t0\n};\n");
-- Now read it back in and compare it to the current scripts.c; only
-- write it out if changed.
out:seek("set", 0)
local newVersion = out:read("*a")
out:close()
local oldVersion
local scriptsFile = io.open(path.join(basedir, "src/host/scripts.c"), "r")
if scriptsFile then
oldVersion = scriptsFile:read("*a")
scriptsFile:close()
end
if newVersion ~= oldVersion then
print("Writing scripts.c")
scriptsFile = io.open("src/host/scripts.c", "w+b")
scriptsFile:write(newVersion)
scriptsFile:close()
end
end