Skip to content
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

CMake: Fix escaping of quotes in response file #15032

Merged
merged 1 commit into from
Sep 1, 2021

Conversation

LDong-Arm
Copy link
Contributor

@LDong-Arm LDong-Arm commented Aug 31, 2021

Summary of changes

We put macros in a response file compile_time_defs.txt and pass it to the compiler. Adding a pair of single quotes around each -D flag ensures macro values are quoted correctly.

For example,

  • String
    • In target_compile_definitions(): either FOO="BAR" or FOO=\"BAR\"
    • In generated response file: '-DFOO="BAR"'
    • Equivalent definition: #define FOO "BAR"
  • Array of integers
    • In target_compile_definitions(): FOO={1, 2, 3}
    • In generated response file: '-DFOO={1, 2, 3}'
    • Equivalent definition: #define FOO {1, 2, 3}

Impact of changes

Migration actions required

Documentation

None


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@LDong-Arm LDong-Arm added this to In progress (8) in Mbed Core via automation Aug 31, 2021
@LDong-Arm LDong-Arm requested review from ccli8 and a team August 31, 2021 10:40
@LDong-Arm LDong-Arm moved this from In progress (8) to Awaiting review (3) in Mbed Core Aug 31, 2021
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Aug 31, 2021
@ciarmcom
Copy link
Member

@LDong-Arm, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 31, 2021

Both compilers tested with macros like this? I recall there were issues alike macros but that could be other older issue we fixed.
CI will show it as we use macros like that in netsockets/mesh.

@LDong-Arm
Copy link
Contributor Author

Both compilers tested with macros like this? I recall there were issues alike macros but that could be other older issue we fixed.
CI will show it as we use macros like that in netsockets/mesh.

I will give netsocket/mesh a try later. If they work, we can run CI to test the change more rigorously.

Comment on lines -10 to +12
# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
# in the macro when retrieved using generator expressions causes linker errors.
# This includes string macros, array macros, and macros with operations.
# TODO CMake: Add escape sequences and quotation marks where necessary instead of removing these macros.
# Append -D to all macros and quote them as we pass these as response file to cxx compiler
set(_compile_definitions
"$<FILTER:${_compile_definitions},EXCLUDE, +>"
)

# Append -D to all macros as we pass these as response file to cxx compiler
set(_compile_definitions
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
"$<$<BOOL:${_compile_definitions}>:'-D$<JOIN:${_compile_definitions},' '-D>'>"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xc0170 I've tested it with sockets and mesh, both worked fine with both GCC_ARM and ARM compilers. And this also solves problems with macros with spaces inside (e.g. '-DMBED_CONF_LORA_APPLICATION_EUI={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}'), so I removed the previous workaround.

Hopefully it's a permanent fix, let's run CI to test it on more examples!

@mbed-ci
Copy link

mbed-ci commented Aug 31, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

Copy link
Contributor

@ccli8 ccli8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified with #15029

Mbed Core automation moved this from Awaiting review (3) to Reviewer approved & awaiting CI & merge (3) Sep 1, 2021
0xc0170
0xc0170 previously approved these changes Sep 1, 2021
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 1, 2021

We need to address today license check, I'll continue investigating with the test team

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 1, 2021

Please rebase to the latest master to get github workflow update to fix basic checks. I'll restart tests and this will go in.

We put macros in a response file compile_time_defs.txt and pass it
to the compiler. Adding a pair of single quotes around each -D flag
ensures macro values are quoted correctly.

For example,
* String
  * target_compile_definitions(): either FOO="BAR" or FOO=\"BAR\"
  * response file: '-DFOO="BAR"'
  * actual definition: #define FOO "BAR"
* Array of integers
  * target_compile_definitions(): FOO={1, 2, 3}
  * response file: '-DFOO={1, 2, 3}'
  * actual definition: #define FOO {1, 2, 3}
@mergify mergify bot dismissed 0xc0170’s stale review September 1, 2021 12:50

Pull request has been modified.

Mbed Core automation moved this from Reviewer approved & awaiting CI & merge (3) to Review in progress (4) Sep 1, 2021
@LDong-Arm
Copy link
Contributor Author

Rebased

Mbed Core automation moved this from Review in progress (4) to Reviewer approved & awaiting CI & merge (3) Sep 1, 2021
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 1, 2021

CI restarted

@mbed-ci
Copy link

mbed-ci commented Sep 1, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170 0xc0170 merged commit 79bc5ac into ARMmbed:master Sep 1, 2021
Mbed Core automation moved this from Reviewer approved & awaiting CI & merge (3) to Done Sep 1, 2021
@mergify mergify bot removed the ready for merge label Sep 1, 2021
@Patater Patater moved this from Done to Reported in Mbed Core Sep 10, 2021
@mbedmain mbedmain added release-version: 6.15.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Mbed Core
  
Reported
Development

Successfully merging this pull request may close these issues.

None yet

6 participants