Skip to content

Commit

Permalink
Changes for develop2
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote committed Jun 17, 2022
2 parents 0f636a1 + e2e63ae commit 79ae5ff
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 50 deletions.
19 changes: 8 additions & 11 deletions conans/model/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __copy__(self):

class _Component(object):

def __init__(self):
def __init__(self, set_defaults=False):
# ###### PROPERTIES
self._generator_properties = None

Expand Down Expand Up @@ -61,6 +61,11 @@ def __init__(self):
self.names = {}
self.filenames = {}

if set_defaults:
self.includedirs = ["include"]
self.libdirs = ["lib"]
self.bindirs = ["bin"]

def serialize(self):
return {
"includedirs": self._includedirs,
Expand Down Expand Up @@ -295,17 +300,9 @@ def get_init(self, attribute, default):
class CppInfo(object):

def __init__(self, set_defaults=False):
self.components = DefaultOrderedDict(lambda: _Component())
self.components = DefaultOrderedDict(lambda: _Component(set_defaults))
# Main package is a component with None key
self.components[None] = _Component()
if set_defaults:
self.includedirs = ["include"]
self.libdirs = ["lib"]
self.resdirs = ["res"]
self.bindirs = ["bin"]
self.builddirs = []
self.frameworkdirs = []

self.components[None] = _Component(set_defaults)
self._aggregated = None # A _NewComponent object with all the components aggregated

def __getattr__(self, attr):
Expand Down
2 changes: 2 additions & 0 deletions conans/test/functional/layout/test_editables_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def build(self):
assert "**FOO includedirs:['package_include_foo']**" in out
assert "**FOO libdirs:['lib']**" in out # The components does have default dirs
assert "**FOO builddirs:[]**" in out # The components don't have default dirs for builddirs

assert "**FOO libs:['lib_when_package_foo', 'lib_when_package2_foo']**" in out
assert "**FOO objects:['myobject.o']**" in out
assert "**FOO build_modules:['mymodules/mybuildmodule']**" in out
Expand All @@ -228,6 +229,7 @@ def build(self):
assert "**VAR includedirs:['package_include_var']**" in out
assert "**VAR libdirs:['lib']**" in out # The components does have default dirs
assert "**VAR builddirs:[]**" in out # The components don't have default dirs

assert "**VAR libs:['lib_when_package_var', 'lib_when_package2_var']**" in out
assert "**VAR cxxflags:['my_cxx_flag2_var']**" in out
assert "**VAR cflags:['my_c_flag_var']**" in out
Expand Down
6 changes: 3 additions & 3 deletions conans/test/functional/layout/test_layout_autopackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ def layout(self):
assert el.components["foo"].srcdirs == []
assert el.components["foo"].resdirs == []
assert self.cpp.package.components["foo"].includedirs == []
assert self.cpp.package.components["foo"].libdirs == []
assert self.cpp.package.components["foo"].bindirs == []
assert self.cpp.package.components["foo"].includedirs == ["include"]
assert self.cpp.package.components["foo"].libdirs == ["lib"]
assert self.cpp.package.components["foo"].bindirs == ["bin"]
assert self.cpp.package.components["foo"].frameworkdirs == []
assert self.cpp.package.components["foo"].srcdirs == []
assert self.cpp.package.components["foo"].resdirs == []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def build(self):
autotools.autoreconf()
autotools.configure()
autotools.make()
""")

client.save({"conanfile.py": conanfile,
Expand Down
58 changes: 22 additions & 36 deletions conans/test/integration/command/create_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import textwrap
import unittest
import pytest

import pytest

Expand Down Expand Up @@ -654,8 +653,8 @@ def package_info(self):
'pkg_config_name': 'pkg_other_name'}
# component info
assert pkg_cpp_info['cmp1']["libs"] == ['libcmp1']
assert pkg_cpp_info['cmp1']["bindirs"] is None
assert pkg_cpp_info['cmp1']["libdirs"] is None
assert pkg_cpp_info['cmp1']["bindirs"][0].endswith("bin") # Abs path /bin
assert pkg_cpp_info['cmp1']["libdirs"][0].endswith("lib") # Abs path /lib
assert pkg_cpp_info['cmp1']["sysroot"] == "/another/sysroot"
assert pkg_cpp_info['cmp1']["properties"] == {'pkg_config_aliases': ['compo1_alias'],
'pkg_config_name': 'compo1'}
Expand Down Expand Up @@ -700,10 +699,10 @@ def package_info(self):
assert "FRAMEWORKS: []" in client.out


import pytest
import re
@pytest.mark.parametrize("with_layout", [True, False])
def test_defaults_in_components_without_layout(with_layout):
def test_defaults_in_components(with_layout):
"""In Conan 2, declaring or not the layout has no influence in how cpp_info behaves. It was
only 1.X"""
lib_conan_file = textwrap.dedent("""
from conan import ConanFile
Expand Down Expand Up @@ -736,19 +735,15 @@ def layout(self):
pass
def generate(self):
if hasattr(self, "layout"):
cppinfo = self.dependencies["lib"].cpp_info
else:
cppinfo = dict(self.deps_cpp_info.dependencies)["lib"]
cppinfo = self.dependencies["lib"].cpp_info
components = cppinfo.components
self.output.warn("BINDIRS: {}".format(cppinfo.bindirs))
self.output.warn("LIBDIRS: {}".format(cppinfo.libdirs))
self.output.warn("INCLUDEDIRS: {}".format(cppinfo.includedirs))
self.output.warn("RESDIRS: {}".format(cppinfo.resdirs))
self.output.warn("FOO LIBDIRS: {}".format(components["foo"].libdirs))
self.output.warn("FOO INCLUDEDIRS: {}".format(components["foo"].includedirs))
self.output.warn("FOO RESDIRS: {}".format(components["foo"].resdirs))
self.output.warning("BINDIRS: {}".format(cppinfo.bindirs))
self.output.warning("LIBDIRS: {}".format(cppinfo.libdirs))
self.output.warning("INCLUDEDIRS: {}".format(cppinfo.includedirs))
self.output.warning("RESDIRS: {}".format(cppinfo.resdirs))
self.output.warning("FOO LIBDIRS: {}".format(components["foo"].libdirs))
self.output.warning("FOO INCLUDEDIRS: {}".format(components["foo"].includedirs))
self.output.warning("FOO RESDIRS: {}".format(components["foo"].resdirs))
""")

Expand All @@ -758,21 +753,12 @@ def generate(self):
client.save({"conanfile.py": consumer_conanfile})
client.run("create . ")

if with_layout:
# The paths are absolute and the components have defaults
# ".+" Check that there is a path, not only "lib"
assert re.search("BINDIRS: \['.+bin'\]", str(client.out))
assert re.search("LIBDIRS: \['.+lib'\]", str(client.out))
assert re.search("INCLUDEDIRS: \['.+include'\]", str(client.out))
assert "WARN: RES DIRS: []"
assert bool(re.search("WARN: FOO LIBDIRS: \['.+lib'\]", str(client.out))) is with_layout
assert bool(re.search("WARN: FOO INCLUDEDIRS: \['.+include'\]", str(client.out))) is with_layout
assert "WARN: FOO RESDIRS: []" in client.out
else:
# The paths are not absolute and the components have defaults
assert "BINDIRS: ['bin']" in client.out
assert "LIBDIRS: ['lib']" in client.out
assert "INCLUDEDIRS: ['include']" in client.out
assert "FOO LIBDIRS: ['lib']" in client.out
assert "FOO INCLUDEDIRS: ['include']" in client.out
assert "FOO RESDIRS: ['res']" in client.out
# The paths are absolute and the components have defaults
# ".+" Check that there is a path, not only "lib"
assert re.search("BINDIRS: \['.+bin'\]", str(client.out))
assert re.search("LIBDIRS: \['.+lib'\]", str(client.out))
assert re.search("INCLUDEDIRS: \['.+include'\]", str(client.out))
assert "WARN: RES DIRS: []"
assert re.search("WARN: FOO LIBDIRS: \['.+lib'\]", str(client.out))
assert re.search("WARN: FOO INCLUDEDIRS: \['.+include'\]", str(client.out))
assert "WARN: FOO RESDIRS: []" in client.out

0 comments on commit 79ae5ff

Please sign in to comment.