-
-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable msbuild batching for custom rules #2141
base: master
Are you sure you want to change the base?
Conversation
add `rule.inputs` and `rule.outputs` pathVars add test cases add documentation
website/docs/Custom-Rules.md
Outdated
|
||
## 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Rename msbuild
to MSBuild
modules/gmake2/_preload.lua
Outdated
|
||
pathVars = { | ||
["rule.inputs"] = { absolute = false, token = "$<" }, | ||
["rule.outputs"] = { absolute = false, token = "$@" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For non-msbuild environments like gmake2 or codelite, these tokens will be substituted as single input and output as there're no batching.
What would be the value without pathVars
? (i.e for gmake/xcode/external modules)
Does they need update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those tokens are only valid in buildcommands
in custom rule context.
For built-in modules it seems like gmake2, codelite and vs are only modules support custom rules.
However I do think it's better to have fallback for any modules. I was thinking of using fcfg_mt
for fallback and name tokens something like file.ruleinputs
/file.ruleoutputs
. Does that make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom rules are indeed not supported by gmake and xcode.
Some external module such as codeblocks/ninja does support it.
How is rule.outputs
"concatenated"? with space? (and $@
$<
may probably be removed).
(first token which is an array...)
rule.inputs
is a little more complex, Does it include %{file.relpath}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in VS modules,
rule.inputs
is space-concatenated file.relpath
s for the batch. (Same as item included in .vcxproject
)
rule.outputs
is space-concatenated path.normalize(buildoutputs)
s for the batch. (Same as outputs defined in .targets
)
@@ -72,3 +72,14 @@ project "MyProject" | |||
StripDebugInfo = true | |||
} | |||
``` | |||
|
|||
## Rule Batching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those tokens should also go in Tokens.md IMO.
So I went with I excluded output list token for now, as it's bit complex to get value and users probably can deduce it from inputs. Also docs are updated as reviewed. |
Unclear for me what it means... What do you mean by "can be batched and built incrementally"? |
I'll give brief example. When you have custom rule, rule 'MyCustomRule'
fileextensions { '.txt' }
buildcommands { 'echo %{file.ruleinputs}' } -- using new ruleinputs token Without batching msbuild will invoke each command per file separately.
When batching is possible, msbuild can invoke command as a whole. (Incremental just means that if only a.txt changed only
This can boost performance for the commands that have long startup time or use shared resorces. |
OK, so your code is a shorthand for: rule "myrule"
--location(LocationDir)
--display "My custom rule"
fileextension ".txt"
-- propertydefinition { .. }
-- buildinputs { "%{file.relpath}.in" } -- Possible extra inputs
-- buildoutputs { path.join(LocationDir, "%{file.basename}.out") } -- All outputs
if "vs2000" <= _ACTION and _ACTION <= "vs3000" then -- Batch only handled by vs*
buildmessage 'custom rule: [Inputs]'
buildcommands { "MyCommand [Inputs]" }
else
buildmessage 'custom rule: %{file.relpath}'
buildcommands { "MyCommand %{file.relpath}" }
end
-- above if-block replaced by
-- buildmessage 'custom rule: %{file.ruleinputs}'
-- buildcommands { "MyCommand %{file.ruleinputs}" }
Wonder if a flag |
Yes pretty much.
I agree that
I think it is better to be separate token, since even if there is flag, many tokens can break batch if MSBuild can't detect common pattern. |
Do you mind pushing an empty commit just to get the actions to trigger? I think I'm good to merge it, assuming all tests pass. |
What does this PR do?
This PR lets users to write custom rules compatible with msbuild batching. By providing
@(Rule)
as input and@(Rule->'%(Output)')
as output, msbuild can recognize this task can be batched and built incrementally.How does this PR change Premake's behavior?
Existing rules should be unaffected because the behavior should be same when using tokens like
${file.relpath}
since properties like%(Identity)
or%(FullPath)
breaks batching.To enable batching, user should write command with newly added tokens
%{rule.inputs}
or%{rule.outputs}
which mapped to string list. For non-msbuild environments likegmake2
orcodelite
, these tokens will be substituted as single input and output as there're no batching.Anything else we should know?
Let me know if introducing new tokens is undesirable.
Did you check all the boxes?
closes #XXXX
in comment to auto-close issue when PR is merged)You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!