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

Implement env_info and user_info as fake attributes in Conan 2.0 so the error is not thrown #12351

Merged
merged 7 commits into from
Oct 24, 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
33 changes: 31 additions & 2 deletions conans/model/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from collections import OrderedDict

from conan.api.output import ConanOutput
from conans.errors import ConanException

_DIRS_VAR_NAMES = ["_includedirs", "_srcdirs", "_libdirs", "_resdirs", "_bindirs", "_builddirs",
Expand Down Expand Up @@ -30,6 +31,32 @@ def __copy__(self):
return the_copy


class MockInfoProperty(object):
"""
# TODO: Remove in 2.X
to mock user_info and env_info
"""
def __init__(self, name):
self._message = f"The use of '{name}' is deprecated in Conan 2.0 and will be removed in " \
f"Conan 2.X. Please, update your recipes unless you are maintaining " \
f"compatibility with Conan 1.X"

def __getitem__(self, key):
ConanOutput().warning(self._message)

def __setitem__(self, key, value):
ConanOutput().warning(self._message)

def __getattr__(self, attr):
if attr != "_message":
ConanOutput().warning(self._message)

def __setattr__(self, attr, value):
if attr != "_message":
ConanOutput().warning(self._message)
return super(MockInfoProperty, self).__setattr__(attr, value)


class _Component(object):

def __init__(self, set_defaults=False):
Expand Down Expand Up @@ -60,8 +87,10 @@ def __init__(self, set_defaults=False):
self._requires = None

# LEGACY 1.X fields, can be removed in 2.X
self.names = {}
self.filenames = {}
self.names = MockInfoProperty("cpp_info.names")
self.filenames = MockInfoProperty("cpp_info.filenames")
self.user_info = MockInfoProperty("cpp_info.user_info")
self.env_info = MockInfoProperty("cpp_info.env_info")

if set_defaults:
self.includedirs = ["include"]
Expand Down
9 changes: 9 additions & 0 deletions conans/test/integration/conan_v2/test_legacy_cpp_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def package_info(self):
self.cpp_info.names["cmake_find_package_multi"] = "absl"
self.cpp_info.filenames["cmake_find_package"] = "tensorflowlite"
self.cpp_info.filenames["cmake_find_package_multi"] = "tensorflowlite"

self.cpp_info.env_info.whatever = "whatever-env_info"
self.cpp_info.user_info.whatever = "whatever-user_info"
""")
c.save({"conanfile.py": conanfile})
c.run("create .")
message = "WARN: The use of '{}' is deprecated in Conan 2.0 and will be removed in " \
"Conan 2.X. Please, update your recipes unless you are maintaining compatibility " \
"with Conan 1.X"

for name in ["cpp_info.names", "cpp_info.filenames", "cpp_info.env_info", "cpp_info.user_info"]:
assert message.format(name) in c.out