Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the > character in define values was not being escaped for use inside CMake generator expressions. CMake generator expressions (like $<$<COMPILE_LANGUAGE:C,CXX>:...>) interpret unescaped > as a closing delimiter, causing broken output such as -D> -DRANDOM_CONFIG_FILE="\"<random_config.h\"". The fix replaces > with $<ANGLE-R> in ListCompileDefinitions. The PR also updates a broken GolangCI-Lint installation URL in DEVELOPING.md.
Changes:
- Replace
>with$<ANGLE-R>in define values withinListCompileDefinitionsto correctly escape the character inside CMake generator expressions. - Add a unit test for the
>escaping behavior inbuildcontent_test.go. - Update the GolangCI-Lint installation URL in
DEVELOPING.mdto the current path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
pkg/maker/buildcontent.go |
Adds strings.ReplaceAll to escape > as $<ANGLE-R> in define values |
pkg/maker/buildcontent_test.go |
Adds test verifying > characters are escaped to $<ANGLE-R> |
DEVELOPING.md |
Updates GolangCI-Lint install URL to the new documentation path |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -308,6 +308,7 @@ func ListCompileDefinitions(defines []interface{}, delimiter string) string { | |||
| key, value := utils.GetDefine(define) | |||
| pair := key | |||
| if len(value) > 0 { | |||
There was a problem hiding this comment.
The fix only escapes > but not <. According to the CMake generator expression documentation, < inside a generator expression value would be interpreted as the start of a nested generator expression (e.g., $< introduces one). The original issue example uses RANDOM_CONFIG_FILE: \"<random_config.h>\" — the < in <random_config.h> would also cause problems inside $<$<COMPILE_LANGUAGE:C,CXX>:...>. CMake provides $<ANGLE-L> as the escape for <, analogous to $<ANGLE-R> for >. Both characters should be escaped to correctly handle defines like RANDOM_CONFIG_FILE="<random_config.h>".
A second ReplaceAll call should be added to replace < with $<ANGLE-L> before the existing > replacement (since $<ANGLE-R> itself contains >, the order matters: replace < first, then replace >).
| if len(value) > 0 { | |
| if len(value) > 0 { | |
| value = strings.ReplaceAll(value, "<", "$<ANGLE-L>") |
| map[string]interface{}{"FOO": "A>B>C"}, | ||
| } | ||
| assert.Equal("FOO=A$<ANGLE-R>B$<ANGLE-R>C", maker.ListCompileDefinitions(defines, ";")) | ||
| }) |
There was a problem hiding this comment.
The test only covers the > escaping case. Since < should also be escaped (as $<ANGLE-L>) inside CMake generator expressions, a test case for < escaping (and ideally combined <..> like the original issue's \"<random_config.h>\") should also be included to match the fix and provide regression coverage.
| }) | |
| }) | |
| t.Run("test escape left angle bracket", func(t *testing.T) { | |
| defines := []interface{}{ | |
| map[string]interface{}{"FOO": "A<B<C"}, | |
| } | |
| assert.Equal("FOO=A$<ANGLE-L>B$<ANGLE-L>C", maker.ListCompileDefinitions(defines, ";")) | |
| }) | |
| t.Run("test escape include style angle brackets", func(t *testing.T) { | |
| defines := []interface{}{ | |
| map[string]interface{}{"INCLUDE": "\"<random_config.h>\""}, | |
| } | |
| assert.Equal("INCLUDE=\"$<ANGLE-L>random_config.h$<ANGLE-R>\"", maker.ListCompileDefinitions(defines, ";")) | |
| }) |
Fixes
>is not escaped in generator expressions #211Changes
>by$<ANGLE-R>Checklist