Skip to content

Commit

Permalink
allow self.name/self.version for build_folder_vars (#15705)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Feb 28, 2024
1 parent ee22708 commit 0d09f6b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conan/tools/cmake/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def get_build_folder_custom_vars(conanfile):
tmp = "shared" if value else "static"
else:
tmp = "{}_{}".format(var, value)
elif group == "self":
tmp = getattr(conanfile, var, None)
else:
raise ConanException("Invalid 'tools.cmake.cmake_layout:build_folder_vars' value, it has"
" to start with 'settings.' or 'options.': {}".format(s))
Expand Down
46 changes: 46 additions & 0 deletions conans/test/integration/toolchains/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,52 @@ def layout(self):
assert "conan-windows-shared-debug" in presets


def test_build_folder_vars_self_name_version():
client = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import cmake_layout
class Conan(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "build_type"
generators = "CMakeToolchain"
def layout(self):
self.folders.build_folder_vars = ["settings.os", "self.name", "self.version"]
cmake_layout(self)
""")
client.save({"conanfile.py": conanfile})
client.run("install . -s os=Windows -s build_type=Debug")
presets = client.load("build/windows-pkg-0.1/Debug/generators/CMakePresets.json")
assert "conan-windows-pkg-0.1-debug" in presets
client.run("install . -s os=Linux -s build_type=Release")
presets = client.load("build/linux-pkg-0.1/Release/generators/CMakePresets.json")
assert "linux-pkg-0.1-release" in presets

# CLI override has priority
client.run("install . -s os=Linux -s build_type=Release "
"-c tools.cmake.cmake_layout:build_folder_vars='[\"self.name\"]'")
presets = client.load("build/pkg/Release/generators/CMakePresets.json")
assert "conan-pkg-release" in presets

# Now we do the build in the cache, the recipe folders are still used
client.run("create . -s os=Windows -s build_type=Debug")
build_folder = client.created_layout().build()
presets = load(os.path.join(build_folder,
"build/windows-pkg-0.1/Debug/generators/CMakePresets.json"))
assert "conan-windows-pkg-0.1-debug" in presets

# If we change the conf ``build_folder_vars``, it doesn't affect the cache build
client.run("create . -s os=Windows -s build_type=Debug "
"-c tools.cmake.cmake_layout:build_folder_vars='[\"settings.os\"]'")
build_folder = client.created_layout().build()
presets = load(os.path.join(build_folder,
"build/windows-pkg-0.1/Debug/generators/CMakePresets.json"))
assert "conan-windows-pkg-0.1-debug" in presets


def test_extra_flags():
client = TestClient()
conanfile = textwrap.dedent("""
Expand Down

0 comments on commit 0d09f6b

Please sign in to comment.