From 571f2da4fb4fa72335ec887f3877f9577c4a2f96 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Fri, 13 Mar 2015 16:48:06 -0400 Subject: [PATCH 1/4] Apply coding conventions to Xcode workspace exporter --- .hgsubstate | 2 +- src/base/premake.lua | 8 ++++++-- tests/testfx.lua | 12 ++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.hgsubstate b/.hgsubstate index 4ce0b665..0fc41e43 100644 --- a/.hgsubstate +++ b/.hgsubstate @@ -1 +1 @@ -aaccdc16e9bb0b2b1a3cdc8855e0c27e7f920f1d modules/xcode +d18d2d5c98aea1987c1b8df237230018fef73eea modules/xcode diff --git a/src/base/premake.lua b/src/base/premake.lua index 7f011d48..5b0c2f29 100644 --- a/src/base/premake.lua +++ b/src/base/premake.lua @@ -339,10 +339,14 @@ end -- Write a opening XML element for a UTF-8 encoded file. Used by -- several different files for different actions, so makes sense -- to have a common call for it. +-- +-- @param upper +-- If true, the encoding is written in uppercase. --- - function premake.xmlUtf8() - premake.outln('') + function premake.xmlUtf8(upper) + local encoding = iif(upper, "UTF-8", "utf-8") + premake.w('', encoding) end diff --git a/tests/testfx.lua b/tests/testfx.lua index 5024bc76..ed999133 100644 --- a/tests/testfx.lua +++ b/tests/testfx.lua @@ -266,16 +266,20 @@ end - function test.getproject(sln, i) + function test.getsolution(sln) 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) end function test.getconfig(prj, buildcfg, platform) - premake.oven.bake() - local sln = premake.global.getSolution(prj.solution.name) + sln = test.getsolution(prj.solution) prj = premake.solution.getproject(sln, prj.name) return premake.project.getconfig(prj, buildcfg, platform) end From de9520eded1e18472a3d5cb277ef2616f2aa1b85 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Fri, 13 Mar 2015 19:17:07 -0400 Subject: [PATCH 2/4] 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. From bda1d10e4a836d4c9341747b57ec935ecd7e9161 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Sat, 14 Mar 2015 14:21:54 -0400 Subject: [PATCH 3/4] Clean up module file error handling; use os.locate() to predetermine script availability --- src/_premake_main.lua | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/_premake_main.lua b/src/_premake_main.lua index bd578937..24b9e63f 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -33,7 +33,7 @@ return { m.installModuleLoader, m.prepareEnvironment, - m.loadCoreModules, + m.preloadModules, m.runSystemScript, m.locateUserScript, m.prepareAction, @@ -76,22 +76,18 @@ dir = base end - 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 + local full = dir .. "/" .. base .. ".lua" + local p = os.locate("modules/" .. full) or + os.locate(full) or + os.locate(name .. ".lua") + + if not p then + return "\n\tno file " .. name .. " on module paths" end - -- Premake standard is moduleName/moduleName.lua - local relPath = dir .. "/" .. base .. ".lua" - local chunk = try("modules/" .. relPath) or - try(relPath) or - try(name .. ".lua") - + local chunk, err = loadfile(p) if not chunk then - return "\n\tno file " .. name .. " on module paths" + error(err, 0) end return chunk @@ -115,7 +111,7 @@ -- and expected to be present at startup. --- - function m.loadCoreModules() + function m.preloadModules() for i = 1, #modules do local name = modules[i] local preload = name .. "/_preload.lua" From 692daee04d67d6f6beb0eb92448fbd3accbbb87e Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Sat, 14 Mar 2015 14:24:32 -0400 Subject: [PATCH 4/4] Update change log --- CHANGES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index fadc1e9d..1c763e2f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,3 +14,5 @@ Since 5.0-alpha1: * Configuration baking and validation now skipped for execute only actions * os.findlib() now accepts paths to search as argument * 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