Skip to content

Commit

Permalink
Merge branch 'develop2' into release/2.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
czoido committed Jun 17, 2022
2 parents cfbef3b + 854f082 commit dfe6b12
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 43 deletions.
2 changes: 1 addition & 1 deletion conan/tools/gnu/autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _get_argument(argument_name, cppinfo_name):
_get_argument("includedir", "includedirs"),
_get_argument("oldincludedir", "includedirs"),
_get_argument("datarootdir", "resdirs")])
return configure_install_flags
return [el for el in configure_install_flags if el]

def _default_autoreconf_flags(self):
return ["--force", "--install"]
Expand Down
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
22 changes: 16 additions & 6 deletions conans/model/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,41 @@ def unrelated_mode(self):
def semver_mode(self):
self.name = self._ref.name
self.version = _VersionRepr(self._ref.version).stable()
self.user = self.channel = self.package_id = None
self.user = self._ref.user
self.channel = self._ref.channel
self.package_id = None
self.recipe_revision = None

def full_version_mode(self):
self.name = self._ref.name
self.version = self._ref.version
self.user = self.channel = self.package_id = None
self.user = self._ref.user
self.channel = self._ref.channel
self.package_id = None
self.recipe_revision = None

def patch_mode(self):
self.name = self._ref.name
self.version = _VersionRepr(self._ref.version).patch()
self.user = self.channel = self.package_id = None
self.user = self._ref.user
self.channel = self._ref.channel
self.package_id = None
self.recipe_revision = None

def minor_mode(self):
self.name = self._ref.name
self.version = _VersionRepr(self._ref.version).minor()
self.user = self.channel = self.package_id = None
self.user = self._ref.user
self.channel = self._ref.channel
self.package_id = None
self.recipe_revision = None

def major_mode(self):
self.name = self._ref.name
self.version = _VersionRepr(self._ref.version).major()
self.user = self.channel = self.package_id = None
self.user = self._ref.user
self.channel = self._ref.channel
self.package_id = None
self.recipe_revision = None

def full_recipe_mode(self):
Expand Down Expand Up @@ -406,7 +416,7 @@ def package_id(self):
package_id = sha1(text.encode())
return package_id

def header_only(self):
def clear(self):
self.settings.clear()
self.options.clear()
self.requires.clear()
Expand Down
4 changes: 2 additions & 2 deletions conans/test/functional/graph/test_graph_build_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def build_all():


foo_id = "efa83b160a55b033c4ea706ddb980cd708e3ba1b"
bar_id = "8dcbed6f1d74e477e5cb4c720cabe6c391d59ea0"
foobar_id = "a9ec6bebb0b06aa725ce41bcc07555b5a0630796"
bar_id = "7d0bb2b97d4339b0d3ded1418a2593f35b9cf267"
foobar_id = "af8f885f621ba7baac3f5b1d2c18cfdf5ba2550c"


def check_if_build_from_sources(refs_modes, output):
Expand Down
8 changes: 5 additions & 3 deletions conans/test/functional/layout/test_editables_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,19 @@ def build(self):

out = str(client2.out).replace(r"\\", "/").replace(package_folder, "")
assert "**FOO includedirs:['package_include_foo']**" in out
assert "**FOO libdirs:[]**" in out # The components don't have default dirs
assert "**FOO builddirs:[]**" in out # The components don't have default dirs
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
assert "**FOO cxxflags:['my_cxx_flag2_foo']**" in out
assert "**FOO cflags:['my_c_flag_foo']**" in out

assert "**VAR includedirs:['package_include_var']**" in out
assert "**VAR libdirs:[]**" in out # The components don't have default dirs
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 @@ -89,7 +89,7 @@ class HeaderOnly(ConanFile):
{% endif %}
def package_id(self):
self.info.header_only()
self.info.clear()
def package_info(self):
self.cpp_info.includedirs = []
Expand Down
4 changes: 4 additions & 0 deletions conans/test/functional/toolchains/gnu/autotools/test_ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ class TestConan(ConanFile):
exports_sources = "configure.ac", "Makefile.am", "main.cpp"
generators = "AutotoolsToolchain", "AutotoolsDeps"
def layout(self):
self.cpp.package.resdirs = ["res"]
def build(self):
autotools = Autotools(self)
autotools.autoreconf()
autotools.configure()
autotools.make()
""")

client.save({"conanfile.py": conanfile,
Expand Down
70 changes: 68 additions & 2 deletions conans/test/integration/command/create_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import re
import textwrap
import unittest

Expand Down Expand Up @@ -652,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 @@ -696,3 +697,68 @@ def package_info(self):
client.save({"conanfile.py": conanfile})
client.run("create .")
assert "FRAMEWORKS: []" in client.out


@pytest.mark.parametrize("with_layout", [True, False])
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
class LibConan(ConanFile):
name = "lib"
version = "1.0"
def layout(self):
pass
def package_info(self):
self.cpp_info.components["foo"].libs = ["foolib"]
""")
if not with_layout:
lib_conan_file = lib_conan_file.replace("def layout(", "def potato(")
client = TestClient()
client.save({"conanfile.py": lib_conan_file})
client.run("create . ")

consumer_conanfile = textwrap.dedent("""
from conan import ConanFile
class Consumer(ConanFile):
name = "consumer"
version = "1.0"
requires = "lib/1.0"
def layout(self):
pass
def generate(self):
cppinfo = self.dependencies["lib"].cpp_info
components = cppinfo.components
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))
""")

if not with_layout:
consumer_conanfile = consumer_conanfile.replace("def layout(", "def potato(")

client.save({"conanfile.py": consumer_conanfile})
client.run("create . ")

# 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
2 changes: 1 addition & 1 deletion conans/test/integration/conanfile/test_attributes_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_info_not_in_package(self):
class Recipe(ConanFile):
def package(self):
self.info.header_only()
self.info.clear()
""")
t.save({'conanfile.py': conanfile})
t.run('create . --name=name --version=version -s os=Linux', assert_error=True)
Expand Down
2 changes: 1 addition & 1 deletion conans/test/integration/graph/core/test_provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def configure(self):
self.provides = 'libjpeg'
def package_info(self):
self.info.header_only()
self.info.clear()
""")
t = TestClient()
t.save({'requires.py': GenConanfile("req", "v1").with_provides("libjpeg"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_version_full_version_schema(self):
# but will look for the same package_id
self.client.run("install .", assert_error=True)
self.assertIn("ERROR: Missing binary: "
"hello2/2.3.8@lasote/stable:f25bd0cc2b8eec83e11ca16e79f4e43539cd93b9",
"hello2/2.3.8@lasote/stable:971e20f31a0d8deb18f03a0f8f72fd95623a8e29",
self.client.out)

# Now change the Hello version and build it, if we install out requires is
Expand Down Expand Up @@ -248,17 +248,17 @@ def test_package_id_requires_patch_mode(self):
self._export("libd", "0.1.0", channel=channel, package_id_text=None,
requires=["libc/0.1.0@user/testing"])
self.client.run("create . --name=libd --version=0.1.0 --user=user --channel=testing", assert_error=True)
package_id_missing = "c4e90f390819b782c27ad290de6727acbcbc76bd"
package_id_missing = "18e1a54bf351cd291da5a01ef545ce338243285f"
self.assertIn(f"""ERROR: Missing binary: libc/0.1.0@user/testing:{package_id_missing}
libc/0.1.0@user/testing: WARN: Can't find a 'libc/0.1.0@user/testing' package binary '{package_id_missing}' for the configuration:
[options]
an_option=off
[requires]
liba/0.1.0
libb/0.1.0
libbar/0.1.0
libfoo/0.1.0""", self.client.out)
liba/0.1.0@user/testing
libb/0.1.0@user/testing
libbar/0.1.0@user/testing
libfoo/0.1.0@user/testing""", self.client.out)


class PackageIDErrorTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class SumConan(ConanFile):
def build(self):
self.output.warning("My compiler is '{}'".format(self.settings.compiler))
def package_id(self):
self.info.header_only()
self.info.clear()
""")

client = TestClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_transitive_second_level_header_only(self):
client.run("create . --name=libb --version=1.0")
# libC -> libB

unrelated = "self.info.header_only()"
unrelated = "self.info.clear()"
client.save({"conanfile.py": GenConanfile().with_require("libb/1.0")
.with_package_id(unrelated)})
client.run("create . --name=libc --version=1.0")
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_transitive_header_only(self):
client.run("create . --name=liba --version=1.0")
client.run("create . --name=liba --version=2.0")
client.save({"conanfile.py": GenConanfile().with_require("liba/1.0")
.with_package_id("self.info.header_only()")})
.with_package_id("self.info.clear()")})
client.run("create . --name=libb --version=1.0")
client.save({"conanfile.py": GenConanfile().with_require("libb/1.0")})
client.run("create . --name=libc --version=1.0")
Expand Down
3 changes: 1 addition & 2 deletions conans/test/integration/py_requires/python_requires_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re
import textwrap
import time
import unittest
Expand Down Expand Up @@ -728,7 +727,7 @@ def build(self):
"python_requires2/1.0@user/test": "Cache"}, python=True)
# - packages
client.assert_listed_binary({"project/1.0@user/test":
("1d71f9c410465b607aaf217320808237e019989f", "Build")})
("257a966344bb19ae8ef0c208eff085952902e25f", "Build")})

# - no mention to alias
self.assertNotIn("alias", client.out)
Expand Down
2 changes: 1 addition & 1 deletion conans/test/unittests/model/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_modes(self):
shared=False
'''
info = ConanInfo.loads(info_text)
info.header_only()
info.clear()
self.assertEqual(info.settings.dumps(), "")
self.assertEqual(info.options.dumps(), "")
self.assertEqual(info.requires.dumps(), "")
Expand Down

0 comments on commit dfe6b12

Please sign in to comment.