Skip to content

Commit

Permalink
Implement env_info and user_info as fake attributes in Conan 2.0 …
Browse files Browse the repository at this point in the history
…so the error is not thrown (#12351)

* fake env properties

* minor changes

* add warning

* fix

* review

* fix format

* remove imports
  • Loading branch information
czoido authored Oct 24, 2022
1 parent 5977581 commit 1eb274a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
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

0 comments on commit 1eb274a

Please sign in to comment.