Skip to content

Commit

Permalink
Enable msbuild batching for custom rules
Browse files Browse the repository at this point in the history
add `rule.inputs` and `rule.outputs` pathVars
add test cases
add documentation
  • Loading branch information
cathei committed Sep 18, 2023
1 parent 561f9a9 commit 0027213
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 6 deletions.
5 changes: 5 additions & 0 deletions modules/codelite/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
onCleanTarget = function(prj)
p.modules.codelite.cleanTarget(prj)
end,

pathVars = {
["rule.inputs"] = { absolute = false, token = "$<" },
["rule.outputs"] = { absolute = false, token = "$@" }
}
}


Expand Down
7 changes: 6 additions & 1 deletion modules/gmake2/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@

onCleanProject = function(prj)
p.clean.file(prj, p.modules.gmake2.getmakefilename(prj, true))
end
end,

pathVars = {
["rule.inputs"] = { absolute = false, token = "$<" },
["rule.outputs"] = { absolute = false, token = "$@" }
}
}

--
Expand Down
17 changes: 17 additions & 0 deletions modules/vstudio/tests/vc2010/test_rule_props.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
'%{output_path}%{file.basename}.example.cc',
'%{output_path}%{file.basename}.example.h'
}
builddependencies {
'dependency_1.lib',
'dependency_2.lib',
}
end


Expand Down Expand Up @@ -68,3 +72,16 @@
]]
end


--
-- additionalDependencies
--

function suite.additionalDependencies()
local r = test.getRule("example")
m.additionalDependencies(r)

test.capture [[
<AdditionalDependencies>dependency_1.lib;dependency_2.lib</AdditionalDependencies>
]]
end
53 changes: 53 additions & 0 deletions modules/vstudio/tests/vc2010/test_rule_targets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,56 @@
</UsingTask>
]]
end



--
-- ruleTask
--

function suite.ruleTask()
local r = test.getRule("example")
m.rule(r)

test.capture [[
<example
Condition="'@(example)' != '' and '%(example.ExcludedFromBuild)' != 'true'"
CommandLineTemplate="%(example.CommandLineTemplate)"
output_path="%(example.output_path)"
AdditionalOptions="%(example.AdditionalOptions)"
Inputs="@(example)"
Outputs="@(example->'%(Outputs)')"
StandardOutputImportance="High"
StandardErrorImportance="High" />
]]
end



--
-- targetInputs
--

function suite.targetInputs()
local r = test.getRule("example")
m.targetInputs(r)

test.capture [[
Inputs="@(example);%(example.AdditionalDependencies);$(MSBuildProjectFile)"
]]
end



--
-- targetOutputs
--

function suite.targetOutputs()
local r = test.getRule("example")
m.targetOutputs(r)

test.capture [[
Outputs="@(example->'%(Outputs)')"
]]
end
2 changes: 2 additions & 0 deletions modules/vstudio/vs2010.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
["file.reldirectory"] = { absolute = false, token = "%(RelativeDir)" },
["file.extension"] = { absolute = false, token = "%(Extension)" },
["file.name"] = { absolute = false, token = "%(Filename)%(Extension)" },
["rule.inputs"] = { absolute = false, token = "[Inputs]" },
["rule.outputs"] = { absolute = false, token = "[Outputs]" },
}


Expand Down
8 changes: 5 additions & 3 deletions modules/vstudio/vs2010_rules_targets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@


function m.inputs(r)
p.w('Inputs="%%(%s.Identity)"', r.name)
-- inputs and outputs passed to task
p.w('Inputs="@(%s)"', r.name)
p.w('Outputs="@(%s->\'%%(Outputs)\')"', r.name)
end


Expand Down Expand Up @@ -410,7 +412,7 @@
end
end
extra = table.concat(extra)
p.w('Inputs="%%(%s.Identity);%%(%s.AdditionalDependencies);%s$(MSBuildProjectFile)"', r.name, r.name, extra)
p.w('Inputs="@(%s);%%(%s.AdditionalDependencies);%s$(MSBuildProjectFile)"', r.name, r.name, extra)
end


Expand All @@ -422,7 +424,7 @@


function m.targetOutputs(r)
p.w('Outputs="%%(%s.Outputs)"', r.name)
p.w('Outputs="@(%s->\'%%(Outputs)\')"', r.name)
end


Expand Down
3 changes: 1 addition & 2 deletions modules/vstudio/vs2010_rules_xml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@
p.push('<StringListProperty')
p.w('Name="Outputs"')
p.w('DisplayName="Outputs"')
p.w('Visible="False"')
p.w('IncludeInCommandLine="False" />')
p.w('IncludeInCommandLine="true" />')
p.pop()
end

Expand Down
11 changes: 11 additions & 0 deletions website/docs/Custom-Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ project "MyProject"
StripDebugInfo = true
}
```

## Rule Batching

With msbuild, custom rules can be batched if same properties are used. To enable this, use `rule.inputs` or `rule.outputs` tokens in `buildcommands`. If corresponding output is up-to-date to the input, then the input will be omitted.

```lua
rule "BatchRule"
fileextension ".xyz"
buildcommands 'MyProcessor.exe %{rule.inputs}'
```

0 comments on commit 0027213

Please sign in to comment.