Re-enable deferred module loading

This commit is contained in:
Jason Perkins 2015-03-13 19:17:07 -04:00
parent 4667789bc3
commit de9520eded
4 changed files with 40 additions and 14 deletions

View File

@ -1 +1 @@
d18d2d5c98aea1987c1b8df237230018fef73eea modules/xcode
fb55ee49710c8f9a296219e5b948a294a282af29 modules/xcode

View File

@ -110,6 +110,7 @@
table.insert(result, '\t"src/_premake_main.lua",')
table.insert(result, '\t"src/_manifest.lua",')
table.insert(result, '\t"src/_modules.lua",')
table.insert(result, "\tNULL")
table.insert(result, "};")
table.insert(result, "")
@ -134,6 +135,7 @@
appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_premake_main.lua")))
appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_manifest.lua")))
appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_modules.lua")))
table.insert(result, "\tNULL")
table.insert(result, "};")

9
src/_modules.lua Normal file
View File

@ -0,0 +1,9 @@
--
-- _modules.lua
-- The list of core modules to preload on startup
-- Copyright (c) 2015 Jason Perkins and the Premake project
--
return {
"xcode",
}

View File

@ -10,6 +10,7 @@
-- Load the collection of core scripts, required for everything else to work
local modules = dofile("_modules.lua")
local manifest = dofile("_manifest.lua")
for i = 1, #manifest do
dofile(manifest[i])
@ -32,6 +33,7 @@
return {
m.installModuleLoader,
m.prepareEnvironment,
m.loadCoreModules,
m.runSystemScript,
m.locateUserScript,
m.prepareAction,
@ -62,9 +64,6 @@
function m.installModuleLoader()
table.insert(package.loaders, 2, m.moduleLoader)
-- TEMPORARY: I'm working on a different solution for this
require("xcode")
end
function m.moduleLoader(name)
@ -77,9 +76,9 @@
dir = base
end
local function tryLoad(filename)
local chunk, err = loadfile(filename)
if not chunk and not err:startswith("No such file") then
local function try(name)
local chunk, err = loadfile(name)
if not chunk and not err:startswith("cannot open") then
error(err, 0)
end
return chunk
@ -87,13 +86,9 @@
-- Premake standard is moduleName/moduleName.lua
local relPath = dir .. "/" .. base .. ".lua"
local chunk = tryLoad("modules/" .. relPath)
if not chunk then
chunk = tryLoad(relPath)
end
if not chunk then
chunk = tryLoad(name .. ".lua")
end
local chunk = try("modules/" .. relPath) or
try(relPath) or
try(name .. ".lua")
if not chunk then
return "\n\tno file " .. name .. " on module paths"
@ -115,6 +110,26 @@
end
---
-- Load the required core modules that are shipped as part of Premake
-- and expected to be present at startup.
---
function m.loadCoreModules()
for i = 1, #modules do
local name = modules[i]
local preload = name .. "/_preload.lua"
local fn = os.locate("modules/" .. preload) or os.locate(preload)
if fn then
include(fn)
else
require(name)
end
end
end
---
-- Look for and run the system-wide configuration script; make sure any
-- configuration scoping gets cleared before continuing.