Skip to content

Commit

Permalink
[cpp_info] [refact] Do not assign to 'xxxx_paths' fields (conan-io#7276)
Browse files Browse the repository at this point in the history
* use get_configs instead of config

* fixing tests

* fix tests

* fix tests

* move pkg_config logic to cpp_info so everyone uses the same

* 'name' from cpp_info needs the generator it is requested for

* configs is a private dict now

* revert change in init

* add test for Conan v2 behavior

* deps_cpp_info['deps'].name warns to use get_name instead

* use cpp_info properly

* compare as lists (convert possible iterables to lists)

* set legit values in cpp_info

* readonly fields expected to be iterable (not nessessaryly lists)

* remove print statement from test

* let any iterable type in

* revert test changes

* use property 'configs' to retrieve the different configs

* check type for cpp_info/deps_cpp_info objects

* just a list
  • Loading branch information
jgsogo authored Jul 15, 2020
1 parent 1ed9b25 commit 8eabf18
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 158 deletions.
18 changes: 9 additions & 9 deletions conans/client/build/autotools_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False):

# Set the generic objects before mapping to env vars to let the user
# alter some value
self.libs = copy.copy(self._deps_cpp_info.libs)
self.libs.extend(copy.copy(self._deps_cpp_info.system_libs))
self.include_paths = copy.copy(self._deps_cpp_info.include_paths)
self.library_paths = copy.copy(self._deps_cpp_info.lib_paths)
self.libs = list(self._deps_cpp_info.libs)
self.libs.extend(list(self._deps_cpp_info.system_libs))
self.include_paths = list(self._deps_cpp_info.include_paths)
self.library_paths = list(self._deps_cpp_info.lib_paths)

self.defines = self._configure_defines()
# Will go to CFLAGS and CXXFLAGS ["-m64" "-m32", "-g", "-s"]
Expand Down Expand Up @@ -249,8 +249,8 @@ def install(self, args="", make_program=None, vars=None):

def _configure_link_flags(self):
"""Not the -L"""
ret = copy.copy(self._deps_cpp_info.sharedlinkflags)
ret.extend(self._deps_cpp_info.exelinkflags)
ret = list(self._deps_cpp_info.sharedlinkflags)
ret.extend(list(self._deps_cpp_info.exelinkflags))
ret.extend(format_frameworks(self._deps_cpp_info.frameworks, self._conanfile.settings))
ret.extend(format_framework_paths(self._deps_cpp_info.framework_paths, self._conanfile.settings))
arch_flag = architecture_flag(self._conanfile.settings)
Expand All @@ -272,7 +272,7 @@ def _configure_link_flags(self):
return ret

def _configure_flags(self):
ret = copy.copy(self._deps_cpp_info.cflags)
ret = list(self._deps_cpp_info.cflags)
arch_flag = architecture_flag(self._conanfile.settings)
if arch_flag:
ret.append(arch_flag)
Expand All @@ -291,15 +291,15 @@ def _configure_flags(self):
return ret

def _configure_cxx_flags(self):
ret = copy.copy(self._deps_cpp_info.cxxflags)
ret = list(self._deps_cpp_info.cxxflags)
cxxf = libcxx_flag(self._conanfile.settings)
if cxxf:
ret.append(cxxf)
return ret

def _configure_defines(self):
# requires declared defines
ret = copy.copy(self._deps_cpp_info.defines)
ret = list(self._deps_cpp_info.defines)

# Debug definition for GCC
btf = build_type_define(build_type=self._build_type)
Expand Down
1 change: 0 additions & 1 deletion conans/test/functional/command/test_package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def wrong_version_test(self):
client.save({CONANFILE: GenConanfile().with_name("Hello").with_version("0.1"),
"test_package/conanfile.py": test_conanfile})
client.run("create . user/channel")
print(client.out)
self.assertNotIn("Hello/0.2", client.out)

def other_requirements_test(self):
Expand Down
12 changes: 6 additions & 6 deletions conans/test/functional/cross_building/graph/protobuf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_crossbuilding(self):
self.assertEqual(protobuf_host_cpp_info.bindirs, ['protobuf-host'])
protobuf_host_cpp_info = app.conanfile.deps_cpp_info["zlib"]
self.assertEqual(protobuf_host_cpp_info.libs, ['zlib-host-1.0'])
self.assertEqual(app.conanfile.deps_cpp_info.libs, ['protobuf-host', 'zlib-host-1.0'])
self.assertListEqual(list(app.conanfile.deps_cpp_info.libs), ['protobuf-host', 'zlib-host-1.0'])

# - app::deps_env_info
protobuf_env_info = app.conanfile.deps_env_info["protobuf"]
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_crossbuilding_with_build_require_cmake(self):
self.assertEqual(protobuf_host_cpp_info.bindirs, ['protobuf-host'])
zlib_host_cpp_info = app.conanfile.deps_cpp_info["zlib"]
self.assertEqual(zlib_host_cpp_info.libs, ['zlib-host-1.0'])
self.assertEqual(app.conanfile.deps_cpp_info.libs, ['protobuf-host', 'zlib-host-1.0'])
self.assertListEqual(list(app.conanfile.deps_cpp_info.libs), ['protobuf-host', 'zlib-host-1.0'])

# - app::deps_env_info
protobuf_env_info = app.conanfile.deps_env_info["protobuf"]
Expand All @@ -200,7 +200,7 @@ def test_crossbuilding_with_build_require_cmake(self):
# - protobuf::deps_cpp_info
zlib_cpp_info = protobuf_host.conanfile.deps_cpp_info["zlib"]
self.assertEqual(zlib_cpp_info.libs, ['zlib-host-1.0'])
self.assertEqual(protobuf_host.conanfile.deps_cpp_info.libs, ['zlib-host-1.0'])
self.assertListEqual(list(protobuf_host.conanfile.deps_cpp_info.libs), ['zlib-host-1.0'])

# - protobuf::deps_env_info (no zlib)
zlib_env_info = list(protobuf_host.conanfile.deps_env_info.deps)
Expand All @@ -212,7 +212,7 @@ def test_crossbuilding_with_build_require_cmake(self):
self.assertEqual(zlib_host.conanfile.name, "zlib")
self.assertEqual(zlib_host.context, CONTEXT_HOST)
self.assertEqual(zlib_host.conanfile.settings.os, profile_host.settings['os'])
self.assertEqual(zlib_host.conanfile.deps_cpp_info.libs, [])
self.assertListEqual(list(zlib_host.conanfile.deps_cpp_info.libs), [])
self.assertEqual(zlib_host.conanfile.deps_env_info.vars["PATH"], ['cmake_build', 'bzip-build-3.0'])

# Check BUILD packages
Expand All @@ -224,8 +224,8 @@ def test_crossbuilding_with_build_require_cmake(self):

# - protobuf::deps_cpp_info
zlib_cpp_info = protobuf_build.conanfile.deps_cpp_info["zlib"]
self.assertEqual(zlib_cpp_info.libs, ['zlib-build-2.0'])
self.assertEqual(protobuf_build.conanfile.deps_cpp_info.libs, ['zlib-build-2.0'])
self.assertListEqual(list(zlib_cpp_info.libs), ['zlib-build-2.0'])
self.assertListEqual(list(protobuf_build.conanfile.deps_cpp_info.libs), ['zlib-build-2.0'])

# - protobuf::deps_env_info (no zlib)
zlib_env_info = list(protobuf_build.conanfile.deps_env_info.deps)
Expand Down
2 changes: 1 addition & 1 deletion conans/test/functional/graph/diamond_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _run(self, use_cmake=True, cmake_targets=False, language=0):
content = content.replace("def build(self):",
"def build(self):\n"
" self.output.info('INCLUDE %s' "
"% self.deps_cpp_info['Hello0'].include_paths)")
"% list(self.deps_cpp_info['Hello0'].include_paths))")
files3[CONANFILE] = content
self.client.save(files3)

Expand Down
4 changes: 2 additions & 2 deletions conans/test/functional/graph/graph_manager_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _put_in_cache(self, ref, conanfile):
def alias_cache(self, alias, target):
ref = ConanFileReference.loads(alias)
conanfile = textwrap.dedent("""
from conans import ConanFile
from conans import ConanFile
class Alias(ConanFile):
alias = "%s"
""" % target)
Expand Down Expand Up @@ -166,6 +166,6 @@ def _check_node(self, node, ref, deps=None, build_deps=None, dependents=None, cl
for n in closure:
libs.append("mylib%s%slib" % (n.ref.name, n.ref.version))
envs.append("myenv%s%senv" % (n.ref.name, n.ref.version))
self.assertEqual(conanfile.deps_cpp_info.libs, libs)
self.assertListEqual(list(conanfile.deps_cpp_info.libs), libs)
env = {"MYENV": envs} if envs else {}
self.assertEqual(conanfile.deps_env_info.vars, env)
4 changes: 2 additions & 2 deletions conans/test/functional/graph/graph_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ def test_build_require_link_order(self):

self._check_node(cheetah, "cheetah/0.1@", deps=[gazelle], build_deps=[grass2],
dependents=[], closure=[gazelle, grass])
self.assertEqual(cheetah.conanfile.deps_cpp_info.libs,
['mylibgazelle0.1lib', 'mylibgrass0.1lib'])
self.assertListEqual(list(cheetah.conanfile.deps_cpp_info.libs),
['mylibgazelle0.1lib', 'mylibgrass0.1lib'])

@parameterized.expand([(True, ), (False, )])
def test_dont_skip_private(self, private_first):
Expand Down
69 changes: 34 additions & 35 deletions conans/test/integration/package_info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ class Consumer(ConanFile):
requires = "intermediate/1.0@us/ch"
def build(self):
self.output.info("System deps: %s" % self.deps_cpp_info.system_libs)
self.output.info("System deps: %s" % list(self.deps_cpp_info.system_libs))
for dep_key, dep_value in self.deps_cpp_info.dependencies:
self.output.info("%s system deps: %s" % (dep_key, dep_value.system_libs))
self.output.info("%s system deps: %s" % (dep_key, list(dep_value.system_libs)))
""")

client = TestClient()
Expand Down Expand Up @@ -174,13 +174,13 @@ class Consumer(ConanFile):
requires = "intermediate/1.0@us/ch"
def build(self):
self.output.info("deps_cpp_info.libs: %s" % self.deps_cpp_info.libs)
self.output.info("deps_cpp_info.defines: %s" % self.deps_cpp_info.defines)
self.output.info("deps_cpp_info.libs: %s" % list(self.deps_cpp_info.libs))
self.output.info("deps_cpp_info.defines: %s" % list(self.deps_cpp_info.defines))
self.output.info("deps_cpp_info.include_paths: %s" %
[os.path.basename(value) for value in self.deps_cpp_info.include_paths])
for dep_key, dep_value in self.deps_cpp_info.dependencies:
self.output.info("%s.libs: %s" % (dep_key, dep_value.libs))
self.output.info("%s.defines: %s" % (dep_key, dep_value.defines))
self.output.info("%s.libs: %s" % (dep_key, list(dep_value.libs)))
self.output.info("%s.defines: %s" % (dep_key, list(dep_value.defines)))
self.output.info("%s.include_paths: %s" % (dep_key,
[os.path.basename(value) for value in
dep_value.include_paths]))
Expand Down Expand Up @@ -281,30 +281,29 @@ class Consumer(ConanFile):
requires = "dep/1.0@us/ch"
def build(self):
# Global values
self.output.info("GLOBAL Include paths: %s" % self.deps_cpp_info.include_paths)
self.output.info("GLOBAL Library paths: %s" % self.deps_cpp_info.lib_paths)
self.output.info("GLOBAL Binary paths: %s" % self.deps_cpp_info.bin_paths)
self.output.info("GLOBAL Libs: %s" % self.deps_cpp_info.libs)
self.output.info("GLOBAL Exes: %s" % self.deps_cpp_info.exes)
self.output.info("GLOBAL System libs: %s" % self.deps_cpp_info.system_libs)
self.output.info("GLOBAL Include paths: %s" % list(self.deps_cpp_info.include_paths))
self.output.info("GLOBAL Library paths: %s" % list(self.deps_cpp_info.lib_paths))
self.output.info("GLOBAL Binary paths: %s" % list(self.deps_cpp_info.bin_paths))
self.output.info("GLOBAL Libs: %s" % list(self.deps_cpp_info.libs))
self.output.info("GLOBAL System libs: %s" % list(self.deps_cpp_info.system_libs))
# Deps values
for dep_key, dep_value in self.deps_cpp_info.dependencies:
self.output.info("DEPS name: %s" % dep_value.get_name('txt'))
self.output.info("DEPS Include paths: %s" % dep_value.include_paths)
self.output.info("DEPS Library paths: %s" % dep_value.lib_paths)
self.output.info("DEPS Binary paths: %s" % dep_value.bin_paths)
self.output.info("DEPS Libs: %s" % dep_value.libs)
self.output.info("DEPS System libs: %s" % dep_value.system_libs)
self.output.info("DEPS Include paths: %s" % list(dep_value.include_paths))
self.output.info("DEPS Library paths: %s" % list(dep_value.lib_paths))
self.output.info("DEPS Binary paths: %s" % list(dep_value.bin_paths))
self.output.info("DEPS Libs: %s" % list(dep_value.libs))
self.output.info("DEPS System libs: %s" % list(dep_value.system_libs))
# Components values
for dep_key, dep_value in self.deps_cpp_info.dependencies:
for comp_name, comp_value in dep_value.components.items():
self.output.info("COMP %s Include paths: %s" % (comp_name,
comp_value.include_paths))
self.output.info("COMP %s Library paths: %s" % (comp_name, comp_value.lib_paths))
self.output.info("COMP %s Binary paths: %s" % (comp_name, comp_value.bin_paths))
self.output.info("COMP %s Libs: %s" % (comp_name, comp_value.libs))
self.output.info("COMP %s Requires: %s" % (comp_name, comp_value.requires))
self.output.info("COMP %s System libs: %s" % (comp_name, comp_value.system_libs))
list(comp_value.include_paths)))
self.output.info("COMP %s Library paths: %s" % (comp_name, list(comp_value.lib_paths)))
self.output.info("COMP %s Binary paths: %s" % (comp_name, list(comp_value.bin_paths)))
self.output.info("COMP %s Libs: %s" % (comp_name, list(comp_value.libs)))
self.output.info("COMP %s Requires: %s" % (comp_name, list(comp_value.requires)))
self.output.info("COMP %s System libs: %s" % (comp_name, list(comp_value.system_libs)))
""")

client = TestClient()
Expand Down Expand Up @@ -354,25 +353,25 @@ def build(self):
self.assertIn("DEPS Libs: ['libplanet', 'libiss', 'libstarlight']", client.out)
self.assertIn("DEPS System libs: ['solar', 'magnetism', 'ground']", client.out)

self.assertIn("COMP Starlight Include paths: %s" % expected_comp_starlight_include_paths,
self.assertIn("COMP Starlight Include paths: %s" % list(expected_comp_starlight_include_paths),
client.out)
self.assertIn("COMP Planet Include paths: %s" % expected_comp_planet_include_paths,
self.assertIn("COMP Planet Include paths: %s" % list(expected_comp_planet_include_paths,),
client.out)
self.assertIn("COMP Launcher Include paths: %s" % expected_comp_launcher_include_paths,
self.assertIn("COMP Launcher Include paths: %s" % list(expected_comp_launcher_include_paths),
client.out)
self.assertIn("COMP ISS Include paths: %s" % expected_comp_iss_include_paths, client.out)
self.assertIn("COMP Starlight Library paths: %s" % expected_comp_starlight_library_paths,
self.assertIn("COMP ISS Include paths: %s" % list(expected_comp_iss_include_paths), client.out)
self.assertIn("COMP Starlight Library paths: %s" % list(expected_comp_starlight_library_paths),
client.out)
self.assertIn("COMP Planet Library paths: %s" % expected_comp_planet_library_paths,
self.assertIn("COMP Planet Library paths: %s" % list(expected_comp_planet_library_paths),
client.out)
self.assertIn("COMP Launcher Library paths: %s" % expected_comp_launcher_library_paths,
self.assertIn("COMP Launcher Library paths: %s" % list(expected_comp_launcher_library_paths),
client.out)
self.assertIn("COMP ISS Library paths: %s" % expected_comp_iss_library_paths, client.out)
self.assertIn("COMP Starlight Binary paths: %s" % expected_comp_iss_binary_paths, client.out)
self.assertIn("COMP Planet Binary paths: %s" % expected_comp_planet_binary_paths, client.out)
self.assertIn("COMP Launcher Binary paths: %s" % expected_comp_launcher_binary_paths,
self.assertIn("COMP ISS Library paths: %s" % list(expected_comp_iss_library_paths), client.out)
self.assertIn("COMP Starlight Binary paths: %s" % list(expected_comp_iss_binary_paths), client.out)
self.assertIn("COMP Planet Binary paths: %s" % list(expected_comp_planet_binary_paths), client.out)
self.assertIn("COMP Launcher Binary paths: %s" % list(expected_comp_launcher_binary_paths),
client.out)
self.assertIn("COMP ISS Binary paths: %s" % expected_comp_iss_binary_paths, client.out)
self.assertIn("COMP ISS Binary paths: %s" % list(expected_comp_iss_binary_paths), client.out)
self.assertIn("COMP Starlight Libs: ['libstarlight']", client.out)
self.assertIn("COMP Planet Libs: ['libplanet']", client.out)
self.assertIn("COMP Launcher Libs: []", client.out)
Expand Down
28 changes: 17 additions & 11 deletions conans/test/unittests/client/generators/b2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from conans.client.conf import get_default_settings_yml
from conans.client.generators.b2 import B2Generator
from conans.model.build_info import CppInfo
from conans.model.build_info import CppInfo, DepsCppInfo
from conans.model.conan_file import ConanFile
from conans.model.env_info import EnvValues
from conans.model.ref import ConanFileReference
Expand Down Expand Up @@ -43,9 +43,11 @@ def b2_test(self):
cpp_info.sharedlinkflags = ["-sharedlinkflag"]
cpp_info.cxxflags = ["-cxxflag"]
cpp_info.public_deps = ["MyPkg"]
cpp_info.lib_paths.extend(["Path\\with\\slashes", "regular/path/to/dir"])
cpp_info.include_paths.extend(["other\\Path\\with\\slashes", "other/regular/path/to/dir"])
cpp_info.libdirs.extend(["Path\\with\\slashes", "regular/path/to/dir"])
cpp_info.includedirs.extend(["other\\Path\\with\\slashes", "other/regular/path/to/dir"])
cpp_info.filter_empty = False
conanfile.deps_cpp_info.add(ref.name, cpp_info)

generator = B2Generator(conanfile)

content = {
Expand Down Expand Up @@ -189,13 +191,15 @@ def b2_empty_settings_test(self):
;
constant-if includedirs(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
"other/Path/with/slashes"
"other/regular/path/to/dir"
"dummy_root_folder2/include"
"dummy_root_folder2/other/Path/with/slashes"
"dummy_root_folder2/other/regular/path/to/dir"
;
constant-if libdirs(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
"Path/with/slashes"
"regular/path/to/dir"
"dummy_root_folder2/lib"
"dummy_root_folder2/Path/with/slashes"
"dummy_root_folder2/regular/path/to/dir"
;
constant-if defines(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
Expand Down Expand Up @@ -274,13 +278,15 @@ def b2_empty_settings_test(self):
;
constant-if includedirs(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
"other/Path/with/slashes"
"other/regular/path/to/dir"
"dummy_root_folder2/include"
"dummy_root_folder2/other/Path/with/slashes"
"dummy_root_folder2/other/regular/path/to/dir"
;
constant-if libdirs(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
"Path/with/slashes"
"regular/path/to/dir"
"dummy_root_folder2/lib"
"dummy_root_folder2/Path/with/slashes"
"dummy_root_folder2/regular/path/to/dir"
;
constant-if defines(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
Expand Down
Loading

0 comments on commit 8eabf18

Please sign in to comment.