Merge Xcode and module loading improvements

This commit is contained in:
Jason Perkins 2015-03-14 14:25:20 -04:00
commit aab1e899bf
7 changed files with 60 additions and 28 deletions

View File

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

View File

@ -14,3 +14,5 @@ Since 5.0-alpha1:
* Configuration baking and validation now skipped for execute only actions * Configuration baking and validation now skipped for execute only actions
* os.findlib() now accepts paths to search as argument * os.findlib() now accepts paths to search as argument
* Visual Studio .user files are now only generated if not empty * Visual Studio .user files are now only generated if not empty
* Xcode4 exporter is now available
* Modules may now be loaded on demand where feasible

View File

@ -110,6 +110,7 @@
table.insert(result, '\t"src/_premake_main.lua",') table.insert(result, '\t"src/_premake_main.lua",')
table.insert(result, '\t"src/_manifest.lua",') table.insert(result, '\t"src/_manifest.lua",')
table.insert(result, '\t"src/_modules.lua",')
table.insert(result, "\tNULL") table.insert(result, "\tNULL")
table.insert(result, "};") table.insert(result, "};")
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/_premake_main.lua")))
appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_manifest.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, "\tNULL")
table.insert(result, "};") 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 -- Load the collection of core scripts, required for everything else to work
local modules = dofile("_modules.lua")
local manifest = dofile("_manifest.lua") local manifest = dofile("_manifest.lua")
for i = 1, #manifest do for i = 1, #manifest do
dofile(manifest[i]) dofile(manifest[i])
@ -32,6 +33,7 @@
return { return {
m.installModuleLoader, m.installModuleLoader,
m.prepareEnvironment, m.prepareEnvironment,
m.preloadModules,
m.runSystemScript, m.runSystemScript,
m.locateUserScript, m.locateUserScript,
m.prepareAction, m.prepareAction,
@ -62,9 +64,6 @@
function m.installModuleLoader() function m.installModuleLoader()
table.insert(package.loaders, 2, m.moduleLoader) table.insert(package.loaders, 2, m.moduleLoader)
-- TEMPORARY: I'm working on a different solution for this
require("xcode")
end end
function m.moduleLoader(name) function m.moduleLoader(name)
@ -77,28 +76,20 @@
dir = base dir = base
end end
local function tryLoad(filename) local full = dir .. "/" .. base .. ".lua"
local chunk, err = loadfile(filename) local p = os.locate("modules/" .. full) or
if not chunk and not err:startswith("No such file") then os.locate(full) or
error(err, 0) os.locate(name .. ".lua")
end
return chunk
end
-- Premake standard is moduleName/moduleName.lua if not p then
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
if not chunk then
return "\n\tno file " .. name .. " on module paths" return "\n\tno file " .. name .. " on module paths"
end end
local chunk, err = loadfile(p)
if not chunk then
error(err, 0)
end
return chunk return chunk
end end
@ -115,6 +106,26 @@
end end
---
-- Load the required core modules that are shipped as part of Premake
-- and expected to be present at startup.
---
function m.preloadModules()
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 -- Look for and run the system-wide configuration script; make sure any
-- configuration scoping gets cleared before continuing. -- configuration scoping gets cleared before continuing.

View File

@ -339,10 +339,14 @@ end
-- Write a opening XML element for a UTF-8 encoded file. Used by -- Write a opening XML element for a UTF-8 encoded file. Used by
-- several different files for different actions, so makes sense -- several different files for different actions, so makes sense
-- to have a common call for it. -- to have a common call for it.
--
-- @param upper
-- If true, the encoding is written in uppercase.
--- ---
function premake.xmlUtf8() function premake.xmlUtf8(upper)
premake.outln('<?xml version="1.0" encoding="utf-8"?>') local encoding = iif(upper, "UTF-8", "utf-8")
premake.w('<?xml version="1.0" encoding="%s"?>', encoding)
end end

View File

@ -266,16 +266,20 @@
end end
function test.getproject(sln, i) function test.getsolution(sln)
premake.oven.bake() premake.oven.bake()
sln = premake.global.getSolution(sln.name) return premake.global.getSolution(sln.name)
end
function test.getproject(sln, i)
sln = test.getsolution(sln)
return premake.solution.getproject(sln, i or 1) return premake.solution.getproject(sln, i or 1)
end end
function test.getconfig(prj, buildcfg, platform) function test.getconfig(prj, buildcfg, platform)
premake.oven.bake() sln = test.getsolution(prj.solution)
local sln = premake.global.getSolution(prj.solution.name)
prj = premake.solution.getproject(sln, prj.name) prj = premake.solution.getproject(sln, prj.name)
return premake.project.getconfig(prj, buildcfg, platform) return premake.project.getconfig(prj, buildcfg, platform)
end end