Added support for file configurations to oven; full file configurations now available to actions

This commit is contained in:
Jason Perkins 2012-03-14 18:20:01 -04:00
parent 399739d012
commit f1f6304e9b
5 changed files with 164 additions and 23 deletions

View File

@ -29,9 +29,9 @@
"base/premake.lua", "base/premake.lua",
-- project APIs -- project APIs
"project/oven.lua",
"project/project.lua", "project/project.lua",
"project/config.lua", "project/config.lua",
"project/oven.lua",
"base/solution.lua", "base/solution.lua",
-- tool APIs -- tool APIs

View File

@ -7,6 +7,7 @@
premake5.config = { } premake5.config = { }
local project = premake5.project local project = premake5.project
local config = premake5.config local config = premake5.config
local oven = premake5.oven
-- --
@ -86,6 +87,36 @@
end end
--
-- Retrieve the configuration settings for a specific file.
--
-- @param cfg
-- The configuration object to query.
-- @param filename
-- The full, absolute path of the file to query.
-- @return
-- A configuration object for the file, or nil if the file is
-- not included in this configuration.
--
function config.getfileconfig(cfg, filename)
-- if there is no entry, then this file is not part of the config
local fcfg = cfg.files[filename]
if not fcfg then
return nil
end
-- initially this value will be a string (the file name); replace
-- it with the full file configuration
if type(fcfg) ~= "table" then
fcfg = oven.bakefile(cfg, filename)
cfg.files[filename] = fcfg
end
return fcfg
end
-- --
-- Retrieve linking information for a specific configuration. That is, -- Retrieve linking information for a specific configuration. That is,
-- the path information that is required to link against the library -- the path information that is required to link against the library
@ -129,25 +160,6 @@
end end
--
-- Retrieve the configuration settings for a specific file.
--
-- @param cfg
-- The configuration object to query.
-- @param filename
-- The full, absolute path of the file to query.
-- @return
-- A configuration object for the file, or nil if the file is
-- not included in this configuration.
--
function config.getfileconfig(cfg, filename)
if cfg.files[filename] then
return {}
end
end
-- --
-- Retrieve a list of link targets from a configuration. -- Retrieve a list of link targets from a configuration.
-- --

View File

@ -1,7 +1,7 @@
-- --
-- src/project/oven.lua -- src/project/oven.lua
-- Premake next-generation configuration "baking" API. -- Premake next-generation configuration "baking" API.
-- Copyright (c) 2011 Jason Perkins and the Premake project -- Copyright (c) 2011-2012 Jason Perkins and the Premake project
-- --
premake5.oven = { } premake5.oven = { }
@ -64,10 +64,46 @@
end end
end end
-- Remember the list of terms used to create this config
cfg.terms = filterTerms
return cfg return cfg
end end
--
-- Retrieve the settings for a specific file within a configuration. Files
-- have special rules: they only return those values from blocks that
-- explicitly match the filename.
--
-- @param cfg
-- The base configuration to query.
-- @param filename
-- The name of the file to query.
-- @return
-- A file configuration object, which may be empty.
--
function oven.bakefile(cfg, filename)
local fcfg = {}
filename = { filename }
for _, block in ipairs(cfg.solution.blocks) do
if oven.filter(block, cfg.terms, filename) then
oven.mergefile(fcfg, cfg, block)
end
end
for _, block in ipairs(cfg.project.blocks) do
if oven.filter(block, cfg.terms, filename) then
oven.mergefile(fcfg, cfg, block)
end
end
return fcfg
end
-- --
-- Compare a list of block keywords against a set of filter terms. Keywords -- Compare a list of block keywords against a set of filter terms. Keywords
-- are Lua patterns applied to the block when it is specified in the script -- are Lua patterns applied to the block when it is specified in the script
@ -90,12 +126,31 @@
-- --
function oven.filter(block, anyOfThese, allOfThese) function oven.filter(block, anyOfThese, allOfThese)
-- All block keywords must match at least one term allOfThese = allOfThese or {}
-- All of these terms must match at least one block keyword
for _, term in ipairs(allOfThese) do
local matched = false
for _, keyword in ipairs(block.keywords) do for _, keyword in ipairs(block.keywords) do
if not oven.testkeyword(keyword, anyOfThese) then if oven.testkeyword(keyword, { term }) then
matched = true
break
end
end
if not matched then
return false return false
end end
end end
-- All block keywords must match at least one term
for _, keyword in ipairs(block.keywords) do
if not oven.testkeyword(keyword, anyOfThese) and not oven.testkeyword(keyword, allOfThese) then
return false
end
end
return true return true
end end
@ -164,6 +219,32 @@
end end
--
-- Merge from an individual block into a file configuration object, using the
-- provided configuration as a basis.
--
-- @param fcfg
-- The file configuration being built; will contain the new values.
-- @param cfg
-- The base configuration.
-- @param block
-- The block containing the values to merge.
--
function oven.mergefile(fcfg, cfg, block)
for key, value in pairs(block) do
-- if this is the first appearance of this field, start by
-- copying over the basis values from the configuration
if not fcfg[key] then
oven.merge(fcfg, cfg, key)
end
-- then merge the file specific values over that
oven.merge(fcfg, block, key)
end
end
-- --
-- Merges a single field from a configuration block into a baked -- Merges a single field from a configuration block into a baked
-- configuration object. -- configuration object.

View File

@ -215,3 +215,37 @@
</File> </File>
]] ]]
end end
--
-- If a custom build rule is supplied, the custom build tool settings should be used.
--
function suite.customBuildTool_onBuildRule()
files { "hello.x" }
configuration "**.x"
buildrule {
description = "Compiling $(InputFile)",
commands = {
'cxc -c "$(InputFile)" -o "$(IntDir)/$(InputName).xo"',
'c2o -c "$(IntDir)/$(InputName).xo" -o "$(IntDir)/$(InputName).obj"'
},
outputs = "$(IntDir)/$(InputName).obj"
}
prepare()
test.capture [[
<File
RelativePath="hello.x"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="cxc &quot;-c $(InputFile)&quot; -o &quot;$(IntDir)/$(InputName).xo&quot;&#x0D;&#x0A;c2o -c &quot;$(IntDir)/$(InputName).xo&quot; -o &quot;$(IntDir)/$(InputName).obj&quot;"
Outputs="$(IntDir)/$(InputName).obj"
/>
</FileConfiguration>
</File>
]]
end

View File

@ -87,3 +87,17 @@
prepare() prepare()
test.isnotnil(fcfg) test.isnotnil(fcfg)
end end
--
-- A build option specified on a specific set of files should appear in the
-- file configuration
--
function suite.settingIsPresent_onFileSpecificFilter()
files "hello.c"
configuration "**.c"
buildoptions "-Xc"
prepare()
test.isequal({ "-Xc" }, fcfg.buildoptions)
end