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

Fix CMake toolchain template env corruption and abseil build regression #15786

Closed
wants to merge 2 commits into from

Conversation

mologie
Copy link

@mologie mologie commented Feb 29, 2024

This pull request changes Conan 2's CMakeToolchain to end in a new line by setting Jinja's keep_final_newline flag. This resolves #15785, where invalid CMake code was emitted.

Setting the flag as-is in the original code would however entirely break the CMake toolchain generation due to a silent corruption of Jinja environments caused by a usage error. The original code would make cmake_value available from blocks.py to toolchain.py by corrupting Jinja shared environments. The whole thing worked incidentally! Any Jinja improvement to make Jinja more robust against this usage error would have broken Conan. This refactors the code to fix the silent corruption and properly inherit cmake_value from toolchain.py into blocks.py.

It also adds a test to ensure that this does not regress again in future versions.

Changelog:

Docs: https://github.com/conan-io/docs/pull/XXXX

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

The cmake_value was incidentally available to CMakeToolchain, because
Jinja maintains a pool of environments based on Template constructor
arguments. It is forbidden to modify an environment fetched from such
a shared pool. blocks.py would accidentally inject into toolchain.py's
pool, which made the whole thing work since only toolchain.py uses the
cmake_value filter.
This fixes cross-compilation of abseil, which would append lines and
thus corrupt the last one. All text files should end in a new line,
hence fixing this in Conan itself.
@CLAassistant
Copy link

CLAassistant commented Feb 29, 2024

CLA assistant check
All committers have signed the CLA.

@mologie
Copy link
Author

mologie commented Feb 29, 2024

Please let me know if this needs a docs PR, I'm not sure about the process there. The docs repo doesn't seem to have any in-progress changes in develop, nor open PRs against the changelog.

@memsharded
Copy link
Member

Thanks very much for this contribution!

Closing as superseded by #15788

@memsharded memsharded closed this Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] regression where cross-compiling abseil generates invalid syntax in CMake toolchain file
3 participants