Пример #1
0
    def test_absolute_directory(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("pkg/0.1")
        cpp_info = CppInfo(ref.name, "C:/my/root/path")
        cpp_info.includedirs = ["D:/my/path/to/something"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        master_content = TXTGenerator(conanfile).content
        after_cpp_info, _, _, _ = TXTGenerator.loads(master_content, filter_empty=False)
        self.assertListEqual(after_cpp_info[ref.name].includedirs, ["D:/my/path/to/something"])
        self.assertListEqual(after_cpp_info[ref.name].include_paths, ["D:/my/path/to/something"])
Пример #2
0
 def _check_individual_deps(self):
     self.assertIn("INCLUDE [", self.client.out)
     self.assertIn("/data/Hello0/0.1/lasote/stable", self.client.out)
     build_file = os.path.join(self.client.current_folder, BUILD_INFO)
     content = load(build_file)
     cmakebuildinfo = load(
         os.path.join(self.client.current_folder, BUILD_INFO_CMAKE))
     self.assertIn(
         "set(CONAN_LIBS helloHello3 helloHello1 helloHello2 helloHello0",
         cmakebuildinfo)
     self.assertIn("set(CONAN_DEPENDENCIES Hello3 Hello1 Hello2 Hello0)",
                   cmakebuildinfo)
     deps_cpp_info, _, _, _ = TXTGenerator.loads(content)
     self.assertEqual(len(deps_cpp_info.include_paths), 4)
     for dep in ("Hello3", "Hello2", "Hello1", "Hello0"):
         self.assertEqual(len(deps_cpp_info[dep].include_paths), 1)
         self.assertEqual(len(deps_cpp_info[dep].lib_paths), 1)
         self.assertEqual(deps_cpp_info[dep].libs, ["hello%s" % dep])
     build_file = os.path.join(self.client.current_folder, BUILD_INFO_CMAKE)
     content = load(build_file)
     for dep in ("Hello3", "Hello2", "Hello1", "Hello0"):
         self.assertEqual(len(deps_cpp_info[dep].include_paths), 1)
         self.assertIn("set(CONAN_INCLUDE_DIRS_%s " % dep.upper(), content)
         self.assertIn("set(CONAN_LIBS_%s hello%s)" % (dep.upper(), dep),
                       content)
Пример #3
0
def load_deps_info(current_path, conanfile, required):

    def get_forbidden_access_object(field_name):
        class InfoObjectNotDefined(object):
            def __getitem__(self, item):
                raise ConanException("self.%s not defined. If you need it for a "
                                     "local command run 'conan install'" % field_name)
            __getattr__ = __getitem__

        return InfoObjectNotDefined()

    if not current_path:
        return
    info_file_path = os.path.join(current_path, BUILD_INFO)
    try:
        deps_cpp_info, deps_user_info, deps_env_info = TXTGenerator.loads(load(info_file_path))
        conanfile.deps_cpp_info = deps_cpp_info
        conanfile.deps_user_info = deps_user_info
        conanfile.deps_env_info = deps_env_info
    except IOError:
        if required:
            raise ConanException("%s file not found in %s\nIt is required for this command\n"
                                 "You can generate it using 'conan install'"
                                 % (BUILD_INFO, current_path))
        conanfile.deps_cpp_info = get_forbidden_access_object("deps_cpp_info")
        conanfile.deps_user_info = get_forbidden_access_object("deps_user_info")
    except ConanException:
        raise ConanException("Parse error in '%s' file in %s" % (BUILD_INFO, current_path))
Пример #4
0
    def test_env_info(self):
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())

        env_info = EnvInfo()
        env_info.VAR1 = "value1"
        env_info.PATH.append("path-extended")
        conanfile.deps_env_info.update(env_info, "my_pkg")

        env_info = EnvInfo()
        env_info.VAR1 = "other-value1"
        env_info.PATH.append("other-path-extended")
        conanfile.deps_env_info.update(env_info, "other-pkg")

        generator = TXTGenerator(conanfile)
        txt_out = generator.content

        self.assertIn(
            textwrap.dedent("""
                    [ENV_my_pkg]
                    PATH=["path-extended"]
                    VAR1=value1
                    [ENV_other-pkg]
                    PATH=["other-path-extended"]
                    VAR1=other-value1"""), txt_out)
Пример #5
0
    def test_content(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder1")
        cpp_info.defines = ["MYDEFINE1"]
        cpp_info.cxxflags = ["-cxxflag_parent"]
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder2")
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.cxxflags = ["-cxxflag_dep"]
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        generator = TXTGenerator(conanfile)
        txt_out = generator.content

        self.assertIn(
            textwrap.dedent("""
            [cppflags_MyPkg]
            -cxxflag_parent

            [cxxflags_MyPkg]
            -cxxflag_parent"""), txt_out)

        self.assertIn(
            textwrap.dedent("""
            [cppflags_MyPkg]
            -cxxflag_parent

            [cxxflags_MyPkg]
            -cxxflag_parent"""), txt_out)
Пример #6
0
    def test_load_sytem_libs(self):
        content = textwrap.dedent("""
            [system_libs]
            a-real-flow-contains-aggregated-list-here

            [name_requirement]
            requirement_name

            [rootpath_requirement]
            requirement_rootpath

            [system_libs_requirement]
            requirement

            [name_requirement_other]
            requirement_other_name

            [rootpath_requirement_other]
            requirement_other_rootpath

            [system_libs_requirement_other]
            requirement_other
        """)

        deps_cpp_info, _, _ = TXTGenerator.loads(content)
        self.assertListEqual(list(deps_cpp_info.system_libs),
                             ["requirement", "requirement_other"])
        self.assertListEqual(list(deps_cpp_info["requirement"].system_libs), [
            "requirement",
        ])
        self.assertListEqual(
            list(deps_cpp_info["requirement_other"].system_libs), [
                "requirement_other",
            ])
Пример #7
0
    def test_abs_path_unix(self):
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("pkg/0.1")
        cpp_info = CppInfo(ref.name, "/rootdir")
        cpp_info.includedirs = ["/an/absolute/dir"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        master_content = TXTGenerator(conanfile).content
        after_cpp_info, _, _, _ = TXTGenerator.loads(master_content,
                                                     filter_empty=False)
        self.assertListEqual(after_cpp_info[ref.name].includedirs,
                             ["../an/absolute/dir"])
        self.assertListEqual(after_cpp_info[ref.name].include_paths,
                             ["/rootdir/../an/absolute/dir"])
Пример #8
0
def _load_deps_info(current_path, conanfile, required):

    def get_forbidden_access_object(field_name):
        class InfoObjectNotDefined(object):
            def __getitem__(self, item):
                raise ConanException("self.%s not defined. If you need it for a "
                                     "local command run 'conan install'" % field_name)
            __getattr__ = __getitem__

        return InfoObjectNotDefined()

    if not current_path:
        return
    info_file_path = os.path.join(current_path, BUILD_INFO)
    try:
        deps_cpp_info, deps_user_info, deps_env_info = TXTGenerator.loads(load(info_file_path))
        conanfile.deps_cpp_info = deps_cpp_info
        conanfile.deps_user_info = deps_user_info
        conanfile.deps_env_info = deps_env_info
    except IOError:
        if required:
            raise ConanException("%s file not found in %s\nIt is required for this command\n"
                                 "You can generate it using 'conan install'"
                                 % (BUILD_INFO, current_path))
        conanfile.deps_cpp_info = get_forbidden_access_object("deps_cpp_info")
        conanfile.deps_user_info = get_forbidden_access_object("deps_user_info")
    except ConanException:
        raise ConanException("Parse error in '%s' file in %s" % (BUILD_INFO, current_path))
Пример #9
0
    def test_names_per_generator(self):
        cpp_info = CppInfo("pkg_name", "root")
        cpp_info.name = "name"
        cpp_info.names["txt"] = "txt_name"
        cpp_info.names["cmake_find_package"] = "SpecialName"
        cpp_info.filenames["cmake_find_package"] = "SpecialFileName"
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        conanfile.deps_cpp_info.add("pkg_name", DepCppInfo(cpp_info))
        content = TXTGenerator(conanfile).content
        parsed_deps_cpp_info, _, _, _ = TXTGenerator.loads(content, filter_empty=False)

        parsed_cpp_info = parsed_deps_cpp_info["pkg_name"]
        self.assertEqual(parsed_cpp_info.get_name("txt"), "txt_name")
        self.assertEqual(parsed_cpp_info.get_name("cmake_find_package"), "SpecialName")
        self.assertEqual(parsed_cpp_info.get_filename("cmake_find_package"), "SpecialFileName")
        self.assertEqual(parsed_cpp_info.get_name("pkg_config"), "pkg_name")
Пример #10
0
    def test_read_write(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder1")
        cpp_info.names["txt"] = "mypkg1-txt"
        cpp_info.version = ref.version
        cpp_info.defines = ["MYDEFINE1"]
        cpp_info.cxxflags = ["-cxxflag_parent"]
        cpp_info.includedirs = ["mypkg1/include"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder2")
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.cxxflags = ["-cxxflag_dep"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        master_content = TXTGenerator(conanfile).content
        after_parse, _, _ = TXTGenerator.loads(master_content,
                                               filter_empty=False)
        conanfile.deps_cpp_info = after_parse
        after_content = TXTGenerator(conanfile).content

        self.assertListEqual(master_content.splitlines(),
                             after_content.splitlines())
Пример #11
0
    def test_conaninfo_filtered(self):
        client = TestClient()
        # Try injecting some package level ENV in the install, but without priority
        self._export(client, "A", [], {}, {"VAR1": "900", "VAR2": "23", "VAR3": "-23"})
        self._export(client, "B", ["A"], {}, {"VAR1": "800", "VAR2": "24"})
        self._export(client, "B2", ["A"], {}, {"VAR1": "800_2", "VAR2": "24_2"})
        self._export(client, "C", ["B", "B2"], {"VAR3": "bestvalue"}, {"VAR1": "700"})

        def load_conaninfo(lib):
            # Read the LIB_A conaninfo
            packages_path = client.cache.package_layout(ConanFileReference.loads("LIB_%s/1.0@lasote/stable" % lib)).packages()
            package_path = os.path.join(packages_path, os.listdir(packages_path)[0])
            info = ConanInfo.loads(load(os.path.join(package_path, CONANINFO)))
            return info

        # Test "A" conaninfo, should filter the FAKE_LIB
        client.save({"conanfile.py": reuse})
        client.run("install . --build missing -e LIB_A:VAR3=override "
                   "-e GLOBAL=99 -e FAKE_LIB:VAR1=-90 -e LIB_B:VAR2=222 "
                   "-e LIB_B2:NEWVAR=VALUE -e VAR3=[newappend]")

        info = load_conaninfo("A")
        self.assertEqual(info.env_values.env_dicts("LIB_A"),
                          ({"VAR3": "override", "GLOBAL": "99"}, {}))
        self.assertEqual(info.env_values.env_dicts(""),
                          ({'GLOBAL': '99'}, {'VAR3': ['newappend']}))

        info = load_conaninfo("B")
        self.assertEqual(info.env_values.env_dicts("LIB_A"), ({'GLOBAL': '99', 'VAR3': "override"},
                                                               {}))

        self.assertEqual(info.env_values.env_dicts("LIB_B"), ({'GLOBAL': '99', "VAR2": "222"},
                                                               {'VAR3': ['newappend']}))

        info = load_conaninfo("B2")
        self.assertEqual(info.env_values.env_dicts("LIB_A"), ({'GLOBAL': '99', 'VAR3': 'override'},
                                                               {}))

        self.assertEqual(info.env_values.env_dicts("LIB_B2"), ({'GLOBAL': '99', 'NEWVAR': "VALUE"},
                                                                {'VAR3': ['newappend']}))

        info = load_conaninfo("C")
        self.assertEqual(info.env_values.env_dicts("LIB_B2"), ({'GLOBAL': '99', 'NEWVAR': "VALUE"},
                                                                {'VAR3': ['newappend']}))
        self.assertEqual(info.env_values.env_dicts("LIB_C"), ({'GLOBAL': '99'},
                                                               {'VAR3': ['newappend']}))

        # Now check the info for the project
        info = ConanInfo.loads(client.load(CONANINFO))
        self.assertEqual(info.env_values.env_dicts("PROJECT"), ({'GLOBAL': '99'},
                                                                 {'VAR3': ['newappend']}))

        _, _, buildinfo, _ = TXTGenerator.loads(client.load(BUILD_INFO))
        self.assertEqual(buildinfo["LIB_A"].VAR1, ["900"])
Пример #12
0
    def test_conaninfo_filtered(self):
        client = TestClient()
        # Try injecting some package level ENV in the install, but without priority
        self._export(client, "A", [], {}, {"VAR1": "900", "VAR2": "23", "VAR3": "-23"})
        self._export(client, "B", ["A"], {}, {"VAR1": "800", "VAR2": "24"})
        self._export(client, "B2", ["A"], {}, {"VAR1": "800_2", "VAR2": "24_2"})
        self._export(client, "C", ["B", "B2"], {"VAR3": "bestvalue"}, {"VAR1": "700"})

        def load_conaninfo(lib):
            # Read the LIB_A conaninfo
            packages_path = client.client_cache.packages(ConanFileReference.loads("LIB_%s/1.0@lasote/stable" % lib))
            package_path = os.path.join(packages_path, os.listdir(packages_path)[0])
            info = ConanInfo.loads(load(os.path.join(package_path, CONANINFO)))
            return info

        # Test "A" conaninfo, should filter the FAKE_LIB
        client.save({"conanfile.py": reuse})
        client.run("install . --build missing -e LIB_A:VAR3=override "
                   "-e GLOBAL=99 -e FAKE_LIB:VAR1=-90 -e LIB_B:VAR2=222 "
                   "-e LIB_B2:NEWVAR=VALUE -e VAR3=[newappend]")

        info = load_conaninfo("A")
        self.assertEquals(info.env_values.env_dicts("LIB_A"),
                          ({"VAR3": "override", "GLOBAL": "99"}, {}))
        self.assertEquals(info.env_values.env_dicts(""),
                          ({'GLOBAL': '99'}, {'VAR3': ['newappend']}))

        info = load_conaninfo("B")
        self.assertEquals(info.env_values.env_dicts("LIB_A"), ({'GLOBAL': '99', 'VAR3': "override"},
                                                               {}))

        self.assertEquals(info.env_values.env_dicts("LIB_B"), ({'GLOBAL': '99', "VAR2": "222"},
                                                               {'VAR3': ['newappend']}))

        info = load_conaninfo("B2")
        self.assertEquals(info.env_values.env_dicts("LIB_A"), ({'GLOBAL': '99', 'VAR3': 'override'},
                                                               {}))

        self.assertEquals(info.env_values.env_dicts("LIB_B2"), ({'GLOBAL': '99', 'NEWVAR': "VALUE"},
                                                                {'VAR3': ['newappend']}))

        info = load_conaninfo("C")
        self.assertEquals(info.env_values.env_dicts("LIB_B2"), ({'GLOBAL': '99', 'NEWVAR': "VALUE"},
                                                                {'VAR3': ['newappend']}))
        self.assertEquals(info.env_values.env_dicts("LIB_C"), ({'GLOBAL': '99'},
                                                               {'VAR3': ['newappend']}))

        # Now check the info for the project
        info = ConanInfo.loads(load(os.path.join(client.current_folder, CONANINFO)))
        self.assertEquals(info.env_values.env_dicts("PROJECT"), ({'GLOBAL': '99'},
                                                                 {'VAR3': ['newappend']}))

        _, _, buildinfo = TXTGenerator.loads(load(os.path.join(client.current_folder, BUILD_INFO)))
        self.assertEquals(buildinfo["LIB_A"].VAR1, ["900"])
Пример #13
0
    def test_user_info(self):
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())

        user_info = UserInfo()
        user_info.VAR1 = "value1"
        conanfile.deps_user_info["my_pkg"] = user_info

        user_info = UserInfo()
        user_info.VAR1 = "other-value1"
        conanfile.deps_user_info["other-pkg"] = user_info

        generator = TXTGenerator(conanfile)
        txt_out = generator.content

        self.assertIn(
            textwrap.dedent("""
                    [USER_my_pkg]
                    VAR1=value1
                    [USER_other-pkg]
                    VAR1=other-value1"""), txt_out)
Пример #14
0
 def _check_individual_deps(self, client):
     self.test_obj.assertIn("INCLUDE [", client.user_io.out)
     self.test_obj.assertIn(".conan/data/Hello0/0.1/lasote/stable", client.user_io.out)
     build_file = os.path.join(client.current_folder, BUILD_INFO)
     content = load(build_file)
     cmakebuildinfo = load(os.path.join(client.current_folder, BUILD_INFO_CMAKE))
     self.test_obj.assertIn("set(CONAN_LIBS helloHello3 helloHello1 helloHello2 helloHello0",
                            cmakebuildinfo)
     self.test_obj.assertIn("set(CONAN_DEPENDENCIES Hello3 Hello1 Hello2 Hello0)", cmakebuildinfo)
     deps_cpp_info, _, _ = TXTGenerator.loads(content)
     self.test_obj.assertEqual(len(deps_cpp_info.include_paths), 4)
     for dep in ("Hello3", "Hello2", "Hello1", "Hello0"):
         self.test_obj.assertEqual(len(deps_cpp_info[dep].include_paths), 1)
         self.test_obj.assertEqual(len(deps_cpp_info[dep].lib_paths), 1)
         self.test_obj.assertEqual(deps_cpp_info[dep].libs, ["hello%s" % dep])
     build_file = os.path.join(client.current_folder, BUILD_INFO_CMAKE)
     content = load(build_file)
     for dep in ("Hello3", "Hello2", "Hello1", "Hello0"):
         self.test_obj.assertEqual(len(deps_cpp_info[dep].include_paths), 1)
         self.test_obj.assertIn("set(CONAN_INCLUDE_DIRS_%s " % dep.upper(), content)
         self.test_obj.assertIn("set(CONAN_LIBS_%s hello%s)" % (dep.upper(), dep), content)
Пример #15
0
    def test_user_info_build(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())

        conanfile.user_info_build = DepsUserInfo()
        user_info = UserInfo()
        user_info.VAR1 = "value1"
        conanfile.user_info_build["build_pkg"] = user_info

        user_info = UserInfo()
        user_info.VAR1 = "other-value1"
        conanfile.user_info_build["other-build-pkg"] = user_info

        generator = TXTGenerator(conanfile)
        txt_out = generator.content

        self.assertIn(
            textwrap.dedent("""
                    [USERBUILD_build_pkg]
                    VAR1=value1
                    [USERBUILD_other-build-pkg]
                    VAR1=other-value1"""), txt_out)
Пример #16
0
    def test_load_sytem_libs(self):
        content = textwrap.dedent("""
            [system_libs]
            main

            [system_libs_requirement]
            requirement

            [system_libs_requirement_other]
            requirement_other
        """)

        deps_cpp_info, _, _ = TXTGenerator.loads(content)
        self.assertEqual(deps_cpp_info.system_libs, [
            "main",
        ])
        a = deps_cpp_info["requirement"]
        self.assertEqual(deps_cpp_info["requirement"].system_libs, [
            "requirement",
        ])
        self.assertEqual(deps_cpp_info["requirement_other"].system_libs, [
            "requirement_other",
        ])
Пример #17
0
    def test_idempotent(self):
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())

        # Add some cpp_info
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder1")
        cpp_info.names["txt"] = "mypkg1-txt"
        cpp_info.version = ref.version
        cpp_info.defines = ["MYDEFINE1"]
        cpp_info.cxxflags = ["-cxxflag_parent"]
        cpp_info.includedirs = ["mypkg1/include"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder2")
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.cxxflags = ["-cxxflag_dep"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        # Add env_info
        env_info = EnvInfo()
        env_info.VAR1 = "value1"
        env_info.PATH.append("path-extended")
        conanfile.deps_env_info.update(env_info, "my_pkg")

        env_info = EnvInfo()
        env_info.VAR1 = "other-value1"
        env_info.PATH.append("other-path-extended")
        conanfile.deps_env_info.update(env_info, "other-pkg")

        # Add user_info for HOST
        user_info = UserInfo()
        user_info.VAR1 = "value1"
        conanfile.deps_user_info["my_pkg"] = user_info

        user_info = UserInfo()
        user_info.VAR1 = "other-value1"
        conanfile.deps_user_info["other-pkg"] = user_info

        # Add user_info for BUILD
        conanfile.user_info_build = DepsUserInfo()
        user_info = UserInfo()
        user_info.VAR1 = "value1"
        conanfile.user_info_build["build_pkg"] = user_info

        user_info = UserInfo()
        user_info.VAR1 = "other-value1"
        conanfile.user_info_build["other-build-pkg"] = user_info

        master_content = TXTGenerator(conanfile).content
        after_cpp_info, after_user_info, after_env_info, after_user_info_build = \
            TXTGenerator.loads(master_content, filter_empty=False)
        # Assign them to a different conanfile
        other_conanfile = ConanFile(Mock(), None)
        other_conanfile.initialize(Settings({}), EnvValues())
        other_conanfile.deps_cpp_info = after_cpp_info
        other_conanfile.deps_env_info = after_env_info
        other_conanfile.deps_user_info = after_user_info
        other_conanfile.user_info_build = after_user_info_build
        after_content = TXTGenerator(other_conanfile).content

        self.assertListEqual(master_content.splitlines(),
                             after_content.splitlines())