premake-core
premake-core copied to clipboard
Should gmake2 actually escape spaces?
What's your question?
Currently, gmake2 escapes spaces in arguments to buildcommands. For an example, look at test_gmake2_file_rules.lua
:
function suite.propertydefinitionSeparator()
rules { "TestRule" }
files { "test.rule", "test2.rule", "test3.rule", "test4.rule" }
filter "files:test.rule"
testRuleVars {
TestListProperty = { "testValue1", "testValue2" }
}
filter "files:test2.rule"
testRuleVars {
TestListPropertyWithSwitch = { "testValue1", "testValue2" }
}
...
prepare()
test.capture [[
# File Rules
# #############################################
test.obj: test.rule
@echo Rule-ing test.rule
$(SILENT) dorule testValue1\ testValue2 "test.rule"
test2.obj: test2.rule
@echo Rule-ing test2.rule
$(SILENT) dorule -StestValue1\ -StestValue2 "test2.rule"
...
]]
end
This makes it so lists/strings, if contain spaces, are escaped, and -StestValue1\ -StestValue2
becomes a single argument: -S"testValue1 -StestValue2"
. Is this intended? Perhaps, it should not be like that? Or, shouldnt it be atleast customizable? So i.e. if you dont want it to be escaped, you just place a flag in the property definition.
Consider a case:
You have a property definition for compiler defines that needs to be split into individual arguments:
-D define1 value1 -D define2 value2
I would personally create a list of definitions, something like { "define1 value1", "define2 value2" }
,
but that would not work, because it would translate into something like -D define1\ value1\ -D define2\ value2
.
For defines specifically, we don't really support setting define values at the current time, just setting if the define exists or not. There is processing done on defines for each platform, as we'd need to format them correctly for gmake2, VS, etc. Supporting defines with values would definitely add a bit of complexity to that, and I'm not 100% convinced that "name value" would be the best approach at this time.
In the general, I think you raise a good point on if we need to do a \
on each space, or if that only makes sense in the cases where there is a space in the value list, etc. This is something that I'm just not 100% sure on.
Is this behavior something that is causing you issues currently?
For defines specifically, we don't really support setting define values at the current time, just setting if the define exists or not. There is processing done on defines for each platform, as we'd need to format them correctly for gmake2, VS, etc. Supporting defines with values would definitely add a bit of complexity to that, and I'm not 100% convinced that "name value" would be the best approach at this time.
In the general, I think you raise a good point on if we need to do a \
on each space, or if that only makes sense in the cases where there is a space in the value list, etc. This is something that I'm just not 100% sure on.
Is this behavior something that is causing you issues currently?
It did, but i solved this using something very hacky - just removing the backslashes in tokens.
Which behavior did it solve? Defines?
Yes
Right now, that's not a use case we support. Let's narrow scope on this and figure out how to solve that specific use case for a feature request.
I also encountered the same problem when trying to add indentation customization.
Here is some context:
I am using premake to generate makefiles for lua compilation using Reuh/candran, it has an indentation option that is defined by spaces. I.e. --indentation " "
. I could not use spaces in there, so i had to do another hack using (" "):rep(...)
Right now, that's not a use case we support. Let's narrow scope on this and figure out how to solve that specific use case for a feature request.
Sure, its not that big of a deal anyways
Okay, after some brain storming, I've come up with a few options:
Option 1: No support of defines and setting their values (current)
Option 2:
defines ( {
'name:value',
'name:value with space'
} )
In the GMake2 exporter, we'd get the following flags:
-Dname=value
-Dname=value\ with\ space
Thoughts?
Hmm, this seems rather good But here is another problem: what if you want to have different defines for different types of files? And how would you define in a rule that it does support defines? And how would you then use it in the buildcommands?
Defines for different types of files are supported with filters (assuming the toolchain supports it). That said, I'm curious, does this work for defines currently?
defines( {
'name=value',
'name=value with spaces'
} )
For defines
, I already opened #1521 for space/quote/other special char (especially as behavior differ between premake4 and premake5).
For rules
and switch
, my testing project also has avoid space (whereas using space might make sense). So for me value should not be escaped, (can still be surrounded by quote).
For list, it seems strange to escape space IMO.
And it should be coherent for all generators, not specific to gmake2 ;-)
That issue is a throwback. I'll take a look through it, because I don't remember what we discussed there.