Write scripts.c to right location even when called from a different working directory

This commit is contained in:
Jason Perkins 2013-12-01 16:03:08 -05:00
parent 1f126d1855
commit 82e2676b40

View File

@ -96,38 +96,40 @@
table.insert(scripts, 1, "_premake_main.lua")
-- 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")
local file = io.tmpfile()
file:write("/* Premake's Lua scripts, as static data buffers for release mode builds */\n")
file:write("/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */\n")
file:write("/* To regenerate this file, run: premake5 embed */ \n\n")
file:write("const char* builtin_scripts[] = {\n")
for i,fn in ipairs(scripts) do
for i, fn in ipairs(scripts) do
local s = stripfile(path.join(dir, fn))
writefile(out, fn, s)
writefile(file, fn, s)
end
out:write("\t0\n};\n");
file: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()
file:seek("set", 0)
local newVersion = file:read("*a")
file:close()
local oldVersion
local scriptsFile = io.open(path.join(basedir, "src/host/scripts.c"), "r")
if scriptsFile then
oldVersion = scriptsFile:read("*a")
scriptsFile:close()
local scriptsFile = path.join(basedir, "src/host/scripts.c")
local file = io.open(scriptsFile, "r")
if file then
oldVersion = file:read("*a")
file:close()
end
if newVersion ~= oldVersion then
print("Writing scripts.c")
scriptsFile = io.open("src/host/scripts.c", "w+b")
scriptsFile:write(newVersion)
scriptsFile:close()
file = io.open(scriptsFile, "w+b")
file:write(newVersion)
file:close()
end
end