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

[bugfix] Bad legacy cpp_info if layout is used #11790

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions conans/client/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ def _call_package_info(self, conanfile, package_folder, ref, is_editable):
# Old cpp info without defaults (the defaults are in the new one)
conanfile.cpp_info = CppInfo(conanfile.name, package_folder,
default_values=CppInfoDefaultValues())
# Note: Remember that this is not needed for Conan 2.x
# Let's avoid losing this information.
conanfile.cpp_info.version = conanfile.version
conanfile.cpp_info.description = conanfile.description
conanfile.cpp_info.public_deps = public_deps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was easier/cleaner than changing the CppInfo class.


if not is_editable:
# Copy the infos.package into the old cppinfo
fill_old_cppinfo(conanfile.cpp.package, conanfile.cpp_info)
Expand Down
4 changes: 2 additions & 2 deletions conans/test/integration/generators/json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_generate_json_info(self):

class HelloConan(ConanFile):
exports_sources = "*.h"
description = "foo"
description = "my desc"
def layout(self):
pass
def package(self):
Expand All @@ -30,7 +30,7 @@ def package_info(self):
conan_json = client.load("conanbuildinfo.json")
data = json.loads(conan_json)
self.assertEqual(data["dependencies"][0]["version"], "0.1")
self.assertIsNone(data["dependencies"][0]["description"])
self.assertEqual(data["dependencies"][0]["description"], "my desc")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I'm missing something but we weren't saving the description before those changes.

self.assertEqual(data["deps_env_info"]["MY_ENV_VAR"], "foo")
self.assertEqual(data["deps_user_info"]["Hello"]["my_var"], "my_value")

Expand Down
36 changes: 36 additions & 0 deletions conans/test/integration/layout/test_legacy_cpp_info_and_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import textwrap

import pytest

from conans.test.utils.tools import TestClient


# TODO: This test does not make sense for Conan v2. Please, remove/skip it in that case.
@pytest.mark.parametrize("declare_layout", [True, False])
def test_legacy_deps_cpp_info_deps_version_using_or_not_layout(declare_layout):
conanfile = textwrap.dedent("""
from conan import ConanFile

class HelloConan(ConanFile):
name = "hello"
version = "1.0"
{}
def package_info(self):
self.cpp_info.libs = ["hello"]
""".format("def layout(self):pass" if declare_layout else ""))
test_conanfile = textwrap.dedent("""
from conan import ConanFile

class HelloTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"

def build(self):
self.output.info(self.deps_cpp_info["hello"].version)

def test(self):
pass
""")
client = TestClient()
client.save({"conanfile.py": conanfile, "test_package/conanfile.py": test_conanfile})
client.run("create .")
assert "hello/1.0 (test package): 1.0" in client.out