Fill in generated skeleton of Visual Studio VS 201x rule files

This commit is contained in:
Jason Perkins 2014-08-14 17:37:35 -04:00
parent 67582066a0
commit 643a0067f0
3 changed files with 495 additions and 11 deletions

View File

@ -13,15 +13,104 @@
m.elements.ruleProps = function(rule)
---
-- Entry point; generate the root <Project> element.
---
m.elements.ruleProps = function(r)
return {
p.xmlUtf8,
p.vstudio.projectElement,
m.targetsGroup,
m.dependsOnGroup,
m.ruleGroup,
}
end
function m.generateRuleProps(rule)
p.callArray(m.elements.ruleProps, rule)
function m.generateRuleProps(r)
p.callArray(m.elements.ruleProps, r)
p.pop()
p.out('</Project>')
end
---
-- Generate the targets property group element.
---
m.elements.targetsGroup = function(r)
return {
m.beforeTargets,
m.afterTargets,
}
end
function m.targetsGroup(r)
p.w('<PropertyGroup')
p.push(' Condition="\'$(%sBeforeTargets)\' == \'\' and \'$(%sAfterTargets)\' == \'\' and \'$(ConfigurationType)\' != \'Makefile\'">',
r.name, r.name)
p.callArray(m.elements.targetsGroup, r)
p.pop('</PropertyGroup>')
end
---
-- Generate the dependencies property group element.
---
m.elements.dependsOnGroup = function(r)
return {
m.dependsOn,
}
end
function m.dependsOnGroup(r)
p.push('<PropertyGroup>')
p.callArray(m.elements.dependsOnGroup, r)
p.pop('</PropertyGroup>')
end
---
-- Generate the rule itemm group element.
---
m.elements.ruleGroup = function(r)
return {
}
end
function m.ruleGroup(r)
p.push('<ItemDefinitionGroup>')
p.push('<%s>', r.name)
p.callArray(m.elements.ruleGroup)
p.pop('</%s>', r.name)
p.pop('</ItemDefinitionGroup>')
end
---
-- Implementations of individual elements.
---
function m.afterTargets(r)
p.w('<%sAfterTargets>CustomBuild</%sAfterTargets>', r.name, r.name)
end
function m.beforeTargets(r)
p.w('<%sBeforeTargets>Midl</%sBeforeTargets>', r.name, r.name)
end
function m.dependsOn(r)
p.w('<%sDependsOn', r.name)
p.w(' Condition="\'$(ConfigurationType)\' != \'Makefile\'">_SelectedFiles;$(%sDependsOn)</%sDependsOn>',
r.name, r.name, r.name)
end

View File

@ -9,15 +9,294 @@
local p = premake
m.elements.ruleTargets = function(rule)
---
-- Entry point; generate the root <Project> element.
---
m.elements.ruleTargets = function(r)
return {
p.xmlUtf8,
p.vstudio.projectElement,
m.availableItemGroup,
m.computeInputsGroup,
m.usingTask,
m.ruleTarget,
}
end
function m.generateRuleTargets(rule)
p.callArray(m.elements.ruleTargets)
function m.generateRuleTargets(r)
p.callArray(m.elements.ruleTargets, r)
p.pop()
p.out('</Project>')
end
---
-- Generate the opening item group element.
---
m.elements.availableItemGroup = function(r)
return {
m.propertyPageSchema,
m.availableItemName,
}
end
function m.availableItemGroup(r)
p.push('<ItemGroup>')
p.callArray(m.elements.availableItemGroup, r)
p.pop('</ItemGroup>')
end
---
-- Generate the computed input targets group.
---
m.elements.computeInputsGroup = function(r)
return {
m.computeLinkInputsTargets,
m.computeLibInputsTargets,
}
end
function m.computeInputsGroup(r)
p.push('<PropertyGroup>')
p.callArray(m.elements.computeInputsGroup, r)
p.pop('</PropertyGroup>')
end
---
-- Generate the rule's target element.
---
m.elements.ruleTargetAttributes = function(r)
return {
m.targetName,
m.beforeTargets,
m.afterTargets,
m.targetCondition,
m.targetOutputs,
m.targetInputs,
m.dependsOnTargets,
}
end
m.elements.ruleTarget = function(r)
return {
m.selectedFiles,
m.tlog,
m.message,
m.writeLinesToFile,
m.rule,
m.computeOutput,
}
end
function m.ruleTarget(r)
local attribs = p.capture(function()
p.push()
p.callArray(m.elements.ruleTargetAttributes, r)
p.pop()
end)
p.push('<Target')
p.outln(attribs .. '>')
p.callArray(m.elements.ruleTarget, r)
p.pop('</Target>')
end
---
-- Write out the rule element.
---
m.elements.ruleAttributes = function(r)
return {
m.ruleCondition,
m.commandLineTemplate,
m.ruleInputs,
}
end
function m.rule(r)
local attribs = p.capture(function()
p.push()
p.callArray(m.elements.ruleAttributes, r)
p.pop()
end)
p.w('<%s', r.name)
p.outln(attribs .. ' />')
end
---
-- Generate the rule's computed output element.
---
m.elements.computeOutput = function(r)
return {
}
end
function m.computeOutput(r)
p.push('<Target')
p.w('Name="Compute%sOutput"', r.name)
p.w('Condition="\'@(%s)\' != \'\'">', r.name)
p.pop('</Target>')
end
---
-- Implementations of individual elements.
---
function m.ruleCondition(r)
p.w('Condition="\'@(%s)\' != \'\' and \'%%(%s.ExcludedFromBuild)\' != \'true\'"', r.name, r.name)
end
function m.commandLineTemplate(r)
p.w('CommandLineTemplate="%%(%s.CommandLineTemplate)"', r.name)
end
function m.ruleInputs(r)
p.w('Inputs="%%(%s.Identity)"', r.name)
end
function m.afterTargets(r)
p.w('AfterTargets="$(%sAfterTargets)"', r.name)
end
function m.availableItemName(r)
p.push('<AvailableItemName Include="%s">', r.name)
p.w('<Targets>_%s</Targets>', r.name)
p.pop('</AvailableItemName>')
end
function m.beforeTargets(r)
p.w('BeforeTargets="$(%sBeforeTargets)"', r.name)
end
function m.computeLibInputsTargets(r)
p.push('<ComputeLibInputsTargets>')
p.w('$(ComputeLibInputsTargets);')
p.w('Compute%sOutput;', r.name)
p.pop('</ComputeLibInputsTargets>')
end
function m.computeLinkInputsTargets(r)
p.push('<ComputeLinkInputsTargets>')
p.w('$(ComputeLinkInputsTargets);')
p.w('Compute%sOutput;', r.name)
p.pop('</ComputeLinkInputsTargets>')
end
function m.dependsOnTargets(r)
p.w('DependsOnTargets="$(%sDependsOn)"', r.name)
end
function m.message(r)
p.w('<Message')
p.w(' Importance="High"')
p.w(' Text="%%(%s.ExecutionDescription)" />', r.name)
end
function m.propertyPageSchema(r)
p.w('<PropertyPageSchema')
p.w(' Include="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml" />')
end
function m.selectedFiles(r)
p.push('<ItemGroup Condition="\'@(SelectedFiles)\' != \'\'">')
p.w('<%s Remove="@(%s)" Condition="\'%%(Identity)\' != \'@(SelectedFiles)\'" />', r.name, r.name)
p.pop('</ItemGroup>')
end
function m.targetCondition(r)
p.w('Condition="\'@(%s)\' != \'\'"', r.name)
end
function m.targetInputs(r)
p.w('Inputs="%%(%s.Identity);%%(%s.AdditionalDependencies);$(MSBuildProjectFile)"', r.name, r.name)
end
function m.targetName(r)
p.w('Name="_%s"', r.name)
end
function m.targetOutputs(r)
p.w('Outputs="%%(%s.Outputs)"', r.name)
end
function m.tlog(r)
p.push('<ItemGroup>')
p.push('<%s_tlog Include="%%(%s.Outputs)" Condition="\'%%(%s.Outputs)\' != \'\' and \'%%(%s.ExcludedFromBuild)\' != \'true\'">',
r.name, r.name, r.name, r.name)
p.w('<Source>@(%s, \'|\')</Source>', r.name)
p.pop('</%s_tlog>', r.name)
p.pop('</ItemGroup>')
end
function m.usingTask(r)
p.push('<UsingTask')
p.w('TaskName="%s"', r.name)
p.w('TaskFactory="XamlTaskFactory"')
p.w('AssemblyName="Microsoft.Build.Tasks.v4.0">')
p.w('<Task>$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml</Task>')
p.pop('</UsingTask>')
end
function m.writeLinesToFile(r)
p.w('<WriteLinesToFile')
p.w(' Condition="\'@(%s_tlog)\' != \'\' and \'%%(%s_tlog.ExcludedFromBuild)\' != \'true\'"', r.name, r.name)
p.w(' File="$(IntDir)$(ProjectName).write.1.tlog"')
p.w(' Lines="^%%(%s_tlog.Source);@(%s_tlog-&gt;\'%%(Fullpath)\')" />', r.name, r.name)
end

View File

@ -7,16 +7,132 @@
local m = premake.vstudio.rules
local p = premake
local project = p.project
local tree = p.tree
m.elements.ruleXml = function(rule)
---
-- Entry point; generate the root <ProjectSchemaDefinitions> element.
---
m.elements.ruleXml = function(r)
return {
p.xmlUtf8,
m.projectSchemaDefinitions,
m.rule,
m.ruleItem,
m.fileExtension,
m.contentType,
}
end
function m.generateRuleXml(rule)
p.callArray(m.elements.ruleXml, rule)
function m.generateRuleXml(r)
p.callArray(m.elements.ruleXml, r)
p.pop('</ProjectSchemaDefinitions>')
end
---
-- Generate the main <Rule> element.
---
m.elements.rule = function(r)
return {
m.dataSource,
m.categories,
}
end
function m.rule(r)
p.push('<Rule')
p.w('Name="%s"', r.name)
p.w('PageTemplate="tool"')
p.w('DisplayName="%s"', r.name)
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
p.pop('</<Rule.Categories>')
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
---
-- Implementations of individual elements.
---
function m.contentType(r)
p.w('<ContentType')
p.w(' Name="%s"', r.name)
p.w(' DisplayName="%s"', r.name)
p.w(' ItemType="%s" />', r.name)
end
function m.dataSource(r)
p.push('<Rule.DataSource>')
p.w('<DataSource')
p.w(' Persistence="ProjectFile"')
p.w(' ItemType="%s" />', r.name)
p.pop('</Rule.DataSource>')
end
function m.fileExtension(r)
p.w('<FileExtension')
p.w(' Name="*.XYZ"')
p.w(' ContentType="%s" />', r.name)
end
function m.ruleItem(r)
p.w('<ItemType')
p.w(' Name="%s"', r.name)
p.w(' DisplayName="%s" />', r.name)
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