Added config.getfileconfig(), basis for per-configuration file and exclusion lists

This commit is contained in:
Jason Perkins 2012-02-13 17:32:23 -05:00
parent 0b1fb89bc0
commit 56d6701528
6 changed files with 149 additions and 66 deletions

View File

@ -90,10 +90,10 @@
scope = "config", scope = "config",
usagecopy = true, usagecopy = true,
}, },
excludes = excludes =
{ {
kind = "filelist", kind = "filelist",
scope = "config", scope = "config",
}, },
@ -147,59 +147,6 @@
OptimiseSize = 'OptimizeSize', OptimiseSize = 'OptimizeSize',
OptimiseSpeed = 'OptimizeSpeed', OptimiseSpeed = 'OptimizeSpeed',
}, },
--[[
allowed = function(value)
local allowed_flags = {
DebugEnvsDontMerge = 1,
DebugEnvsInherit = 1,
EnableSSE = 1,
EnableSSE2 = 1,
ExtraWarnings = 1,
FatalWarnings = 1,
FloatFast = 1,
FloatStrict = 1,
Managed = 1,
MFC = 1,
NativeWChar = 1,
No64BitChecks = 1,
NoEditAndContinue = 1,
NoExceptions = 1,
NoFramePointer = 1,
NoImportLib = 1,
NoIncrementalLink = 1,
NoManifest = 1,
NoMinimalRebuild = 1,
NoNativeWChar = 1,
NoPCH = 1,
NoRTTI = 1,
Optimize = 1,
OptimizeSize = 1,
OptimizeSpeed = 1,
SEH = 1,
StaticRuntime = 1,
Symbols = 1,
Unicode = 1,
Unsafe = 1,
WinMain = 1
}
local englishToAmericanSpelling =
{
Optimise = 'Optimize',
OptimiseSize = 'OptimizeSize',
OptimiseSpeed = 'OptimizeSpeed'
}
if englishToAmericanSpelling[value] then value = englishToAmericanSpelling[value] end
if allowed_flags[value] then return value
else
return nil, "invalid flag '" .. value .. "'"
end
end,
--]]
}, },
framework = framework =
@ -580,7 +527,7 @@
if not value then if not value then
error(err, depth) error(err, depth)
end end
table.insert(obj[fieldname], value) obj[fieldname] = table.join(obj[fieldname], value)
end end
end end
@ -599,7 +546,7 @@
-- values are converted to absolute paths before being stored. -- values are converted to absolute paths before being stored.
-- --
local function domatchedarray(ctype, fieldname, value, matchfunc) local function domatchedarray(obj, fieldname, value, matchfunc)
local result = { } local result = { }
function makeabsolute(value, depth) function makeabsolute(value, depth)
@ -619,15 +566,15 @@
end end
makeabsolute(value, 3) makeabsolute(value, 3)
return premake.setarray(ctype, fieldname, result) return premake.setarray(obj, fieldname, result)
end end
function premake.setdirarray(ctype, fieldname, value) function premake.setdirarray(obj, fieldname, value)
return domatchedarray(ctype, fieldname, value, os.matchdirs) return domatchedarray(obj, fieldname, value, os.matchdirs)
end end
function premake.setfilearray(ctype, fieldname, value) function premake.setfilearray(obj, fieldname, value)
return domatchedarray(ctype, fieldname, value, os.matchfiles) return domatchedarray(obj, fieldname, value, os.matchfiles)
end end
@ -733,9 +680,18 @@
-- --
function premake.remove(fieldname, value) function premake.remove(fieldname, value)
local kind = premake.fields[fieldname].kind
function set(value)
if kind ~= "list" and not value:startswith("**") then
return path.getabsolute(value)
else
return value
end
end
local cfg = premake.CurrentConfiguration local cfg = premake.CurrentConfiguration
cfg.removes = cfg.removes or {} cfg.removes = cfg.removes or {}
cfg.removes[fieldname] = premake.setarray(cfg.removes, fieldname, value) cfg.removes[fieldname] = premake.setarray(cfg.removes, fieldname, value, set)
end end
@ -758,9 +714,18 @@
end end
end end
end end
--
-- For backward compatibility, excludes() is becoming an alias for removefiles().
--
function excludes(value)
removefiles(value)
return accessor("excludes", value)
end
-- --
-- Project object constructors. -- Project object constructors.
-- --

View File

@ -129,6 +129,25 @@
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

@ -67,8 +67,6 @@
-- --
-- Return an iterator for the list of source code files contained by a project. -- Return an iterator for the list of source code files contained by a project.
-- Note that this only returns the files specified at the project level; I'm
-- not supported configuration level file lists, yet.
-- --
-- @param prj -- @param prj
-- The project to query. -- The project to query.

View File

@ -0,0 +1,89 @@
--
-- tests/config/test_fileconfig.lua
-- Test the config object's file configuration accessor.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
T.config_fileconfig = { }
local suite = T.config_fileconfig
local project = premake5.project
local config = premake5.config
--
-- Setup and teardown
--
local sln, prj, fcfg
function suite.setup()
sln, prj = test.createsolution()
end
local function prepare()
local cfg = project.getconfig(prj, "Debug")
fcfg = config.getfileconfig(cfg, path.join(os.getcwd(), "hello.c"))
end
--
-- A file specified at the project level should be present in all configurations.
--
function suite.isPresent_onProjectLevel()
files "hello.c"
prepare()
test.isnotnil(fcfg)
end
--
-- A file specified only in the current configuration should return a value.
--
function suite.isPresent_onCurrentConfigOnly()
configuration "Debug"
files "hello.c"
prepare()
test.isnotnil(fcfg)
end
--
-- A file specified only in a different configuration should return nil.
--
function suite.isNotPresent_onDifferentConfigOnly()
configuration "Release"
files "hello.c"
prepare()
test.isnil(fcfg)
end
--
-- A file specified at the project, and excluded in the current configuration
-- should return nil.
--
function suite.isNotPresent_onExcludedInCurrent()
files "hello.c"
configuration "Debug"
excludes "hello.c"
prepare()
test.isnil(fcfg)
end
--
-- A file specified at the project, and excluded in a different configuration
-- should return a value.
--
function suite.isNotPresent_onExcludedInCurrent()
files "hello.c"
configuration "Release"
excludes "hello.c"
prepare()
test.isnotnil(fcfg)
end

View File

@ -67,6 +67,7 @@
dofile("project/test_vpaths.lua") dofile("project/test_vpaths.lua")
-- Configuration object tests -- Configuration object tests
dofile("config/test_fileconfig.lua")
dofile("config/test_linkinfo.lua") dofile("config/test_linkinfo.lua")
dofile("config/test_links.lua") dofile("config/test_links.lua")
dofile("config/test_objdir.lua") dofile("config/test_objdir.lua")

View File

@ -287,3 +287,14 @@
cfg = oven.bake(sln) cfg = oven.bake(sln)
test.isnil(cfg.flags.Optimize) test.isnil(cfg.flags.Optimize)
end end
--
-- Remove should also work with file paths.
--
function suite.remove_onFileField()
files { "hello.c", "goodbye.c" }
removefiles { "goodbye.c" }
cfg = oven.bake(sln)
test.isequal(path.join(os.getcwd(), "hello.c"), table.concat(cfg.files))
end