Support project-level custom rule variables for VS 201x
This commit is contained in:
parent
8d206735b6
commit
19c3d7c972
@ -136,12 +136,6 @@
|
||||
tokens = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
name = "customRule",
|
||||
scope = "config",
|
||||
kind = "string",
|
||||
}
|
||||
|
||||
api.register {
|
||||
name = "customRules",
|
||||
scope = "project",
|
||||
|
@ -240,7 +240,7 @@
|
||||
m.elements.itemDefinitionGroup = function(cfg)
|
||||
if cfg.kind == p.UTILITY then
|
||||
return {
|
||||
|
||||
m.customRuleVars,
|
||||
}
|
||||
else
|
||||
return {
|
||||
@ -251,6 +251,7 @@
|
||||
m.buildEvents,
|
||||
m.imageXex,
|
||||
m.deploy,
|
||||
m.customRuleVars,
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -462,6 +463,44 @@
|
||||
end
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- Write out project-level custom rule variables.
|
||||
---
|
||||
|
||||
function m.customRuleVars(cfg)
|
||||
local vars = p.api.getCustomVars()
|
||||
table.foreachi(cfg.project._customRules, function(rule)
|
||||
local contents = p.capture(function ()
|
||||
p.push()
|
||||
for _, var in ipairs(vars) do
|
||||
if cfg[var] then
|
||||
local key = p.api.getCustomVarKey(var)
|
||||
local value = cfg[var]
|
||||
|
||||
if type(value) == "table" then
|
||||
local fmt = p.api.getCustomListFormat(var)
|
||||
value = table.concat(value, fmt[1])
|
||||
end
|
||||
|
||||
if value and #value > 0 then
|
||||
m.element(key, nil, '%s', value)
|
||||
end
|
||||
end
|
||||
end
|
||||
p.pop()
|
||||
end)
|
||||
|
||||
if #contents > 0 then
|
||||
p.push('<%s>', rule)
|
||||
p.outln(contents)
|
||||
p.pop('</%s>', rule)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Reference any managed assemblies listed in the links()
|
||||
--
|
||||
@ -703,8 +742,8 @@
|
||||
local fcfg = fileconfig.getconfig(file, cfg)
|
||||
if fileconfig.hasCustomBuildRule(fcfg) then
|
||||
return "CustomBuild"
|
||||
elseif fcfg and fcfg.customRule then
|
||||
return fcfg.customRule
|
||||
elseif fcfg and fcfg._customRule then
|
||||
return fcfg._customRule
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -992,13 +992,14 @@
|
||||
local fieldName = "_custom_" .. name
|
||||
local field = premake.field.get(fieldName)
|
||||
if not field then
|
||||
api.register {
|
||||
field = premake.field.new {
|
||||
name = fieldName,
|
||||
scope = "config",
|
||||
kind = kind
|
||||
kind = kind,
|
||||
tokens = true,
|
||||
}
|
||||
end
|
||||
_G[fieldName](value)
|
||||
api.callback(field, value)
|
||||
end
|
||||
|
||||
|
||||
@ -1030,3 +1031,41 @@
|
||||
table.remove(value, 1)
|
||||
api._customVarFormats[name] = value
|
||||
end
|
||||
|
||||
|
||||
function customRule(value)
|
||||
-- Store the rule name in the current configuration, like a
|
||||
-- normal set-field operation would
|
||||
local fieldName = "_customRule"
|
||||
local field = premake.field.get(fieldName)
|
||||
if not field then
|
||||
field = premake.field.new {
|
||||
name = fieldName,
|
||||
scope = "config",
|
||||
kind = "string",
|
||||
}
|
||||
end
|
||||
api.callback(field, value)
|
||||
|
||||
-- Wild hack: I need a way to get all of the custom rule names that are
|
||||
-- in use within a project. The rule names are currently only associated
|
||||
-- with individual files. Rather than iterating over all the files after
|
||||
-- the fact, keep a master list of rule names in the first configuration
|
||||
-- block of the project. This way it will come out of the baking system
|
||||
-- looking like a normal list:string field.
|
||||
fieldName = "_customRules"
|
||||
field = premake.field.get(fieldName)
|
||||
if not field then
|
||||
field = premake.field.new {
|
||||
name = fieldName,
|
||||
scope = "config",
|
||||
kind = "list:string"
|
||||
}
|
||||
end
|
||||
|
||||
local cset = api.gettarget()
|
||||
local current = cset.current
|
||||
cset.current = cset.blocks[1]
|
||||
api.callback(field, value)
|
||||
cset.current = current
|
||||
end
|
||||
|
@ -530,6 +530,24 @@
|
||||
end
|
||||
|
||||
|
||||
function suite.customRule_onLiteralPath()
|
||||
targetdir "../bin/%{cfg.buildcfg}"
|
||||
files { "hello.dae" }
|
||||
filter "files:**.dae"
|
||||
customRule "Animation"
|
||||
customVar { "OutputDirectory", "%{cfg.targetdir}/anim" }
|
||||
prepare()
|
||||
test.capture [[
|
||||
<ItemGroup>
|
||||
<Animation Include="hello.dae">
|
||||
<OutputDirectory Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../bin/Debug/anim</OutputDirectory>
|
||||
<OutputDirectory Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../bin/Release/anim</OutputDirectory>
|
||||
</Animation>
|
||||
</ItemGroup>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
function suite.customRule_onPerConfigLiteralVars()
|
||||
files { "hello.dae" }
|
||||
filter { "files:**.dae" }
|
||||
|
Loading…
Reference in New Issue
Block a user