2014-08-11 21:02:36 +00:00
|
|
|
---
|
|
|
|
-- vs2010_rules_xml.lua
|
|
|
|
-- Generate a Visual Studio 201x custom rules XML file.
|
|
|
|
-- Copyright (c) 2014 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
2014-08-27 14:40:36 +00:00
|
|
|
premake.vstudio.vs2010.rules.xml = {}
|
|
|
|
|
|
|
|
local m = premake.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
|
|
|
local p = premake
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
p.xmlUtf8,
|
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)
|
|
|
|
p.callArray(m.elements.project, r)
|
2014-08-14 21:37:35 +00:00
|
|
|
p.pop('</ProjectSchemaDefinitions>')
|
|
|
|
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-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-10 20:38:38 +00:00
|
|
|
p.w('DisplayName="%s"', r.description 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)
|
|
|
|
local defs = r.propertyDefinition
|
|
|
|
for i = 1, #defs do
|
|
|
|
local def = defs[i]
|
|
|
|
if def.kind == "list" then
|
|
|
|
m.stringListProperty(def)
|
|
|
|
elseif type(def.values) == "table" then
|
|
|
|
m.enumProperty(def)
|
|
|
|
else
|
|
|
|
m.stringProperty(def)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.baseProperty(def)
|
|
|
|
p.w('Name="%s"', def.name)
|
|
|
|
p.w('HelpContext="0"')
|
|
|
|
p.w('DisplayName="%s"', def.display or def.name)
|
|
|
|
p.w('Description="%s"', def.description or def.display or def.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.enumProperty(def)
|
|
|
|
p.push('<EnumProperty')
|
|
|
|
m.baseProperty(def)
|
|
|
|
|
|
|
|
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)
|
|
|
|
p.w('DisplayName="%s"', values[key])
|
|
|
|
p.w('Switch="%s" />', switches[key] or values[key])
|
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
p.pop('</EnumProperty>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.stringProperty(def)
|
|
|
|
p.push('<StringProperty')
|
|
|
|
m.baseProperty(def)
|
|
|
|
p.w('Switch="[value]" />')
|
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.stringListProperty(def)
|
|
|
|
p.push('<StringListProperty')
|
|
|
|
m.baseProperty(def)
|
|
|
|
p.w('Switch="[value]" />')
|
|
|
|
p.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
---
|
|
|
|
-- Implementations of individual elements.
|
|
|
|
---
|
|
|
|
|
|
|
|
function m.contentType(r)
|
2014-09-11 14:20:13 +00:00
|
|
|
p.push('<ContentType')
|
|
|
|
p.w('Name="%s"', r.name)
|
|
|
|
p.w('DisplayName="%s"', r.name)
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.fileExtension(r)
|
2014-09-11 14:20:13 +00:00
|
|
|
p.push('<FileExtension')
|
|
|
|
p.w('Name="*.XYZ"')
|
|
|
|
p.w('ContentType="%s" />', r.name)
|
|
|
|
p.pop()
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.ruleItem(r)
|
2014-09-11 14:20:13 +00:00
|
|
|
p.push('<ItemType')
|
|
|
|
p.w('Name="%s"', r.name)
|
|
|
|
p.w('DisplayName="%s" />', r.name)
|
|
|
|
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
|
|
|
|
|