示例#1
0
    def test_load_imports_arguments(self):
        file_content = '''
[imports]
OpenCV/bin, * -> ./bin # I need this binaries
OpenCV/lib, * -> ./lib @ root_package=Pkg
OpenCV/data, * -> ./data @ root_package=Pkg, folder=True # Irrelevant
docs, * -> ./docs @ root_package=Pkg, folder=True, ignore_case=False, excludes="a b c" # Other
licenses, * -> ./licenses @ root_package=Pkg, folder=True, ignore_case=False, excludes="a b c", keep_path=False # Other
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Mock(), None)
        ret = loader.load_conanfile_txt(file_path, create_profile())

        ret.copy = Mock()
        ret.imports()
        expected = [
            call(u'*', u'./bin', u'OpenCV/bin', None, False, True, None, True),
            call(u'*', u'./lib', u'OpenCV/lib', u'Pkg', False, True, None,
                 True),
            call(u'*', u'./data', u'OpenCV/data', u'Pkg', True, True, None,
                 True),
            call(u'*', u'./docs', u'docs', u'Pkg', True, False,
                 [u'"a', u'b', u'c"'], True),
            call(u'*', u'./licenses', u'licenses', u'Pkg', True, False,
                 [u'"a', u'b', u'c"'], False)
        ]
        self.assertEqual(ret.copy.call_args_list, expected)
示例#2
0
 def build_graph(self, content, update=False):
     self.loader._cached_conanfile_classes = {}
     profile = create_profile()
     root_conan = self.retriever.root(str(content), profile)
     deps_graph = self.builder.load_graph(root_conan,
                                          update,
                                          update,
                                          self.remotes,
                                          profile_host=profile,
                                          profile_build=None)
     self.output.write("\n".join(self.resolver.output))
     return deps_graph
示例#3
0
 def test_layout_not_predefined(self):
     txt = textwrap.dedent("""
                 [layout]
                 missing
             """)
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "conanfile.txt")
     save(file_path, txt)
     with pytest.raises(ConanException) as exc:
         loader = ConanFileLoader(None, Mock(), None)
         loader.load_conanfile_txt(file_path, create_profile())
     assert "Unknown predefined layout 'missing'" in str(exc.value)
示例#4
0
    def _build_and_check(self, tmp_dir, file_path, text_file, msg):
        loader = ConanFileLoader(None, Mock(), ConanPythonRequire(None, None))
        ret = loader.load_consumer(file_path, create_profile())
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEqual(content, msg)
示例#5
0
 def test_load_options_error(self):
     conanfile_txt = textwrap.dedent("""
         [options]
         myoption: myvalue
     """)
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "file.txt")
     save(file_path, conanfile_txt)
     loader = ConanFileLoader(None, Mock(), None)
     with six.assertRaisesRegex(self, ConanException,
                                r"Error while parsing \[options\] in conanfile\n"
                                "Options should be specified as 'pkg:option=value'"):
         loader.load_conanfile_txt(file_path, create_profile())
示例#6
0
 def test_layout_multiple(self):
     txt = textwrap.dedent("""
                 [layout]
                 cmake_layout
                 vs_layout
             """)
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "conanfile.txt")
     save(file_path, txt)
     with pytest.raises(ConanException) as exc:
         loader = ConanFileLoader(None, Mock(), None)
         loader.load_conanfile_txt(file_path, create_profile())
     assert "Only one layout can be declared in the [layout] section of the conanfile.txt" \
            in str(exc.value)
示例#7
0
    def test_requires_init(self):
        loader = ConanFileLoader(None, Mock(), ConanPythonRequire(None, None))
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    def requirements(self):
        self.requires("MyPkg/0.1@user/channel")
"""
        for requires in ("''", "[]", "()", "None"):
            save(conanfile_path, conanfile.format(requires))
            result = loader.load_consumer(conanfile_path, profile_host=create_profile())
            result.requirements()
            self.assertEqual("MyPkg/0.1@user/channel", str(result.requires))
示例#8
0
    def test_inherit_short_paths(self):
        loader = ConanFileLoader(None, Mock(), ConanPythonRequire(None, None))
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from base_recipe import BasePackage
class Pkg(BasePackage):
    pass
"""
        base_recipe = """from conans import ConanFile
class BasePackage(ConanFile):
    short_paths = True
"""
        save(conanfile_path, conanfile)
        save(os.path.join(tmp_dir, "base_recipe.py"), base_recipe)
        conan_file = loader.load_basic(conanfile_path)
        self.assertEqual(conan_file.short_paths, True)

        result = loader.load_consumer(conanfile_path, profile_host=create_profile())
        self.assertEqual(result.short_paths, True)
示例#9
0
    def test_complete(self):
        """ basic installation of a new conans
        """
        client = TestClient()
        files = cpp_hello_source_files()

        ref = ConanFileReference.loads("Hello/1.2.1@frodo/stable")
        reg_folder = client.cache.package_layout(ref).export()

        client.save(files, path=reg_folder)
        client.save({CONANFILE: myconan1,
                     "infos/%s" % CONANINFO: "//empty",
                     "include/no_copy/lib0.h":                     "NO copy",
                     "include/math/lib1.h":                        "copy",
                     "include/math/lib2.h":                        "copy",
                     "include/physics/lib.hpp":                    "copy",
                     "my_lib/debug/libd.a":                        "copy",
                     "my_data/readme.txt":                         "copy",
                     "my_data/readme.md":                          "NO copy",
                     "contrib/math/math.h":                        "copy",
                     "contrib/physics/gravity.h":                  "copy",
                     "contrib/contrib.h":                          "copy",
                     "include/opencv/opencv.hpp":                  "copy",
                     "include/opencv2/opencv2.hpp":                "copy",
                     "modules/simu/src/simu.cpp":                  "NO copy",
                     "modules/simu/include/opencv2/simu/simu.hpp": "copy",
                     "modules/3D/doc/readme.md":                   "NO copy",
                     "modules/3D/include/opencv2/3D/3D.hpp":       "copy",
                     "modules/dev/src/dev.cpp":                    "NO copy",
                     "modules/dev/include/opencv2/dev/dev.hpp":    "copy",
                     "modules/opencv_mod.hpp":                     "copy"}, path=reg_folder)

        conanfile_path = os.path.join(reg_folder, CONANFILE)
        pref = PackageReference(ref, "myfakeid")
        build_folder = client.cache.package_layout(pref.ref).build(pref)
        package_folder = client.cache.package_layout(pref.ref).package(pref)
        install_folder = os.path.join(build_folder, "infos")

        shutil.copytree(reg_folder, build_folder)

        loader = ConanFileLoader(None, TestBufferConanOutput(), ConanPythonRequire(None, None))
        conanfile = loader.load_consumer(conanfile_path, create_profile())

        conanfile.layout.set_base_build_folder(build_folder)
        conanfile.layout.set_base_source_folder(build_folder)
        conanfile.layout.set_base_package_folder(package_folder)
        conanfile.layout.set_base_install_folder(install_folder)

        run_package_method(conanfile, None, Mock(), conanfile_path, ref, copy_info=True)

        # test build folder
        self.assertTrue(os.path.exists(build_folder))
        self.assertTrue(os.path.exists(os.path.join(package_folder, CONANINFO)))

        # test pack folder
        self.assertTrue(os.path.exists(package_folder))

        def exist(rel_path):
            return os.path.exists(os.path.join(package_folder, rel_path))

        # Expected files
        self.assertTrue(exist("include/lib1.h"))
        self.assertTrue(exist("include/lib2.h"))
        self.assertTrue(exist("include/physics/lib.hpp"))
        self.assertTrue(exist("include/contrib/math/math.h"))
        self.assertTrue(exist("include/contrib/physics/gravity.h"))
        self.assertTrue(exist("include/contrib/contrib.h"))
        self.assertTrue(exist("include/opencv/opencv.hpp"))
        self.assertTrue(exist("include/opencv2/opencv2.hpp"))
        self.assertTrue(exist("include/opencv2/simu/simu.hpp"))
        self.assertTrue(exist("include/opencv2/3D/3D.hpp"))
        self.assertTrue(exist("include/opencv2/dev/dev.hpp"))
        self.assertTrue(exist("lib/my_lib/libd.a"))
        self.assertTrue(exist("res/shares/readme.txt"))

        # Not expected files
        self.assertFalse(exist("include/opencv2/opencv_mod.hpp"))
        self.assertFalse(exist("include/opencv2/simu.hpp"))
        self.assertFalse(exist("include/opencv2/3D.hpp"))
        self.assertFalse(exist("include/opencv2/dev.hpp"))
        self.assertFalse(exist("include/modules/simu/src/simu.cpp"))
        self.assertFalse(exist("include/modules/3D/doc/readme.md"))
        self.assertFalse(exist("include/modules/dev/src/dev.cpp"))
        self.assertFalse(exist("include/opencv2/opencv_mod.hpp"))
        self.assertFalse(exist("include/include/no_copy/lib0.h"))
        self.assertFalse(exist("res/my_data/readme.md"))
示例#10
0
    def test_load_conan_txt(self):
        file_content = '''[requires]
OpenCV/2.4.10@phil/stable
OpenCV2/2.4.10@phil/stable
[build_requires]
MyPkg/1.0.0@phil/stable
[generators]
one
two
[imports]
OpenCV/bin, * -> ./bin # I need this binaries
OpenCV/lib, * -> ./lib
[options]
OpenCV:use_python=True
OpenCV:other_option=False
OpenCV2:use_python2=1
OpenCV2:other_option=Cosa
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Mock(), None)
        ret = loader.load_conanfile_txt(file_path, create_profile())
        options1 = OptionsValues.loads("""OpenCV:use_python=True
OpenCV:other_option=False
OpenCV2:use_python2=1
OpenCV2:other_option=Cosa""")
        requirements = Requirements()
        requirements.add("OpenCV/2.4.10@phil/stable")
        requirements.add("OpenCV2/2.4.10@phil/stable")
        build_requirements = ["MyPkg/1.0.0@phil/stable"]

        self.assertEqual(ret.requires, requirements)
        self.assertEqual(ret.build_requires, build_requirements)
        self.assertEqual(ret.generators, ["one", "two"])
        self.assertEqual(ret.options.values.dumps(), options1.dumps())

        ret.copy = Mock()
        ret.imports()

        self.assertTrue(ret.copy.call_args_list,
                        [('*', './bin', 'OpenCV/bin'),
                         ('*', './lib', 'OpenCV/lib')])

        # Now something that fails
        file_content = '''[requires]
OpenCV/2.4.104phil/stable
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Mock(), None)
        with six.assertRaisesRegex(self, ConanException,
                                   "The reference has too many '/'"):
            loader.load_conanfile_txt(file_path, create_profile())

        file_content = '''[requires]
OpenCV/2.4.10@phil/stable111111111111111111111111111111111111111111111111111111111111111
[imports]
OpenCV/bin/* - ./bin
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Mock(), None)
        with six.assertRaisesRegex(self, ConanException,
                                   "is too long. Valid names must contain"):
            loader.load_conanfile_txt(file_path, create_profile())