Add command line options to filter terms for configurations
--renderer=opengl can be used like: configuration { "renderer=opengl" } --release can be used like: configuration { "release" }
This commit is contained in:
parent
69572e392f
commit
c79f93665a
@ -68,6 +68,17 @@
|
||||
-- configuration blocks which match these terms will be returned.
|
||||
|
||||
context.addterms(ctx, _ACTION)
|
||||
|
||||
-- Add command line options to the filtering options
|
||||
|
||||
for key, value in pairs(_OPTIONS) do
|
||||
local term = key
|
||||
if value ~= "" then
|
||||
term = term .. "=" .. value
|
||||
end
|
||||
context.addterms(ctx, term)
|
||||
end
|
||||
|
||||
context.compile(ctx)
|
||||
|
||||
-- Specify the solution's file system location; when path tokens are
|
||||
@ -131,9 +142,9 @@
|
||||
local ctx = context.new(prj.configset, environ)
|
||||
|
||||
-- Add filtering terms to the context to make it as specific as I can.
|
||||
-- Action comes first, because it never depends on anything else.
|
||||
-- Start with the same filtering that was applied at the solution level.
|
||||
|
||||
context.addterms(ctx, _ACTION)
|
||||
context.copyterms(ctx, sln)
|
||||
|
||||
-- Now filter on the current system and architecture, allowing the
|
||||
-- values that might already in the context to override my defaults.
|
||||
@ -447,11 +458,14 @@
|
||||
|
||||
-- Add filtering terms to the context and then compile the results. These
|
||||
-- terms describe the "operating environment"; only results contained by
|
||||
-- configuration blocks which match these terms will be returned.
|
||||
-- configuration blocks which match these terms will be returned. Start
|
||||
-- by copying over the top-level environment from the solution. Don't
|
||||
-- copy the project terms though, so configurations can override those.
|
||||
|
||||
context.copyterms(ctx, prj.solution)
|
||||
|
||||
context.addterms(ctx, buildcfg)
|
||||
context.addterms(ctx, platform)
|
||||
context.addterms(ctx, _ACTION)
|
||||
context.addterms(ctx, prj.language)
|
||||
|
||||
-- allow the project script to override the default system
|
||||
|
88
tests/oven/test_filtering.lua
Normal file
88
tests/oven/test_filtering.lua
Normal file
@ -0,0 +1,88 @@
|
||||
--
|
||||
-- tests/oven/test_filtering.lua
|
||||
-- Test the project object configuration accessor.
|
||||
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
local suite = test.declare("oven_filtering")
|
||||
local oven = premake.oven
|
||||
local solution = premake.solution
|
||||
|
||||
local sln, prj
|
||||
|
||||
--
|
||||
-- Setup
|
||||
--
|
||||
|
||||
function suite.setup()
|
||||
sln = test.createsolution()
|
||||
end
|
||||
|
||||
local function prepare()
|
||||
sln = oven.bakeSolution(sln)
|
||||
prj = solution.getproject(sln, 1)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Test filtering by the selected action.
|
||||
--
|
||||
|
||||
function suite.onAction()
|
||||
_ACTION = "vs2012"
|
||||
configuration { "vs2012" }
|
||||
defines { "USE_VS2012" }
|
||||
prepare()
|
||||
test.isequal({ "USE_VS2012" }, prj.defines)
|
||||
end
|
||||
|
||||
function suite.onActionMismatch()
|
||||
_ACTION = "vs2010"
|
||||
configuration { "vs2012" }
|
||||
defines { "USE_VS2012" }
|
||||
prepare()
|
||||
test.isequal({}, prj.defines)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Test filtering on command line options.
|
||||
--
|
||||
|
||||
function suite.onOptionNoValue()
|
||||
_OPTIONS["release"] = ""
|
||||
configuration { "release" }
|
||||
defines { "USE_RELEASE" }
|
||||
prepare()
|
||||
test.isequal({ "USE_RELEASE" }, prj.defines)
|
||||
end
|
||||
|
||||
function suite.onOptionNoValueUnset()
|
||||
configuration { "release" }
|
||||
defines { "USE_RELEASE" }
|
||||
prepare()
|
||||
test.isequal({ }, prj.defines)
|
||||
end
|
||||
|
||||
function suite.onOptionWithValue()
|
||||
_OPTIONS["renderer"] = "opengl"
|
||||
configuration { "renderer=opengl" }
|
||||
defines { "USE_OPENGL" }
|
||||
prepare()
|
||||
test.isequal({ "USE_OPENGL" }, prj.defines)
|
||||
end
|
||||
|
||||
function suite.onOptionWithValueMismatch()
|
||||
_OPTIONS["renderer"] = "direct3d"
|
||||
configuration { "renderer=opengl" }
|
||||
defines { "USE_OPENGL" }
|
||||
prepare()
|
||||
test.isequal({ }, prj.defines)
|
||||
end
|
||||
|
||||
function suite.onOptionWithValueUnset()
|
||||
configuration { "renderer=opengl" }
|
||||
defines { "USE_OPENGL" }
|
||||
prepare()
|
||||
test.isequal({ }, prj.defines)
|
||||
end
|
@ -79,6 +79,9 @@
|
||||
dofile("config/test_links.lua")
|
||||
dofile("config/test_targetinfo.lua")
|
||||
|
||||
-- Baking tests
|
||||
dofile("oven/test_filtering.lua")
|
||||
|
||||
-- API tests
|
||||
dofile("api/test_array_kind.lua")
|
||||
dofile("api/test_callback.lua")
|
||||
|
Reference in New Issue
Block a user