Support project-level custom rule variables for VS 201x
This commit is contained in:
parent
8d206735b6
commit
19c3d7c972
@ -136,12 +136,6 @@
|
|||||||
tokens = true,
|
tokens = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
api.register {
|
|
||||||
name = "customRule",
|
|
||||||
scope = "config",
|
|
||||||
kind = "string",
|
|
||||||
}
|
|
||||||
|
|
||||||
api.register {
|
api.register {
|
||||||
name = "customRules",
|
name = "customRules",
|
||||||
scope = "project",
|
scope = "project",
|
||||||
|
@ -240,7 +240,7 @@
|
|||||||
m.elements.itemDefinitionGroup = function(cfg)
|
m.elements.itemDefinitionGroup = function(cfg)
|
||||||
if cfg.kind == p.UTILITY then
|
if cfg.kind == p.UTILITY then
|
||||||
return {
|
return {
|
||||||
|
m.customRuleVars,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return {
|
return {
|
||||||
@ -251,6 +251,7 @@
|
|||||||
m.buildEvents,
|
m.buildEvents,
|
||||||
m.imageXex,
|
m.imageXex,
|
||||||
m.deploy,
|
m.deploy,
|
||||||
|
m.customRuleVars,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -462,6 +463,44 @@
|
|||||||
end
|
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()
|
-- Reference any managed assemblies listed in the links()
|
||||||
--
|
--
|
||||||
@ -703,8 +742,8 @@
|
|||||||
local fcfg = fileconfig.getconfig(file, cfg)
|
local fcfg = fileconfig.getconfig(file, cfg)
|
||||||
if fileconfig.hasCustomBuildRule(fcfg) then
|
if fileconfig.hasCustomBuildRule(fcfg) then
|
||||||
return "CustomBuild"
|
return "CustomBuild"
|
||||||
elseif fcfg and fcfg.customRule then
|
elseif fcfg and fcfg._customRule then
|
||||||
return fcfg.customRule
|
return fcfg._customRule
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -992,13 +992,14 @@
|
|||||||
local fieldName = "_custom_" .. name
|
local fieldName = "_custom_" .. name
|
||||||
local field = premake.field.get(fieldName)
|
local field = premake.field.get(fieldName)
|
||||||
if not field then
|
if not field then
|
||||||
api.register {
|
field = premake.field.new {
|
||||||
name = fieldName,
|
name = fieldName,
|
||||||
scope = "config",
|
scope = "config",
|
||||||
kind = kind
|
kind = kind,
|
||||||
|
tokens = true,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
_G[fieldName](value)
|
api.callback(field, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1030,3 +1031,41 @@
|
|||||||
table.remove(value, 1)
|
table.remove(value, 1)
|
||||||
api._customVarFormats[name] = value
|
api._customVarFormats[name] = value
|
||||||
end
|
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
|
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()
|
function suite.customRule_onPerConfigLiteralVars()
|
||||||
files { "hello.dae" }
|
files { "hello.dae" }
|
||||||
filter { "files:**.dae" }
|
filter { "files:**.dae" }
|
||||||
|
Reference in New Issue
Block a user