From de9520eded1e18472a3d5cb277ef2616f2aa1b85 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Fri, 13 Mar 2015 19:17:07 -0400 Subject: [PATCH] Re-enable deferred module loading --- .hgsubstate | 2 +- scripts/embed.lua | 2 ++ src/_modules.lua | 9 +++++++++ src/_premake_main.lua | 41 ++++++++++++++++++++++++++++------------- 4 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 src/_modules.lua diff --git a/.hgsubstate b/.hgsubstate index 0fc41e43..cf2e15a4 100644 --- a/.hgsubstate +++ b/.hgsubstate @@ -1 +1 @@ -d18d2d5c98aea1987c1b8df237230018fef73eea modules/xcode +fb55ee49710c8f9a296219e5b948a294a282af29 modules/xcode diff --git a/scripts/embed.lua b/scripts/embed.lua index 23c61b65..9746ea61 100644 --- a/scripts/embed.lua +++ b/scripts/embed.lua @@ -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, "};") diff --git a/src/_modules.lua b/src/_modules.lua new file mode 100644 index 00000000..90730c36 --- /dev/null +++ b/src/_modules.lua @@ -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", + } diff --git a/src/_premake_main.lua b/src/_premake_main.lua index 059b632d..bd578937 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -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.