---
-- vs2010_rules_xml.lua
-- Generate a Visual Studio 201x custom rules XML file.
-- Copyright (c) Jason Perkins and the Premake project
--
local p = premake
p.vstudio.vs2010.rules.xml = {}
local m = p.vstudio.vs2010.rules.xml
m.elements = {}
---
-- Entry point; generate the root element.
---
m.elements.project = function(r)
return {
m.projectSchemaDefinitions,
m.rule,
m.ruleItem,
m.fileExtension,
m.contentType,
}
end
function m.generate(r)
p.xmlUtf8()
p.callArray(m.elements.project, r)
p.out('')
end
---
-- Generate the main element.
---
m.elements.rule = function(r)
return {
m.dataSource,
m.categories,
m.inputs,
m.properties,
m.commandLineTemplate,
m.beforeTargets,
m.afterTargets,
m.outputs,
m.executionDescription,
m.additionalDependencies,
m.additionalOptions,
}
end
function m.rule(r)
p.push('')
p.callArray(m.elements.rule, r)
p.pop('')
end
---
-- Generate the list of categories.
---
function m.categories(r)
local categories = {
[1] = { name="General" },
[2] = { name="Command Line", subtype="CommandLine" },
}
p.push('')
for i = 1, #categories do
m.category(categories[i])
end
p.pop('')
end
function m.category(cat)
local attribs = p.capture(function()
p.push()
p.w('Name="%s"', cat.name)
if cat.subtype then
p.w('Subtype="%s"', cat.subtype)
end
p.pop()
end)
p.push('')
p.push('')
p.w('%s', cat.name)
p.pop('')
p.pop('')
end
---
-- Generate the list of property definitions.
---
function m.properties(r)
local defs = r.propertydefinition
for i = 1, #defs do
local def = defs[i]
if def.kind == "boolean" then
m.boolProperty(def)
elseif def.kind == "list" then
m.stringListProperty(def)
elseif type(def.values) == "table" then
m.enumProperty(def)
elseif def.kind and def.kind:startswith("list:") then
m.stringListProperty(def)
else
m.stringProperty(def)
end
end
end
function m.baseProperty(def, suffix)
local c = p.capture(function ()
p.w('Name="%s"', def.name)
p.w('HelpContext="0"')
p.w('DisplayName="%s"', def.display or def.name)
if def.description then
p.w('Description="%s"', def.description)
end
end)
if suffix then
c = c .. suffix
end
p.outln(c)
end
function m.boolProperty(def)
p.push('')
p.pop()
end
function m.enumProperty(def)
p.push('')
local values = def.values
local switches = def.switch or {}
local keys = table.keys(def.values)
table.sort(keys)
for _, key in pairs(keys) do
p.push('')
p.pop()
end
p.pop('')
end
function m.stringProperty(def)
p.push('')
p.pop()
end
function m.stringListProperty(def)
p.push('')
p.pop()
end
---
-- Implementations of individual elements.
---
function m.additionalDependencies(r)
p.push('')
p.pop()
end
function m.additionalOptions(r)
p.push('')
p.push('')
p.w('Additional Options')
p.pop('')
p.push('')
p.w('Additional Options')
p.pop('')
p.pop('')
end
function m.afterTargets(r)
p.push('')
p.push('')
p.w('Execute After')
p.pop('')
p.push('')
p.w('Specifies the targets for the build customization to run after.')
p.pop('')
p.push('')
p.push('', r.name)
p.pop()
p.pop('')
p.push('')
p.push('')
p.pop()
p.pop('')
p.pop('')
end
function m.beforeTargets(r)
p.push('')
p.push('')
p.w('Execute Before')
p.pop('')
p.push('')
p.w('Specifies the targets for the build customization to run before.')
p.pop('')
p.push('')
p.push('', r.name)
p.pop()
p.pop('')
p.push('')
p.push('')
p.pop()
p.pop('')
p.pop('')
end
function m.commandLineTemplate(r)
p.push('')
p.pop()
end
function m.contentType(r)
p.push('', r.name)
p.pop()
end
function m.dataSource(r)
p.push('')
p.push('', r.name)
p.pop()
p.pop('')
end
function m.executionDescription(r)
p.push('')
p.pop()
end
function m.fileExtension(r)
for _, v in ipairs(r.fileextension) do
p.push('', r.name)
p.pop()
end
end
function m.inputs(r)
p.push('')
p.push('')
p.push('')
p.pop()
p.pop('')
p.pop('')
end
function m.outputs(r)
p.push('')
p.pop()
end
function m.ruleItem(r)
p.push('', r.display or r.name)
p.pop()
end
function m.projectSchemaDefinitions(r)
p.push('')
end