Esempio n. 1
0
    def test_collect_libs(self):
        conanfile = ConanFileMock()
        # Without package_folder
        conanfile.package_folder = None
        result = tools.collect_libs(conanfile)
        self.assertEqual([], result)

        # Default behavior
        conanfile.package_folder = temp_folder()
        mylib_path = os.path.join(conanfile.package_folder, "lib", "mylib.lib")
        save(mylib_path, "")
        conanfile.cpp_info = CppInfo("", "")
        result = tools.collect_libs(conanfile)
        self.assertEqual(["mylib"], result)

        # Custom folder
        customlib_path = os.path.join(conanfile.package_folder,
                                      "custom_folder", "customlib.lib")
        save(customlib_path, "")
        result = tools.collect_libs(conanfile, folder="custom_folder")
        self.assertEqual(["customlib"], result)

        # Custom folder doesn't exist
        result = tools.collect_libs(conanfile, folder="fake_folder")
        self.assertEqual([], result)
        self.assertIn("Lib folder doesn't exist, can't collect libraries:",
                      conanfile.output)

        # Use cpp_info.libdirs
        conanfile.cpp_info.libdirs = ["lib", "custom_folder"]
        result = tools.collect_libs(conanfile)
        self.assertEqual(["customlib", "mylib"], result)

        # Custom folder with multiple libdirs should only collect from custom folder
        self.assertEqual(["lib", "custom_folder"], conanfile.cpp_info.libdirs)
        result = tools.collect_libs(conanfile, folder="custom_folder")
        self.assertEqual(["customlib"], result)

        # Warn same lib different folders
        conanfile = ConanFileMock()
        conanfile.package_folder = temp_folder()
        conanfile.cpp_info = CppInfo(conanfile.name, "")
        custom_mylib_path = os.path.join(conanfile.package_folder,
                                         "custom_folder", "mylib.lib")
        lib_mylib_path = os.path.join(conanfile.package_folder, "lib",
                                      "mylib.lib")
        save(custom_mylib_path, "")
        save(lib_mylib_path, "")
        conanfile.cpp_info.libdirs = ["lib", "custom_folder"]
        result = tools.collect_libs(conanfile)
        self.assertEqual(["mylib"], result)
        self.assertIn(
            "Library 'mylib' was either already found in a previous "
            "'conanfile.cpp_info.libdirs' folder or appears several times with a "
            "different file extension", conanfile.output)

        # Warn lib folder does not exist with correct result
        conanfile = ConanFileMock()
        conanfile.package_folder = temp_folder()
        conanfile.cpp_info = CppInfo(conanfile.name, "")
        lib_mylib_path = os.path.join(conanfile.package_folder, "lib",
                                      "mylib.lib")
        save(lib_mylib_path, "")
        no_folder_path = os.path.join(conanfile.package_folder, "no_folder")
        conanfile.cpp_info.libdirs = ["no_folder",
                                      "lib"]  # 'no_folder' does NOT exist
        result = tools.collect_libs(conanfile)
        self.assertEqual(["mylib"], result)
        self.assertIn(
            "WARN: Lib folder doesn't exist, can't collect libraries: %s" %
            no_folder_path, conanfile.output)
Esempio n. 2
0
def test_collect_libs():
    conanfile = ConanFileMock()
    conanfile.cpp_info = CppInfo(conanfile.name, "")
    # Without package_folder
    result = collect_libs(conanfile)
    assert [] == result

    # Default behavior
    conanfile.folders.set_base_package(temp_folder())
    mylib_path = os.path.join(conanfile.package_folder, "lib", "mylib.lib")
    save(mylib_path, "")

    result = collect_libs(conanfile)
    assert ["mylib"] == result

    # Custom folder
    customlib_path = os.path.join(conanfile.package_folder, "custom_folder",
                                  "customlib.lib")
    save(customlib_path, "")
    result = collect_libs(conanfile, folder="custom_folder")
    assert ["customlib"] == result

    # Custom folder doesn't exist
    result = collect_libs(conanfile, folder="fake_folder")
    assert [] == result
    assert "Lib folder doesn't exist, can't collect libraries:" in conanfile.output

    # Use cpp_info.libdirs
    conanfile.cpp_info.libdirs = ["lib", "custom_folder"]
    result = collect_libs(conanfile)
    assert ["customlib", "mylib"] == result

    # Custom folder with multiple libdirs should only collect from custom folder
    assert ["lib", "custom_folder"] == conanfile.cpp_info.libdirs
    result = collect_libs(conanfile, folder="custom_folder")
    assert ["customlib"] == result

    # Warn same lib different folders
    conanfile = ConanFileMock()
    conanfile.folders.set_base_package(temp_folder())
    conanfile.cpp_info = CppInfo(conanfile.name, "")
    custom_mylib_path = os.path.join(conanfile.package_folder, "custom_folder",
                                     "mylib.lib")
    lib_mylib_path = os.path.join(conanfile.package_folder, "lib", "mylib.lib")
    save(custom_mylib_path, "")
    save(lib_mylib_path, "")
    conanfile.cpp_info.libdirs = ["lib", "custom_folder"]
    result = collect_libs(conanfile)
    assert ["mylib"] == result
    assert "Library 'mylib' was either already found in a previous "\
           "'conanfile.cpp_info.libdirs' folder or appears several times with a "\
           "different file extension" in conanfile.output

    # Warn lib folder does not exist with correct result
    conanfile = ConanFileMock()
    conanfile.folders.set_base_package(temp_folder())
    conanfile.cpp_info = CppInfo(conanfile.name, "")
    lib_mylib_path = os.path.join(conanfile.package_folder, "lib", "mylib.lib")
    save(lib_mylib_path, "")
    no_folder_path = os.path.join(conanfile.package_folder, "no_folder")
    conanfile.cpp_info.libdirs = ["no_folder",
                                  "lib"]  # 'no_folder' does NOT exist
    result = collect_libs(conanfile)
    assert ["mylib"] == result
    assert "WARN: Lib folder doesn't exist, can't collect libraries: %s" % no_folder_path \
           in conanfile.output