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

full cmake_build_module editables functional test #17214

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion conans/model/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,12 @@ def merge_list(o, d):

if other._properties:
current_values = self.get_init("_properties", {})
current_values.update(other._properties)
for k, v in other._properties.items():
existing = current_values.get(k)
if existing is not None and isinstance(existing, list) and not overwrite:
existing.extend(v)
else:
current_values[k] = v

def set_relative_base_folder(self, folder):
for varname in _DIRS_VAR_NAMES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,82 @@ def package_info(self):
client.save({"CMakeLists.txt": cmakelists.replace("crypto", "#crypto")})
assert "ROOT MESSAGE:hello!" not in client.out


@pytest.mark.tool("cmake")
@pytest.mark.parametrize("editable", [True, False])
def test_build_modules_custom_script_editable(editable):
c = TestClient()
conanfile = textwrap.dedent(r"""
import os, glob
from conan import ConanFile
from conan.tools.files import copy, save

class Conan(ConanFile):
name = "myfunctions"
version = "1.0"
exports_sources = ["*.cmake"]

def build(self):
cmake = 'set(MY_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR})\n'\
'macro(otherfunc)\n'\
'file(READ "${MY_CMAKE_PATH}/my.txt" c)\n'\
'message("Hello ${c}!!!!")\nendmacro()'
save(self, "otherfuncs.cmake", cmake)
save(self, "my.txt", "contents of text file!!!!")

def layout(self):
self.folders.source = "my_sources"
self.folders.build = "my_build"
src = glob.glob(os.path.join(self.recipe_folder, self.folders.source, "*.cmake"))
build = glob.glob(os.path.join(self.recipe_folder, self.folders.build, "*.cmake"))
self.cpp.source.set_property("cmake_build_modules", src)
self.cpp.build.set_property("cmake_build_modules", build)

def package(self):
copy(self, "*.cmake", self.source_folder, os.path.join(self.package_folder, "mods"))
copy(self, "*.cmake", self.build_folder, os.path.join(self.package_folder, "mods"))
copy(self, "*.txt", self.build_folder, os.path.join(self.package_folder, "mods"))

def package_info(self):
self.cpp_info.set_property("cmake_build_modules", glob.glob("mods/*.cmake"))
""")

myfunction = textwrap.dedent("""
function(myfunction)
message("Hello myfunction!!!!")
endfunction()
""")

consumer = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMake

class Conan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"
requires = "myfunctions/1.0"

def build(self):
cmake = CMake(self)
cmake.configure()
""")
cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(test)
find_package(myfunctions CONFIG REQUIRED)
myfunction()
otherfunc()
""")
c.save({"functions/conanfile.py": conanfile,
"functions/my_sources/myfunction.cmake": myfunction,
"app/conanfile.py": consumer,
"app/CMakeLists.txt": cmakelists})

if editable:
c.run("editable add functions")
c.run("build functions")
else:
c.run("create functions")
c.run("build app")
assert "Hello myfunction!!!!" in c.out
assert "Hello contents of text file!!!!" in c.out