def test_fill_old_cppinfo():
    """The source/build have priority unless it is not declared at all"""
    source = NewCppInfo()
    source.libdirs = ["source_libdir"]
    source.cxxflags = ["source_cxxflags"]
    build = NewCppInfo()
    build.libdirs = ["build_libdir"]
    build.frameworkdirs = [
    ]  # An empty list is an explicit delaration with priority too
    build.set_property("cmake_build_modules", ["my_cmake.cmake"])
    build.builddirs = ["my_build"]

    old_cpp = CppInfo("lib/1.0", "/root/folder")
    old_cpp.filter_empty = False
    old_cpp.libdirs = ["package_libdir"]
    old_cpp.cxxflags = ["package_cxxflags"]
    old_cpp.cflags = ["package_cflags"]
    old_cpp.frameworkdirs = ["package_frameworks"]

    full_editables = NewCppInfo()
    full_editables.merge(source)
    full_editables.merge(build)

    fill_old_cppinfo(full_editables, old_cpp)
    assert [e.replace("\\", "/") for e in old_cpp.lib_paths] == \
           ["/root/folder/source_libdir", "/root/folder/build_libdir"]
    assert old_cpp.cxxflags == ["source_cxxflags"]
    assert old_cpp.cflags == ["package_cflags"]
    assert old_cpp.frameworkdirs == []
    assert old_cpp.get_property("cmake_build_modules")
    assert old_cpp.builddirs == ["my_build"]
def test_fill_old_cppinfo_simple():
    """ The previous test but simpler, just with one cppinfo simulating the package layout"""
    package_info = NewCppInfo()
    package_info.libs = []  # This is explicit declaration too
    package_info.includedirs = ["other_include"]

    old_cpp = CppInfo("lib/1.0", "/root/folder")
    old_cpp.filter_empty = False
    old_cpp.libs = ["this_is_discarded"]
    old_cpp.libdirs = ["package_libdir"]
    old_cpp.cxxflags = ["package_cxxflags"]
    old_cpp.cflags = ["package_cflags"]
    old_cpp.frameworkdirs = ["package_frameworks"]

    fill_old_cppinfo(package_info, old_cpp)
    assert [e.replace("\\", "/") for e in old_cpp.lib_paths] == \
           ["/root/folder/package_libdir"]
    assert old_cpp.cxxflags == ["package_cxxflags"]
    assert old_cpp.cflags == ["package_cflags"]
    assert old_cpp.frameworkdirs == ["package_frameworks"]
    assert old_cpp.libs == []
    assert old_cpp.includedirs == ["other_include"]
Beispiel #3
0
    def _call_package_info(self, conanfile, package_folder, ref, is_editable):
        conanfile.cpp_info = CppInfo(conanfile.name, package_folder)
        conanfile.cpp_info.version = conanfile.version
        conanfile.cpp_info.description = conanfile.description

        conanfile.env_info = EnvInfo()
        conanfile.user_info = UserInfo()

        # Get deps_cpp_info from upstream nodes
        public_deps = [
            name for name, req in conanfile.requires.items()
            if not req.private and not req.override
        ]
        conanfile.cpp_info.public_deps = public_deps
        # Once the node is build, execute package info, so it has access to the
        # package folder and artifacts
        # Minimal pythonpath, not the whole context, make it 50% slower
        # FIXME Conan 2.0, Remove old ways of reusing python code
        with pythonpath(conanfile):
            with tools.chdir(package_folder):
                with conanfile_exception_formatter(str(conanfile),
                                                   "package_info"):
                    self._hook_manager.execute("pre_package_info",
                                               conanfile=conanfile,
                                               reference=ref)
                    if hasattr(conanfile, "layout"):
                        # Old cpp info without defaults (the defaults are in the new one)
                        conanfile.cpp_info = CppInfo(
                            conanfile.name,
                            package_folder,
                            default_values=CppInfoDefaultValues())
                        if not is_editable:
                            conanfile.cpp.package.set_relative_base_folder(
                                conanfile.package_folder)
                            # Copy the infos.package into the old cppinfo
                            fill_old_cppinfo(conanfile.cpp.package,
                                             conanfile.cpp_info)
                        else:
                            conanfile.cpp_info.filter_empty = False

                    conanfile.package_info()

                    if hasattr(conanfile, "layout") and is_editable:
                        # Adjust the folders of the layout to consolidate the rootfolder of the
                        # cppinfos inside
                        # convert directory entries to be relative to the declared folders.build
                        conanfile.cpp.build.set_relative_base_folder(
                            conanfile.build_folder)

                        # convert directory entries to be relative to the declared folders.source
                        conanfile.cpp.source.set_relative_base_folder(
                            conanfile.source_folder)

                        full_editable_cppinfo = NewCppInfo()
                        full_editable_cppinfo.merge(conanfile.cpp.source)
                        full_editable_cppinfo.merge(conanfile.cpp.build)
                        # Paste the editable cpp_info but prioritizing it, only if a
                        # variable is not declared at build/source, the package will keep the value
                        fill_old_cppinfo(full_editable_cppinfo,
                                         conanfile.cpp_info)

                    if conanfile._conan_dep_cpp_info is None:
                        try:
                            if not is_editable and not hasattr(
                                    conanfile, "layout"):
                                # FIXME: The default for the cppinfo from build are not the same
                                #        so this check fails when editable
                                # FIXME: Remove when new cppinfo model. If using the layout method
                                #        the cppinfo object is filled from self.cpp.package new
                                #        model and we cannot check if the defaults have been modified
                                #        because it doesn't exist in the new model where the defaults
                                #        for the components are always empty
                                conanfile.cpp_info._raise_incorrect_components_definition(
                                    conanfile.name, conanfile.requires)
                        except ConanException as e:
                            raise ConanException("%s package_info(): %s" %
                                                 (str(conanfile), e))
                        conanfile._conan_dep_cpp_info = DepCppInfo(
                            conanfile.cpp_info)
                    self._hook_manager.execute("post_package_info",
                                               conanfile=conanfile,
                                               reference=ref)