-
Notifications
You must be signed in to change notification settings - Fork 991
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 handling of tools.build:defines
for (Ninja) multi-config CMake CMake (#15921)
#16637
Fix handling of tools.build:defines
for (Ninja) multi-config CMake CMake (#15921)
#16637
Conversation
541a208
to
ed1c66a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution @DenizThatMenace
It would be necessary first to contribute a test that shows that this change is necessary (red without the fix, green with the fix). Thanks!
Why do you need this, if you are clearly using wrong CMake syntax? |
To protect against future breaking of this change. If it is not covered by tests it can be broken at any time by a refactor, an update, other fixes... The only way to move these things forward is to have tests that cover the functionality. We always add tests or new checks for practically all of our PRs. |
It is not only good, it is fundamentally necessary for a project and a codebase like Conan to make sure things are properly covered by tests to avoid continuous regressions and problems.
Whatever someone else does in the codebase elsewhere is irrelevant if a test that captures the failing cases cover it, it will not be a problem, and possible regressions will be captured. We carefully check for test modifications and modifying the behavior of an existing test is an immediate red flag.
It is not necessary to know anything about the codebase to do a new test, and the test framework makes reproducing things very straightforward, just by copying and modifying a test like
def test_cmake_toolchain_cxxflags_multi_config():
c = TestClient()
profile_release = textwrap.dedent(r"""
include(default)
[conf]
tools.build:defines=["conan_test_answer=42", "conan_test_other=24"]
""")
profile_debug = textwrap.dedent(r"""
include(default)
[settings]
build_type=Debug
..
""")
conanfile = textwrap.dedent(r'''
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
class Test(ConanFile):
...
''')
main = textwrap.dedent(r"""
#include <iostream>
...
}
""")
cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(Test CXX)
add_executable(example src/main.cpp)
""")
c.save({"conanfile.py": conanfile,
"profile_release": profile_release,
"profile_debug": profile_debug,
"src/main.cpp": main,
"CMakeLists.txt": cmakelists}, clean_first=True)
c.run("install . -pr=./profile_release")
c.run("install . -pr=./profile_debug")
with c.chdir("build"):
c.run_command("cmake .. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake")
c.run_command("cmake --build . --config Release") In any case, don't worry, it is not a problem, we will try to contribute a test when possible. We tried before and we couldn't make it fail in a test, so it might take a while, hopefully we can reproduce in a test at some point. |
ed1c66a
to
762a614
Compare
It took me quite some time to figure it out, but I was able to install all test-requirements, run/debug tests and create a new one that can reproduce the error and which fails if my fix is missing. On a side-note: I do not understand how the tests can work with any CMake version. I had to locally modify my test to always use CMake 3.23.5 and create a symlink from To me the discovery of CMake looks totally broken. (But maybe I did something wrong?) |
The CMake generator-expressions that results from the values given to Conan's `tools.build:defines` configuration will now properly be put into quotes to form a CMake string. (Note: CMake's generator-expressions should never contain any (non-escaped) quotes.)
762a614
to
7fd9565
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job. I have managed to get the tests passing in the 3 platforms, they were initially failing because of some minor details in Linux/OSX (the cmake version), and some of the typical Windows stuff.
This can be moved forward, thanks for your contribution!
Regarding the tests and CMake configuration, it works via |
Changelog: Bugfix: Fix handling of
tools.build:defines
for Ninja Multi-Config CMake.Docs: Omit
Fixes: #15921
The CMake generator-expressions that results from the values given to Conan's
tools.build:defines
configuration will now properly be put into quotes to form a CMake string. (Note: CMake's generator-expressions should never contain any (non-escaped) quotes.)develop
branch, documenting this one.