Skip to content

Should gmake2 actually escape spaces? #1941

@artemking4

Description

@artemking4

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.

Activity

nickclark2016

nickclark2016 commented on Sep 4, 2022

@nickclark2016
Member

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?

nickclark2016

nickclark2016 commented on Sep 4, 2022

@nickclark2016
Member

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?

artemking4

artemking4 commented on Sep 4, 2022

@artemking4
Author

It did, but i solved this using something very hacky - just removing the backslashes in tokens.

nickclark2016

nickclark2016 commented on Sep 4, 2022

@nickclark2016
Member

Which behavior did it solve? Defines?

artemking4

artemking4 commented on Sep 4, 2022

@artemking4
Author

Yes

nickclark2016

nickclark2016 commented on Sep 4, 2022

@nickclark2016
Member

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.

artemking4

artemking4 commented on Sep 4, 2022

@artemking4
Author

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(...)

artemking4

artemking4 commented on Sep 4, 2022

@artemking4
Author

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

nickclark2016

nickclark2016 commented on Sep 4, 2022

@nickclark2016
Member

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?

artemking4

artemking4 commented on Sep 4, 2022

@artemking4
Author

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?

nickclark2016

nickclark2016 commented on Sep 6, 2022

@nickclark2016
Member

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'
} )
Jarod42

Jarod42 commented on Sep 6, 2022

@Jarod42
Contributor

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 ;-)

nickclark2016

nickclark2016 commented on Sep 6, 2022

@nickclark2016
Member

That issue is a throwback. I'll take a look through it, because I don't remember what we discussed there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Jarod42@nickclark2016@artemking4

        Issue actions