-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make CppInfo an importable tool (#14101)
* make CppInfo an importable tool * load/save
- Loading branch information
1 parent
64e20c4
commit 5ad2216
Showing
5 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from conans.model.build_info import CppInfo as _CppInfo | ||
|
||
|
||
def CppInfo(conanfile): | ||
# Creation of a CppInfo object, to decouple the creation from the actual internal location | ||
# that at the moment doesn't require a ``conanfile`` argument, but might require in the future | ||
# and allow us to refactor the location of conans.model.build_info import CppInfo | ||
return _CppInfo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
conans/test/integration/conanfile/test_cpp_info_serialize.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
import textwrap | ||
|
||
from conans.test.utils.tools import TestClient | ||
|
||
|
||
def test_cpp_info_serialize_round_trip(): | ||
""" test that serialize and deserialize CppInfo works | ||
""" | ||
# TODO: Define standard name for file | ||
c = TestClient() | ||
conanfile = textwrap.dedent("""\ | ||
import os | ||
from conan import ConanFile | ||
from conan.tools import CppInfo | ||
class Pkg(ConanFile): | ||
name = "pkg" | ||
version = "0.1" | ||
def package(self): | ||
cpp_info = CppInfo(self) | ||
cpp_info.includedirs = ["myinc"] | ||
cpp_info.libs = ["mylib", "myother"] | ||
cpp_info.libdirs = ["mylibs"] | ||
p = os.path.join(self.package_folder, "cpp_info.json") | ||
cpp_info.save(p) | ||
def package_info(self): | ||
cpp_info = CppInfo(self).load("cpp_info.json") | ||
self.cpp_info = cpp_info | ||
""") | ||
|
||
c.save({"conanfile.py": conanfile}) | ||
c.run("create . --format=json") | ||
graph = json.loads(c.stdout) | ||
cpp_info = graph["graph"]["nodes"]["1"]["cpp_info"]["root"] | ||
assert cpp_info["includedirs"][0].endswith("myinc") | ||
assert cpp_info["libdirs"][0].endswith("mylibs") | ||
assert cpp_info["libs"] == ["mylib", "myother"] |