2009-07-16 15:20:15 +00:00
|
|
|
--
|
|
|
|
-- Embed the Lua scripts into src/host/scripts.c as static data buffers.
|
2013-09-10 20:24:39 +00:00
|
|
|
-- I embed the actual scripts, rather than Lua bytecodes, because the
|
|
|
|
-- bytecodes are not portable to different architectures, which causes
|
2009-07-16 15:20:15 +00:00
|
|
|
-- issues in Mac OS X Universal builds.
|
|
|
|
--
|
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
local function loadScript(fname)
|
2015-03-09 21:07:12 +00:00
|
|
|
fname = path.getabsolute(fname)
|
2015-04-01 17:42:15 +00:00
|
|
|
local f = io.open(fname)
|
|
|
|
local s = assert(f:read("*a"))
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
-- strip tabs
|
|
|
|
s = s:gsub("[\t]", "")
|
2015-03-29 19:35:43 +00:00
|
|
|
|
|
|
|
-- strip any CRs
|
|
|
|
s = s:gsub("[\r]", "")
|
|
|
|
|
2015-04-01 17:42:15 +00:00
|
|
|
-- strip out block comments
|
|
|
|
s = s:gsub("[^\"']%-%-%[%[.-%]%]", "")
|
|
|
|
s = s:gsub("[^\"']%-%-%[=%[.-%]=%]", "")
|
|
|
|
s = s:gsub("[^\"']%-%-%[==%[.-%]==%]", "")
|
|
|
|
|
|
|
|
-- strip out inline comments
|
|
|
|
s = s:gsub("\n%-%-[^\n]*", "\n")
|
|
|
|
|
2015-03-29 19:35:43 +00:00
|
|
|
-- escape backslashes
|
|
|
|
s = s:gsub("\\", "\\\\")
|
|
|
|
|
2015-04-01 17:42:15 +00:00
|
|
|
-- strip duplicate line feeds
|
|
|
|
s = s:gsub("\n+", "\n")
|
|
|
|
|
|
|
|
-- strip out leading comments
|
|
|
|
s = s:gsub("^%-%-[^\n]*\n", "")
|
|
|
|
|
2015-03-29 19:35:43 +00:00
|
|
|
-- escape line feeds
|
|
|
|
s = s:gsub("\n", "\\n")
|
|
|
|
|
|
|
|
-- escape double quote marks
|
|
|
|
s = s:gsub("\"", "\\\"")
|
2015-03-29 19:43:40 +00:00
|
|
|
|
|
|
|
return s
|
2010-01-07 15:36:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
local function appendScript(result, contents)
|
2013-09-10 20:24:39 +00:00
|
|
|
-- break up large strings to fit in Visual Studio's string length limit
|
2014-05-29 22:04:58 +00:00
|
|
|
local max = 4096
|
2010-01-07 15:36:03 +00:00
|
|
|
local start = 1
|
|
|
|
local len = contents:len()
|
2015-03-25 20:10:27 +00:00
|
|
|
if len > 0 then
|
|
|
|
while start <= len do
|
|
|
|
local n = len - start
|
|
|
|
if n > max then n = max end
|
|
|
|
local finish = start + n
|
|
|
|
|
|
|
|
-- make sure I don't cut an escape sequence
|
|
|
|
while contents:sub(finish, finish) == "\\" do
|
|
|
|
finish = finish - 1
|
|
|
|
end
|
2010-01-07 16:24:17 +00:00
|
|
|
|
2015-03-25 20:10:27 +00:00
|
|
|
local s = contents:sub(start, finish)
|
|
|
|
table.insert(result, "\t\"" .. s .. iif(finish < len, '"', '",'))
|
2014-05-29 22:04:58 +00:00
|
|
|
|
2015-03-25 20:10:27 +00:00
|
|
|
start = finish + 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
table.insert(result, "\t\"\",")
|
2013-09-10 20:24:39 +00:00
|
|
|
end
|
2010-01-07 15:36:03 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
table.insert(result, "")
|
2010-01-07 15:36:03 +00:00
|
|
|
end
|
2009-07-16 15:20:15 +00:00
|
|
|
|
|
|
|
|
2013-11-07 14:39:46 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
-- Prepare the file header
|
2013-09-10 20:24:39 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
local result = {}
|
|
|
|
table.insert(result, "/* Premake's Lua scripts, as static data buffers for release mode builds */")
|
|
|
|
table.insert(result, "/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */")
|
|
|
|
table.insert(result, "/* To regenerate this file, run: premake5 embed */")
|
|
|
|
table.insert(result, "")
|
|
|
|
table.insert(result, '#include "premake.h"')
|
|
|
|
table.insert(result, "")
|
2013-12-01 20:24:25 +00:00
|
|
|
|
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
-- Find all of the _manifest.lua files within the project
|
2013-09-10 20:24:39 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
local mask = path.join(_MAIN_SCRIPT_DIR, "**/_manifest.lua")
|
|
|
|
local manifests = os.matchfiles(mask)
|
2013-09-10 20:24:39 +00:00
|
|
|
|
2015-08-24 16:08:43 +00:00
|
|
|
-- Find all of the _user_modules.lua files within the project
|
|
|
|
|
|
|
|
local userModuleFiles = {}
|
|
|
|
userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "**/_user_modules.lua")))
|
|
|
|
userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "_user_modules.lua")))
|
2013-09-10 20:24:39 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
-- Generate an index of the script file names. Script names are stored
|
|
|
|
-- relative to the directory containing the manifest, i.e. the main
|
|
|
|
-- Xcode script, which is at $/modules/xcode/xcode.lua is stored as
|
2014-10-16 21:32:09 +00:00
|
|
|
-- "xcode/xcode.lua".
|
2013-12-01 20:24:25 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
table.insert(result, "const char* builtin_scripts_index[] = {")
|
2013-12-01 20:24:25 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
for mi = 1, #manifests do
|
|
|
|
local manifestName = manifests[mi]
|
|
|
|
local manifestDir = path.getdirectory(manifestName)
|
|
|
|
local baseDir = path.getdirectory(manifestDir)
|
|
|
|
|
|
|
|
local files = dofile(manifests[mi])
|
|
|
|
for fi = 1, #files do
|
|
|
|
local filename = path.join(manifestDir, files[fi])
|
|
|
|
filename = path.getrelative(baseDir, filename)
|
|
|
|
table.insert(result, '\t"' .. filename .. '",')
|
2013-12-01 20:24:25 +00:00
|
|
|
end
|
2014-09-26 13:25:14 +00:00
|
|
|
end
|
|
|
|
|
2014-10-16 21:32:09 +00:00
|
|
|
table.insert(result, '\t"src/_premake_main.lua",')
|
|
|
|
table.insert(result, '\t"src/_manifest.lua",')
|
2015-03-13 23:17:07 +00:00
|
|
|
table.insert(result, '\t"src/_modules.lua",')
|
2014-09-26 13:25:14 +00:00
|
|
|
table.insert(result, "\tNULL")
|
|
|
|
table.insert(result, "};")
|
|
|
|
table.insert(result, "")
|
|
|
|
|
|
|
|
|
|
|
|
-- Embed the actual script contents
|
|
|
|
|
|
|
|
table.insert(result, "const char* builtin_scripts[] = {")
|
2013-12-01 20:24:25 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
for mi = 1, #manifests do
|
|
|
|
local manifestName = manifests[mi]
|
|
|
|
local manifestDir = path.getdirectory(manifestName)
|
|
|
|
|
|
|
|
local files = dofile(manifests[mi])
|
|
|
|
for fi = 1, #files do
|
|
|
|
local filename = path.join(manifestDir, files[fi])
|
|
|
|
|
|
|
|
local scr = loadScript(filename)
|
|
|
|
appendScript(result, scr)
|
2013-12-01 20:24:25 +00:00
|
|
|
end
|
2009-07-16 15:20:15 +00:00
|
|
|
end
|
2014-09-26 13:25:14 +00:00
|
|
|
|
2014-09-29 19:28:11 +00:00
|
|
|
appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_premake_main.lua")))
|
|
|
|
appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_manifest.lua")))
|
2015-08-24 16:08:43 +00:00
|
|
|
|
|
|
|
-- Write the list of modules
|
|
|
|
|
|
|
|
local modules = dofile("../src/_modules.lua")
|
|
|
|
for _, userModules in ipairs(userModuleFiles) do
|
|
|
|
modules = table.join(modules, dofile(userModules))
|
|
|
|
end
|
|
|
|
appendScript(result, "return {" .. table.implode(modules, "\\\"", "\\\"", ",\\n") .. "}")
|
2014-09-29 19:28:11 +00:00
|
|
|
|
2014-09-26 13:25:14 +00:00
|
|
|
table.insert(result, "\tNULL")
|
|
|
|
table.insert(result, "};")
|
|
|
|
table.insert(result, "")
|
|
|
|
|
|
|
|
|
|
|
|
-- Write it all out. Check against the current contents of scripts.c first,
|
|
|
|
-- and only overwrite it if there are actual changes.
|
|
|
|
|
|
|
|
result = table.concat(result, "\n")
|
|
|
|
|
|
|
|
local scriptsFile = path.getabsolute(path.join(_SCRIPT_DIR, "../src/host/scripts.c"))
|
|
|
|
|
|
|
|
local oldVersion
|
|
|
|
local file = io.open(scriptsFile, "r")
|
|
|
|
if file then
|
|
|
|
oldVersion = file:read("*a")
|
|
|
|
file:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
if oldVersion ~= result then
|
2015-04-01 17:42:15 +00:00
|
|
|
print("Writing scripts.c")
|
2014-09-26 13:25:14 +00:00
|
|
|
file = io.open(scriptsFile, "w+b")
|
|
|
|
file:write(result)
|
|
|
|
file:close()
|
|
|
|
end
|