Skip to content

Commit

Permalink
CPS config merge
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored and franramirez688 committed Oct 3, 2024
1 parent 7a35b62 commit 70f0eb4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
24 changes: 23 additions & 1 deletion conan/cps/cps.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ def from_cpp_info(cpp_info, pkg_type, libname=None):
cps_comp.requires = [f":{c}" if "::" not in c else c.replace("::", ":") for c in required]
return cps_comp

def update(self, conf, conf_def):
# TODO: conf not used at the moent
self.location = self.location or conf_def.get("location")
self.link_location = self.link_location or conf_def.get("link_location")
self.link_libraries = self.link_libraries or conf_def.get("link_libraries")


class CPS:
""" represents the CPS file for 1 package
Expand Down Expand Up @@ -299,4 +305,20 @@ def save(self, folder):
@staticmethod
def load(file):
contents = load(file)
return CPS.deserialize(json.loads(contents))
print("BASE FILE", contents)
base = CPS.deserialize(json.loads(contents))

path, name = os.path.split(file)
basename, ext = os.path.splitext(name)
for conf in "release", "debug":
full_conf = os.path.join(path, f"{basename}@{conf}{ext}")
if os.path.exists(full_conf):
conf_content = json.loads(load(full_conf))
print("CONF FILE", conf, json.dumps(conf_content, indent=2))
for comp, comp_def in conf_content.get("components", {}).items():
existing = base.components.get(comp)
if existing:
existing.update(conf, comp_def)
else:
base.components[comp] = comp_def
return base
37 changes: 37 additions & 0 deletions test/integration/cps/test_cps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import os
import textwrap

from conan.cps import CPS
from conan.test.assets.genconanfile import GenConanfile
from conan.test.utils.test_files import temp_folder
from conan.test.utils.tools import TestClient
from conans.util.files import save_files


def test_cps():
Expand Down Expand Up @@ -117,3 +120,37 @@ def package_info(self):
assert 'set(zlib_INCLUDE_DIRS_RELEASE "${zlib_PACKAGE_FOLDER_RELEASE}/include")' in cmake
assert 'set(zlib_LIB_DIRS_RELEASE "${zlib_PACKAGE_FOLDER_RELEASE}/lib")'
assert 'set(zlib_LIBS_RELEASE zlib)' in cmake


def test_cps_merge():
folder = temp_folder()
cps_base = textwrap.dedent("""
{
"components" : {
"mypkg" : {
"includes" : [ "@prefix@/include" ],
"type" : "archive"
}
},
"cps_version" : "0.12.0",
"name" : "mypkg",
"version" : "1.0"
}
""")
cps_conf = textwrap.dedent("""
{
"components" : {
"mypkg" : {
"link_languages" : [ "cpp" ],
"location" : "@prefix@/lib/mypkg.lib"
}
},
"configuration" : "Release",
"name" : "mypkg"
}
""")
save_files(folder, {"mypkg.cps": cps_base,
"[email protected]": cps_conf})
cps = CPS.load(os.path.join(folder, "mypkg.cps"))
json_cps = cps.serialize()
print(json.dumps(json_cps, indent=2))

0 comments on commit 70f0eb4

Please sign in to comment.