Skip to content

Commit 590df5b

Browse files
authored
Enable msbuild batching for custom rules (#2141)
* Enable msbuild batching for custom rules add `rule.inputs` and `rule.outputs` pathVars add test cases add documentation * renaming token to `file.ruleinputs`, excluding outputs for now.
1 parent 57efe5b commit 590df5b

File tree

7 files changed

+93
-3
lines changed

7 files changed

+93
-3
lines changed

modules/vstudio/tests/vc2010/test_rule_props.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
'%{output_path}%{file.basename}.example.cc',
3939
'%{output_path}%{file.basename}.example.h'
4040
}
41+
builddependencies {
42+
'dependency_1.lib',
43+
'dependency_2.lib',
44+
}
4145
end
4246

4347

@@ -68,3 +72,16 @@
6872
]]
6973
end
7074

75+
76+
--
77+
-- additionalDependencies
78+
--
79+
80+
function suite.additionalDependencies()
81+
local r = test.getRule("example")
82+
m.additionalDependencies(r)
83+
84+
test.capture [[
85+
<AdditionalDependencies>dependency_1.lib;dependency_2.lib</AdditionalDependencies>
86+
]]
87+
end

modules/vstudio/tests/vc2010/test_rule_targets.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,55 @@
9595
</UsingTask>
9696
]]
9797
end
98+
99+
100+
101+
--
102+
-- ruleTask
103+
--
104+
105+
function suite.ruleTask()
106+
local r = test.getRule("example")
107+
m.rule(r)
108+
109+
test.capture [[
110+
<example
111+
Condition="'@(example)' != '' and '%(example.ExcludedFromBuild)' != 'true'"
112+
CommandLineTemplate="%(example.CommandLineTemplate)"
113+
output_path="%(example.output_path)"
114+
AdditionalOptions="%(example.AdditionalOptions)"
115+
Inputs="@(example)"
116+
StandardOutputImportance="High"
117+
StandardErrorImportance="High" />
118+
]]
119+
end
120+
121+
122+
123+
--
124+
-- targetInputs
125+
--
126+
127+
function suite.targetInputs()
128+
local r = test.getRule("example")
129+
m.targetInputs(r)
130+
131+
test.capture [[
132+
Inputs="@(example);%(example.AdditionalDependencies);$(MSBuildProjectFile)"
133+
]]
134+
end
135+
136+
137+
138+
--
139+
-- targetOutputs
140+
--
141+
142+
function suite.targetOutputs()
143+
local r = test.getRule("example")
144+
m.targetOutputs(r)
145+
146+
test.capture [[
147+
Outputs="@(example->'%(Outputs)')"
148+
]]
149+
end

modules/vstudio/vs2010.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
["file.reldirectory"] = { absolute = false, token = "%(RelativeDir)" },
3737
["file.extension"] = { absolute = false, token = "%(Extension)" },
3838
["file.name"] = { absolute = false, token = "%(Filename)%(Extension)" },
39+
["file.ruleinputs"] = { absolute = false, token = "[Inputs]" },
3940
}
4041

4142

modules/vstudio/vs2010_rules_targets.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294

295295

296296
function m.inputs(r)
297-
p.w('Inputs="%%(%s.Identity)"', r.name)
297+
p.w('Inputs="@(%s)"', r.name)
298298
end
299299

300300

@@ -410,7 +410,7 @@
410410
end
411411
end
412412
extra = table.concat(extra)
413-
p.w('Inputs="%%(%s.Identity);%%(%s.AdditionalDependencies);%s$(MSBuildProjectFile)"', r.name, r.name, extra)
413+
p.w('Inputs="@(%s);%%(%s.AdditionalDependencies);%s$(MSBuildProjectFile)"', r.name, r.name, extra)
414414
end
415415

416416

@@ -422,7 +422,7 @@
422422

423423

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

428428

src/base/fileconfig.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,11 @@
298298
function fcfg_mt.extension(fcfg)
299299
return path.getextension(fcfg.abspath)
300300
end
301+
302+
303+
function fcfg_mt.ruleinputs(fcfg)
304+
-- fallback for batch rule inputs
305+
return fcfg.relpath
306+
end
307+
308+

website/docs/Custom-Rules.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ project "MyProject"
7272
StripDebugInfo = true
7373
}
7474
```
75+
76+
## Rule Batching
77+
78+
With MSBuild, custom rules can be batched if same properties are used. To enable this, use `file.ruleinputs` tokens in `buildcommands`. If corresponding `buildoutputs` is up-to-date to the input, then the input will be omitted. This token falls back to `file.relpath` on unsupported environment.
79+
80+
```lua
81+
rule "BatchRule"
82+
fileextension ".xyz"
83+
buildcommands "MyProcessor.exe %{file.ruleinputs}"
84+
```
85+

website/docs/Tokens.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ file.reldirectory
5454
file.name
5555
file.basename -- (file part without extension)
5656
file.extension -- (including '.'; eg ".cpp")
57+
file.ruleinputs -- (see custom rules)
5758

5859
-- These values are available on build and link targets
5960
-- Replace [target] with one of "cfg.buildtarget" or "cfg.linktarget"

0 commit comments

Comments
 (0)