2014-08-11 21:02:36 +00:00
|
|
|
---
|
|
|
|
-- vs2010_rules_xml.lua
|
|
|
|
-- Generate a Visual Studio 201x custom rules XML file.
|
2017-08-30 18:35:42 +00:00
|
|
|
-- Copyright (c) Jason Perkins and the Premake project
|
2014-08-11 21:02:36 +00:00
|
|
|
--
|
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
local p = premake
|
|
|
|
p.vstudio.vs2010.rules.xml = {}
|
2014-08-27 14:40:36 +00:00
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
local m = p.vstudio.vs2010.rules.xml
|
2014-08-14 21:45:44 +00:00
|
|
|
m.elements = {}
|
2014-08-11 21:50:55 +00:00
|
|
|
|
2014-08-11 21:02:36 +00:00
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
---
|
|
|
|
-- Entry point; generate the root <ProjectSchemaDefinitions> element.
|
|
|
|
---
|
|
|
|
|
2014-08-14 21:45:44 +00:00
|
|
|
m.elements.project = function(r)
|
2014-08-11 21:50:55 +00:00
|
|
|
return {
|
2014-08-14 21:37:35 +00:00
|
|
|
m.projectSchemaDefinitions,
|
|
|
|
m.rule,
|
|
|
|
m.ruleItem,
|
|
|
|
m.fileExtension,
|
|
|
|
m.contentType,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-08-14 21:45:44 +00:00
|
|
|
function m.generate(r)
|
2016-05-02 23:26:42 +00:00
|
|
|
p.xmlUtf8()
|
2014-08-14 21:45:44 +00:00
|
|
|
p.callArray(m.elements.project, r)
|
2014-09-19 19:26:56 +00:00
|
|
|
p.out('</ProjectSchemaDefinitions>')
|
2014-08-14 21:37:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
-- Generate the main <Rule> element.
|
|
|
|
---
|
|
|
|
|
|
|
|
m.elements.rule = function(r)
|
|
|
|
return {
|
|
|
|
m.dataSource,
|
|
|
|
m.categories,
|
2014-09-11 14:20:13 +00:00
|
|
|
m.inputs,
|
|
|
|
m.properties,
|
2014-09-19 19:26:56 +00:00
|
|
|
m.commandLineTemplate,
|
|
|
|
m.beforeTargets,
|
|
|
|
m.afterTargets,
|
|
|
|
m.outputs,
|
|
|
|
m.executionDescription,
|
|
|
|
m.additionalDependencies,
|
|
|
|
m.additionalOptions,
|
2014-08-11 21:50:55 +00:00
|
|
|
}
|
|
|
|
end
|
2014-08-11 21:02:36 +00:00
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
function m.rule(r)
|
|
|
|
p.push('<Rule')
|
|
|
|
p.w('Name="%s"', r.name)
|
|
|
|
p.w('PageTemplate="tool"')
|
2014-09-11 14:57:13 +00:00
|
|
|
p.w('DisplayName="%s"', r.display or r.name)
|
2014-08-14 21:37:35 +00:00
|
|
|
p.w('Order="200">')
|
|
|
|
p.callArray(m.elements.rule, r)
|
|
|
|
p.pop('</Rule>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
-- Generate the list of categories.
|
|
|
|
---
|
|
|
|
|
|
|
|
function m.categories(r)
|
|
|
|
local categories = {
|
|
|
|
[1] = { name="General" },
|
|
|
|
[2] = { name="Command Line", subtype="CommandLine" },
|
|
|
|
}
|
|
|
|
p.push('<Rule.Categories>')
|
|
|
|
for i = 1, #categories do
|
|
|
|
m.category(categories[i])
|
|
|
|
end
|
2014-09-10 20:38:38 +00:00
|
|
|
p.pop('</Rule.Categories>')
|
2014-08-14 21:37:35 +00:00
|
|
|
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('<Category')
|
|
|
|
p.outln(attribs .. '>')
|
|
|
|
|
|
|
|
p.push('<Category.DisplayName>')
|
|
|
|
p.w('<sys:String>%s</sys:String>', cat.name)
|
|
|
|
p.pop('</Category.DisplayName>')
|
|
|
|
|
|
|
|
p.pop('</Category>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-11 14:20:13 +00:00
|
|
|
---
|
|
|
|
-- Generate the list of property definitions.
|
|
|
|
---
|
|
|
|
|
|
|
|
function m.properties(r)
|
2015-05-05 18:46:00 +00:00
|
|
|
local defs = r.propertydefinition
|
2014-09-11 14:20:13 +00:00
|
|
|
for i = 1, #defs do
|
|
|
|
local def = defs[i]
|
2014-09-11 14:57:13 +00:00
|
|
|
if def.kind == "boolean" then
|
|
|
|
m.boolProperty(def)
|
|
|
|
elseif def.kind == "list" then
|
2014-09-11 14:20:13 +00:00
|
|
|
m.stringListProperty(def)
|
|
|
|
elseif type(def.values) == "table" then
|
|
|
|
m.enumProperty(def)
|
2016-11-21 18:37:08 +00:00
|
|
|
elseif def.kind and def.kind:startswith("list:") then
|
2016-08-01 21:40:40 +00:00
|
|
|
m.stringListProperty(def)
|
2014-09-11 14:20:13 +00:00
|
|
|
else
|
|
|
|
m.stringProperty(def)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-09-23 19:44:16 +00:00
|
|
|
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)
|
2014-09-11 14:57:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.boolProperty(def)
|
|
|
|
p.push('<BoolProperty')
|
|
|
|
m.baseProperty(def)
|
2016-09-06 18:47:18 +00:00
|
|
|
if def.switch then
|
|
|
|
p.w('Switch="%s"', def.switch)
|
|
|
|
end
|
2017-06-13 19:11:54 +00:00
|
|
|
p.w('/>')
|
2014-09-11 14:57:13 +00:00
|
|
|
p.pop()
|
2014-09-11 14:20:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.enumProperty(def)
|
|
|
|
p.push('<EnumProperty')
|
2014-09-23 19:44:16 +00:00
|
|
|
m.baseProperty(def, '>')
|
2014-09-11 14:20:13 +00:00
|
|
|
|
|
|
|
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('<EnumValue')
|
|
|
|
p.w('Name="%d"', key)
|
2014-09-11 14:57:13 +00:00
|
|
|
if switches[key] then
|
|
|
|
p.w('DisplayName="%s"', values[key])
|
2016-09-06 18:47:18 +00:00
|
|
|
if switches[key] then
|
|
|
|
p.w('Switch="%s"', switches[key])
|
|
|
|
end
|
2014-09-11 14:57:13 +00:00
|
|
|
else
|
2017-06-13 19:11:54 +00:00
|
|
|
p.w('DisplayName="%s"', values[key])
|
2014-09-11 14:57:13 +00:00
|
|
|
end
|
2017-06-13 19:11:54 +00:00
|
|
|
p.w('/>')
|
2014-09-11 14:20:13 +00:00
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
p.pop('</EnumProperty>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.stringProperty(def)
|
|
|
|
p.push('<StringProperty')
|
|
|
|
m.baseProperty(def)
|
2016-09-06 18:47:18 +00:00
|
|
|
if def.switch then
|
|
|
|
p.w('Switch="%s"', def.switch)
|
|
|
|
end
|
2017-06-13 19:11:54 +00:00
|
|
|
p.w('/>')
|
2014-09-11 14:20:13 +00:00
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.stringListProperty(def)
|
|
|
|
p.push('<StringListProperty')
|
|
|
|
m.baseProperty(def)
|
2016-09-06 18:47:18 +00:00
|
|
|
if def.separator then
|
|
|
|
p.w('Separator="%s"', def.separator)
|
|
|
|
end
|
|
|
|
if def.switch then
|
|
|
|
p.w('Switch="%s"', def.switch)
|
|
|
|
end
|
2017-06-13 19:11:54 +00:00
|
|
|
p.w('/>')
|
2014-09-11 14:20:13 +00:00
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
---
|
|
|
|
-- Implementations of individual elements.
|
|
|
|
---
|
|
|
|
|
2014-09-19 19:26:56 +00:00
|
|
|
function m.additionalDependencies(r)
|
|
|
|
p.push('<StringListProperty')
|
|
|
|
p.w('Name="AdditionalDependencies"')
|
|
|
|
p.w('DisplayName="Additional Dependencies"')
|
|
|
|
p.w('IncludeInCommandLine="False"')
|
|
|
|
p.w('Visible="false" />')
|
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.additionalOptions(r)
|
|
|
|
p.push('<StringProperty')
|
|
|
|
p.w('Subtype="AdditionalOptions"')
|
|
|
|
p.w('Name="AdditionalOptions"')
|
|
|
|
p.w('Category="Command Line">')
|
|
|
|
p.push('<StringProperty.DisplayName>')
|
|
|
|
p.w('<sys:String>Additional Options</sys:String>')
|
|
|
|
p.pop('</StringProperty.DisplayName>')
|
|
|
|
p.push('<StringProperty.Description>')
|
|
|
|
p.w('<sys:String>Additional Options</sys:String>')
|
|
|
|
p.pop('</StringProperty.Description>')
|
|
|
|
p.pop('</StringProperty>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.afterTargets(r)
|
|
|
|
p.push('<DynamicEnumProperty')
|
|
|
|
p.w('Name="%sAfterTargets"', r.name)
|
|
|
|
p.w('Category="General"')
|
|
|
|
p.w('EnumProvider="Targets"')
|
|
|
|
p.w('IncludeInCommandLine="False">')
|
|
|
|
|
|
|
|
p.push('<DynamicEnumProperty.DisplayName>')
|
|
|
|
p.w('<sys:String>Execute After</sys:String>')
|
|
|
|
p.pop('</DynamicEnumProperty.DisplayName>')
|
|
|
|
|
|
|
|
p.push('<DynamicEnumProperty.Description>')
|
|
|
|
p.w('<sys:String>Specifies the targets for the build customization to run after.</sys:String>')
|
|
|
|
p.pop('</DynamicEnumProperty.Description>')
|
|
|
|
|
|
|
|
p.push('<DynamicEnumProperty.ProviderSettings>')
|
|
|
|
p.push('<NameValuePair')
|
|
|
|
p.w('Name="Exclude"')
|
|
|
|
p.w('Value="^%sAfterTargets|^Compute" />', r.name)
|
|
|
|
p.pop()
|
|
|
|
p.pop('</DynamicEnumProperty.ProviderSettings>')
|
|
|
|
|
|
|
|
p.push('<DynamicEnumProperty.DataSource>')
|
|
|
|
p.push('<DataSource')
|
|
|
|
p.w('Persistence="ProjectFile"')
|
|
|
|
p.w('ItemType=""')
|
|
|
|
p.w('HasConfigurationCondition="true" />')
|
|
|
|
p.pop()
|
|
|
|
p.pop('</DynamicEnumProperty.DataSource>')
|
|
|
|
|
|
|
|
p.pop('</DynamicEnumProperty>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.beforeTargets(r)
|
|
|
|
p.push('<DynamicEnumProperty')
|
|
|
|
p.w('Name="%sBeforeTargets"', r.name)
|
|
|
|
p.w('Category="General"')
|
|
|
|
p.w('EnumProvider="Targets"')
|
|
|
|
p.w('IncludeInCommandLine="False">')
|
|
|
|
|
|
|
|
p.push('<DynamicEnumProperty.DisplayName>')
|
|
|
|
p.w('<sys:String>Execute Before</sys:String>')
|
|
|
|
p.pop('</DynamicEnumProperty.DisplayName>')
|
|
|
|
|
|
|
|
p.push('<DynamicEnumProperty.Description>')
|
|
|
|
p.w('<sys:String>Specifies the targets for the build customization to run before.</sys:String>')
|
|
|
|
p.pop('</DynamicEnumProperty.Description>')
|
|
|
|
|
|
|
|
p.push('<DynamicEnumProperty.ProviderSettings>')
|
|
|
|
p.push('<NameValuePair')
|
|
|
|
p.w('Name="Exclude"')
|
|
|
|
p.w('Value="^%sBeforeTargets|^Compute" />', r.name)
|
|
|
|
p.pop()
|
|
|
|
p.pop('</DynamicEnumProperty.ProviderSettings>')
|
|
|
|
|
|
|
|
p.push('<DynamicEnumProperty.DataSource>')
|
|
|
|
p.push('<DataSource')
|
|
|
|
p.w('Persistence="ProjectFile"')
|
|
|
|
p.w('HasConfigurationCondition="true" />')
|
|
|
|
p.pop()
|
|
|
|
p.pop('</DynamicEnumProperty.DataSource>')
|
|
|
|
|
|
|
|
p.pop('</DynamicEnumProperty>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.commandLineTemplate(r)
|
|
|
|
p.push('<StringProperty')
|
|
|
|
p.w('Name="CommandLineTemplate"')
|
|
|
|
p.w('DisplayName="Command Line"')
|
|
|
|
p.w('Visible="False"')
|
|
|
|
p.w('IncludeInCommandLine="False" />')
|
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
function m.contentType(r)
|
2014-09-11 14:20:13 +00:00
|
|
|
p.push('<ContentType')
|
|
|
|
p.w('Name="%s"', r.name)
|
2014-09-19 19:26:56 +00:00
|
|
|
p.w('DisplayName="%s"', r.display or r.name)
|
2014-09-11 14:20:13 +00:00
|
|
|
p.w('ItemType="%s" />', r.name)
|
|
|
|
p.pop()
|
2014-08-14 21:37:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.dataSource(r)
|
|
|
|
p.push('<Rule.DataSource>')
|
2014-09-11 14:20:13 +00:00
|
|
|
p.push('<DataSource')
|
|
|
|
p.w('Persistence="ProjectFile"')
|
|
|
|
p.w('ItemType="%s" />', r.name)
|
|
|
|
p.pop()
|
2014-08-14 21:37:35 +00:00
|
|
|
p.pop('</Rule.DataSource>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-19 19:26:56 +00:00
|
|
|
function m.executionDescription(r)
|
|
|
|
p.push('<StringProperty')
|
|
|
|
p.w('Name="ExecutionDescription"')
|
|
|
|
p.w('DisplayName="Execution Description"')
|
|
|
|
p.w('Visible="False"')
|
|
|
|
p.w('IncludeInCommandLine="False" />')
|
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
function m.fileExtension(r)
|
2016-08-01 21:41:25 +00:00
|
|
|
for _, v in ipairs(r.fileextension) do
|
|
|
|
p.push('<FileExtension')
|
|
|
|
p.w('Name="*%s"', v)
|
|
|
|
p.w('ContentType="%s" />', r.name)
|
|
|
|
p.pop()
|
|
|
|
end
|
2014-09-11 14:20:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.inputs(r)
|
|
|
|
p.push('<StringListProperty')
|
|
|
|
p.w('Name="Inputs"')
|
|
|
|
p.w('Category="Command Line"')
|
|
|
|
p.w('IsRequired="true"')
|
|
|
|
p.w('Switch=" ">')
|
|
|
|
|
|
|
|
p.push('<StringListProperty.DataSource>')
|
|
|
|
p.push('<DataSource')
|
|
|
|
p.w('Persistence="ProjectFile"')
|
|
|
|
p.w('ItemType="%s"', r.name)
|
|
|
|
p.w('SourceType="Item" />')
|
|
|
|
p.pop()
|
|
|
|
|
|
|
|
p.pop('</StringListProperty.DataSource>')
|
|
|
|
p.pop('</StringListProperty>')
|
2014-08-11 21:02:36 +00:00
|
|
|
end
|
2014-08-14 21:37:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-19 19:26:56 +00:00
|
|
|
function m.outputs(r)
|
|
|
|
p.push('<StringListProperty')
|
|
|
|
p.w('Name="Outputs"')
|
|
|
|
p.w('DisplayName="Outputs"')
|
|
|
|
p.w('Visible="False"')
|
|
|
|
p.w('IncludeInCommandLine="False" />')
|
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
function m.ruleItem(r)
|
2014-09-11 14:20:13 +00:00
|
|
|
p.push('<ItemType')
|
|
|
|
p.w('Name="%s"', r.name)
|
2014-09-19 19:26:56 +00:00
|
|
|
p.w('DisplayName="%s" />', r.display or r.name)
|
2014-09-11 14:20:13 +00:00
|
|
|
p.pop()
|
2014-08-14 21:37:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.projectSchemaDefinitions(r)
|
|
|
|
p.push('<ProjectSchemaDefinitions xmlns="http://schemas.microsoft.com/build/2009/properties" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib">')
|
|
|
|
end
|
|
|
|
|