예제 #1
0
    def no_value_declared_test(self):
        client = TestClient()
        dep1 = GenConanfile()

        base = '''
[requires]
base/0.1
[generators]
virtualenv
    '''
        client.save({"conanfile.py": dep1})
        client.run("create . base/0.1@")
        client.save({"conanfile.txt": base}, clean_first=True)
        client.run("install . -g virtualenv_python")
        name = "activate_run_python.sh" if platform.system(
        ) != "Windows" else "activate_run_python.bat"
        contents = client.load(name)
        self.assertNotIn("PYTHONPATH", contents)
예제 #2
0
    def test_cmake_find_filename(self):
        conanfile = textwrap.dedent("""
                    from conans import ConanFile
                    class HelloConan(ConanFile):
                        def package_info(self):
                            self.cpp_info.filenames['cmake_find_package'] = 'FooBar'
                            self.cpp_info.names['cmake_find_package'] = 'foobar'
                            self.cpp_info.names['cmake_find_package_multi'] = 'foobar_multi'
                            self.cpp_info.names['pkg_config'] = 'foobar_cfg'
                    """)
        client = TestClient()
        client.save({"conanfile.py": conanfile})
        client.run("create . bar/0.1.0@user/testing")
        client.run("install bar/0.1.0@user/testing -g markdown")
        content = client.load("bar.md")

        self.assertIn("Generates the file FindFooBar.cmake", content)
        self.assertIn("find_package(FooBar)", content)
예제 #3
0
파일: info_test.py 프로젝트: yipdw/conan
    def test_full_attributes(self):
        client = TestClient()

        conanfile = textwrap.dedent("""
            from conans import ConanFile

            class MyTest(ConanFile):
                name = "Pkg"
                version = "0.2"
                settings = "build_type"
                author = "John Doe"
                license = "MIT"
                url = "https://foo.bar.baz"
                homepage = "https://foo.bar.site"
                topics = ("foo", "bar", "qux")
                provides = ("libjpeg", "libjpg")
                deprecated = "other-pkg"
        """)

        client.save({"subfolder/conanfile.py": conanfile})
        client.run("export ./subfolder lasote/testing")
        client.run("info ./subfolder")

        self.assertIn("conanfile.py (Pkg/0.2)", client.out)
        self.assertIn("License: MIT", client.out)
        self.assertIn("Author: John Doe", client.out)
        self.assertIn("Topics: foo, bar, qux", client.out)
        self.assertIn("URL: https://foo.bar.baz", client.out)
        self.assertIn("Homepage: https://foo.bar.site", client.out)
        self.assertIn("Provides: libjpeg, libjpg", client.out)
        self.assertIn("Deprecated: other-pkg", client.out)

        client.run("info ./subfolder --json=output.json")
        output = json.loads(client.load('output.json'))[0]
        self.assertEqual(output['reference'], 'conanfile.py (Pkg/0.2)')
        self.assertListEqual(output['license'], [
            'MIT',
        ])
        self.assertEqual(output['author'], 'John Doe')
        self.assertListEqual(output['topics'], ['foo', 'bar', 'qux'])
        self.assertEqual(output['url'], 'https://foo.bar.baz')
        self.assertEqual(output['homepage'], 'https://foo.bar.site')
        self.assertListEqual(output['provides'], ['libjpeg', 'libjpg'])
        self.assertEqual(output['deprecated'], 'other-pkg')
예제 #4
0
    def test(self, host_context):
        # https://github.com/conan-io/conan/issues/7864
        t = TestClient()
        t.save({"conanfile.py": GenConanfile()})
        t.run("create . gtest/1.8.0@PORT/stable")
        t.run("create . gtest/1.8.1@bloomberg/stable")

        t.save({
            "conanfile.py":
            GenConanfile().with_require("gtest/1.8.0@PORT/stable")
        })
        t.run("create . intermediate/1.0@PORT/stable")

        if host_context:
            t.save({
                "conanfile.py":
                GenConanfile().with_requires(
                    "intermediate/1.0@PORT/stable").with_build_requirement(
                        "gtest/1.8.0@PORT/stable", force_host_context=True)
            })
        else:
            # WARNING: This test will fail in Conan 2.0, because build_requires will be by default
            # in the build-context and do not conflict
            t.save({
                "conanfile.py":
                GenConanfile().with_requires("intermediate/1.0@PORT/stable").
                with_build_requires("gtest/1.8.0@PORT/stable")
            })
        t.run("create . scubaclient/1.6@PORT/stable")

        # IMPORTANT: We need to override the private build-require in the profile too,
        # otherwise it will conflict, as it will not be overriden by regular requires
        t.save({
            "conanfile.py":
            GenConanfile().with_requires("gtest/1.8.1@bloomberg/stable",
                                         "scubaclient/1.6@PORT/stable"),
            "myprofile":
            "[build_requires]\ngtest/1.8.1@bloomberg/stable"
        })

        t.run("lock create conanfile.py --build -pr=myprofile")
        lock = t.load("conan.lock")
        self.assertIn("gtest/1.8.1@bloomberg/stable", lock)
        self.assertNotIn("gtest/1.8.0@PORT/stable", lock)
예제 #5
0
    def test_basic_test(self):
        test_server = TestServer()
        servers = {"default": test_server}
        client = TestClient(servers=servers,
                            users={"default": [("lasote", "mypass")]})
        for i in (1, 2):
            client.save({
                "conanfile.py":
                GenConanfile().with_name("Hello").with_version("0.%s" % i)
            })
            client.run("export . lasote/channel")

        client.run("alias Hello/0.X@lasote/channel Hello/0.1@lasote/channel")
        conanfile_chat = textwrap.dedent("""
            from conans import ConanFile
            class TestConan(ConanFile):
                name = "Chat"
                version = "1.0"
                requires = "Hello/0.X@lasote/channel"
                """)
        client.save({"conanfile.py": conanfile_chat}, clean_first=True)
        client.run("export . lasote/channel")
        client.save({"conanfile.txt": "[requires]\nChat/1.0@lasote/channel"},
                    clean_first=True)

        client.run("install . --build=missing")

        self.assertIn("Hello/0.1@lasote/channel from local", client.out)
        self.assertNotIn("Hello/0.X@lasote/channel", client.out)
        conaninfo = client.load("conaninfo.txt")
        self.assertIn("Hello/0.1@lasote/channel", conaninfo)
        self.assertNotIn("Hello/0.X@lasote/channel", conaninfo)

        client.run('upload "*" --all --confirm')
        client.run('remove "*" -f')

        client.run("install .")
        self.assertIn("Hello/0.1@lasote/channel from 'default'", client.out)
        self.assertNotIn("Hello/0.X@lasote/channel from", client.out)

        client.run("alias Hello/0.X@lasote/channel Hello/0.2@lasote/channel")
        client.run("install . --build=missing")
        self.assertIn("Hello/0.2", client.out)
        self.assertNotIn("Hello/0.1", client.out)
예제 #6
0
def test_cpp_package():
    client = TestClient()

    conan_hello = textwrap.dedent("""
        import os
        from conans import ConanFile
        from conan.tools.files import save
        class Pkg(ConanFile):
            def package(self):
                save(self, os.path.join(self.package_folder, "foo/include/foo.h"), "")
                save(self, os.path.join(self.package_folder,"foo/libs/foo.lib"), "")

            def layout(self):
                self.cpp.package.includedirs = ["foo/include"]
                self.cpp.package.libdirs = ["foo/libs"]
                self.cpp.package.libs = ["foo"]
             """)

    client.save({"conanfile.py": conan_hello})
    client.run("create . hello/1.0@")

    conan_consumer = textwrap.dedent("""
        from conans import ConanFile
        class HelloTestConan(ConanFile):
            settings = "os", "compiler", "build_type", "arch"
            requires = "hello/1.0"
            generators = "CMakeDeps"
            def generate(self):
                info = self.dependencies["hello"].cpp_info
                self.output.warn("**includedirs:{}**".format(info.includedirs))
                self.output.warn("**libdirs:{}**".format(info.libdirs))
                self.output.warn("**libs:{}**".format(info.libs))
        """)

    client.save({"conanfile.py": conan_consumer})
    client.run("install .")
    assert "**includedirs:['foo/include']**" in client.out
    assert "**libdirs:['foo/libs']**" in client.out
    assert "**libs:['foo']**" in client.out
    cmake = client.load("hello-release-x86_64-data.cmake")

    assert 'set(hello_INCLUDE_DIRS_RELEASE "${hello_PACKAGE_FOLDER_RELEASE}/foo/include")' in cmake
    assert 'set(hello_LIB_DIRS_RELEASE "${hello_PACKAGE_FOLDER_RELEASE}/foo/libs")' in cmake
    assert 'set(hello_LIBS_RELEASE foo)' in cmake
예제 #7
0
def test_exclude_code_analysis(pattern, exclude_a, exclude_b):
    client = TestClient()
    client.save({"conanfile.py": GenConanfile()})
    client.run("create . pkga/1.0@")
    client.run("create . pkgb/1.0@")

    conanfile = textwrap.dedent("""
        from conans import ConanFile
        from conan.tools.microsoft import MSBuild

        class HelloConan(ConanFile):
            settings = "os", "build_type", "compiler", "arch"
            requires = "pkgb/1.0@", "pkga/1.0"
            generators = "msbuild"
            def build(self):
                msbuild = MSBuild(self)
                msbuild.build("MyProject.sln")
        """)
    profile = textwrap.dedent("""
        include(default)
        build_type=Release
        arch=x86_64
        [conf]
        tools.microsoft.msbuilddeps:exclude_code_analysis = %s
        """ % pattern)

    client.save({"conanfile.py": conanfile, "profile": profile})
    client.run("install . --profile profile")
    depa = client.load("conan_pkga_release_x64.props")
    depb = client.load("conan_pkgb_release_x64.props")

    if exclude_a:
        inc = "$(ConanpkgaIncludeDirectories)"
        ca_exclude = "<CAExcludePath>%s;$(CAExcludePath)</CAExcludePath>" % inc
        assert ca_exclude in depa
    else:
        assert "CAExcludePath" not in depa

    if exclude_b:
        inc = "$(ConanpkgbIncludeDirectories)"
        ca_exclude = "<CAExcludePath>%s;$(CAExcludePath)</CAExcludePath>" % inc
        assert ca_exclude in depb
    else:
        assert "CAExcludePath" not in depb
예제 #8
0
    def test_transitive_private(self):
        # https://github.com/conan-io/conan/issues/3523
        client = TestClient()
        conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    pass
    def package_info(self):
        self.cpp_info.libs = [self.name]
"""
        client.save({"conanfile.py": conanfile})
        client.run("create . PkgC/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.replace("pass", "requires='PkgC/0.1@user/channel'")
        })
        client.run("create . PkgB/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.replace(
                "pass", "requires=('PkgB/0.1@user/channel', 'private'), "
                "'PkgC/0.1@user/channel'")
        })
        client.run("create . PkgA/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.replace("pass", "requires='PkgA/0.1@user/channel'")
        })
        client.run("install . -g=cmake")
        self.assertIn(
            "PkgC/0.1@user/channel:%s - Cache" % NO_SETTINGS_PACKAGE_ID,
            client.out)
        conanbuildinfo = load(
            os.path.join(client.current_folder, "conanbuildinfo.txt"))
        self.assertIn("[libs];PkgA;PkgC",
                      ";".join(conanbuildinfo.splitlines()))
        self.assertIn("PkgC/0.1/user/channel/package", conanbuildinfo)
        self.assertIn("[includedirs_PkgC]", conanbuildinfo)
        conanbuildinfo = client.load("conanbuildinfo.cmake")
        self.assertIn("set(CONAN_LIBS PkgA PkgC ${CONAN_LIBS})",
                      conanbuildinfo)
        client.run("info . --graph=file.html")
        html = load(os.path.join(client.current_folder, "file.html"))
        self.assertEqual(1, html.count("label: 'PkgC/0.1', shape: 'box'"))
예제 #9
0
    def test_apple_framework(self):

        client = TestClient()
        conanfile_fr = conanfile_py + '''
    def package_info(self):
        self.cpp_info.sharedlinkflags = ["-framework Foundation"]
        self.cpp_info.exelinkflags = self.cpp_info.sharedlinkflags
'''
        client.save({"conanfile.py": conanfile_fr,
                     "hello.h": hello})

        client.run("export . lasote/testing")
        client.save({"conanfile.txt": conanfile,
                     "CMakeLists.txt": cmake,
                     "main.cpp": main}, clean_first=True)

        client.run("install . -g cmake")
        bili = client.load("conanbuildinfo.cmake")
        self.assertIn("-framework Foundation", bili)
예제 #10
0
    def test_multifile(self):
        gen_ref = ConanFileReference.loads("MyCustomGen/0.2@lasote/stable")
        client = TestClient(servers=self.servers,
                            users={"default": [("lasote", "mypass")]})
        files = {CONANFILE: generator_multi}
        client.save(files)
        client.run("export . lasote/stable")
        client.run("upload %s" % str(gen_ref))

        # Test local, no retrieval
        files = {CONANFILE_TXT: consumer_multi}
        client.save(files, clean_first=True)
        client.run("install . --build")
        self.assertIn(
            "Generator MyCustomMultiGenerator is multifile. "
            "Property 'filename' not used", client.out)
        for i in (1, 2):
            generated = client.load("file%d.gen" % i)
            self.assertEqual(generated, "CustomContent%d" % i)
예제 #11
0
파일: info_test.py 프로젝트: vermosen/conan
    def info_build_requires_test(self):
        client = TestClient()
        conanfile = """from conans import ConanFile
class AConan(ConanFile):
    pass
    """
        client.save({"conanfile.py": conanfile})
        client.run("create . tool/0.1@user/channel")
        client.run("create . dep/0.1@user/channel")
        conanfile = conanfile + 'requires = "dep/0.1@user/channel"'
        client.save({"conanfile.py": conanfile})
        client.run("export . Pkg/0.1@user/channel")
        client.run("export . Pkg2/0.1@user/channel")
        client.save(
            {
                "conanfile.txt":
                "[requires]\nPkg/0.1@user/channel\nPkg2/0.1@user/channel",
                "myprofile": "[build_requires]\ntool/0.1@user/channel"
            },
            clean_first=True)
        client.run("info . -pr=myprofile --dry-build=missing")
        # Check that there is only 1 output for tool, not repeated many times
        pkgs = [
            line for line in str(client.out).splitlines()
            if line.startswith("tool")
        ]
        self.assertEqual(len(pkgs), 1)

        client.run(
            "info . -pr=myprofile --dry-build=missing --graph=file.html")
        html = client.load("file.html")
        self.assertIn("html", html)
        # To check that this node is not duplicated
        self.assertEqual(1, html.count("label: 'dep/0.1'"))
        self.assertIn(
            "label: 'Pkg2/0.1', shape: 'box', color: {background: 'Khaki'}",
            html)
        self.assertIn(
            "label: 'Pkg/0.1', shape: 'box', color: {background: 'Khaki'}",
            html)
        self.assertIn(
            "label: 'tool/0.1', shape: 'ellipse', color: {background: 'SkyBlue'}",
            html)
예제 #12
0
    def double_alias_test(self, use_requires):
        # https://github.com/conan-io/conan/issues/2583
        client = TestClient()
        if use_requires:
            conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    requires = "%s"
"""
        else:
            conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    def requirements(self):
        req = "%s"
        if req:
            self.requires(req)
"""

        client.save({"conanfile.py": conanfile % ""}, clean_first=True)
        client.run("export . LibD/0.1@user/testing")
        client.run("alias LibD/latest@user/testing LibD/0.1@user/testing")

        client.save({"conanfile.py": conanfile % "LibD/latest@user/testing"})
        client.run("export . LibC/0.1@user/testing")
        client.run("alias LibC/latest@user/testing LibC/0.1@user/testing")

        client.save({"conanfile.py": conanfile % "LibC/latest@user/testing"})
        client.run("export . LibB/0.1@user/testing")
        client.run("alias LibB/latest@user/testing LibB/0.1@user/testing")

        client.save({"conanfile.py": conanfile % "LibC/latest@user/testing"})
        client.run("export . LibA/0.1@user/testing")
        client.run("alias LibA/latest@user/testing LibA/0.1@user/testing")

        client.save(
                {"conanfile.txt": "[requires]\nLibA/latest@user/testing\nLibB/latest@user/testing"},
                clean_first=True)
        client.run("info conanfile.txt --graph=file.dot")
        graphfile = client.load("file.dot")
        self.assertIn('"LibA/0.1@user/testing" -> {"LibC/0.1@user/testing"}', graphfile)
        self.assertIn('"LibB/0.1@user/testing" -> {"LibC/0.1@user/testing"}', graphfile)
        self.assertIn('"LibC/0.1@user/testing" -> {"LibD/0.1@user/testing"}', graphfile)
        self.assertTrue(('"conanfile.txt" -> {"LibB/0.1@user/testing" "LibA/0.1@user/testing"}' in graphfile) or
                        ('"conanfile.txt" -> {"LibA/0.1@user/testing" "LibB/0.1@user/testing"}' in graphfile))
예제 #13
0
    def test_multiple_private_skip(self):
        client = TestClient()
        conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    def package_info(self):
        self.cpp_info.libs = ["zlib"]
"""
        client.save({"conanfile.py": conanfile})
        client.run("create . zlib/1.2.11@conan/stable")
        client.save({"conanfile.py": conanfile.replace("zlib", "bzip2")})
        client.run("create . bzip2/1.0.6@conan/stable")
        conanfile = """from conans import ConanFile
class MyPackage(ConanFile):
    requires = ('zlib/1.2.11@conan/stable', 'private'), ('bzip2/1.0.6@conan/stable', 'private')
    def package_info(self):
        self.cpp_info.libs = ["mypackage"]
"""
        client.save({"conanfile.py": conanfile})
        client.run("create . MyPackage/1.0@testing/testing")
        client.run("remove bzip2/1.0.6@conan/stable -p -f")
        client.run("remove zlib* -p -f")
        conanfile = """from conans import ConanFile
class V3D(ConanFile):
    requires = "zlib/1.2.11@conan/stable", "MyPackage/1.0@testing/testing"
"""
        client.save({"conanfile.py": conanfile})
        client.run("install . -g=cmake", assert_error=True)
        self.assertIn(
            "ERROR: Missing prebuilt package for 'zlib/1.2.11@conan/stable'",
            client.out)
        client.run("install zlib/1.2.11@conan/stable --build=missing")
        client.run("install . -g=cmake")
        self.assertIn(
            "bzip2/1.0.6@conan/stable:%s - Skip" % NO_SETTINGS_PACKAGE_ID,
            client.out)
        self.assertIn(
            "zlib/1.2.11@conan/stable:%s - Cache" % NO_SETTINGS_PACKAGE_ID,
            client.out)
        conanbuildinfo = client.load("conanbuildinfo.cmake")
        # The order is dictated by V3D declaration order, as other are privates
        self.assertIn("set(CONAN_LIBS zlib mypackage ${CONAN_LIBS})",
                      conanbuildinfo)
        self.assertNotIn("bzip2", conanbuildinfo)
예제 #14
0
    def test_custom_content_components(self):
        conanfile = textwrap.dedent("""
            from conans import ConanFile
            from conans.tools import save
            import os
            import textwrap

            class PkgConfigConan(ConanFile):
                def package_info(self):
                    self.cpp_info.components["mycomponent"].set_property("pkg_config_custom_content",
                                                                         "componentdir=${prefix}/mydir")
            """)
        client = TestClient()
        client.save({"conanfile.py": conanfile})
        client.run("create . pkg/0.1@")
        client.run("install pkg/0.1@ -g pkg_config")

        pc_content = client.load("mycomponent.pc")
        self.assertIn("componentdir=${prefix}/mydir", pc_content)
예제 #15
0
    def test_dependents_txt(self):
        client = TestClient()
        boost = """from conans import ConanFile
class Boost(ConanFile):
    def package_info(self):
        self.env_info.PATH.append("myboostpath")
"""
        client.save({CONANFILE: boost})
        client.run("create . Boost/1.0@user/channel")
        other = """[build_requires]
Boost/1.0@user/channel
"""
        client.save({"conanfile.txt": other}, clean_first=True)
        client.run("install .")

        self.assertIn("""Build requirements
    Boost/1.0@user/channel""", client.out)
        conanbuildinfo = client.load("conanbuildinfo.txt")
        self.assertIn('PATH=["myboostpath"]', conanbuildinfo)
예제 #16
0
    def test_per_package_layout(self):
        client = TestClient()

        def files(name, depend=None):
            deps = ('"Hello%s/0.1@lasote/stable"' % depend) if depend else "None"
            return {"conanfile.py": conanfile_build.format(deps=deps, name=name)}

        client.save(files("C"), path=os.path.join(client.current_folder, "C"))
        client.save(files("B", "C"), path=os.path.join(client.current_folder, "B"))
        client.save(files("A", "B"), path=os.path.join(client.current_folder, "A"))

        project = dedent("""
            editables:
                HelloB/0.1@lasote/stable:
                    path: B
                    layout: B/layoutB
                HelloC/0.1@lasote/stable:
                    path: C
                    layout: C/layoutC
                HelloA/0.1@lasote/stable:
                    path: A
                    layout: A/layoutA
            root: HelloA/0.1@lasote/stable
            """)
        layout = dedent("""
            [build_folder]
            build

            [includedirs]
            myinclude{}
            """)
        client.save({"conanws.yml": project,
                     "A/layoutA": layout.format("A"),
                     "B/layoutB": layout.format("B"),
                     "C/layoutC": layout.format("C")})
        client.run("workspace install conanws.yml")
        self.assertIn("HelloA/0.1@lasote/stable from user folder - Editable", client.out)
        self.assertIn("HelloB/0.1@lasote/stable from user folder - Editable", client.out)
        self.assertIn("HelloC/0.1@lasote/stable from user folder - Editable", client.out)

        cmake = client.load(os.path.join("A", "build", "conanbuildinfo.cmake"))
        self.assertIn("myincludeC", cmake)
        self.assertIn("myincludeB", cmake)
예제 #17
0
def test_private_transitive():
    # https://github.com/conan-io/conan/issues/9514
    client = TestClient()
    client.save({
        "dep/conanfile.py":
        GenConanfile(),
        "pkg/conanfile.py":
        GenConanfile().with_require("dep/0.1", private=True),
        "consumer/conanfile.py":
        GenConanfile().with_requires("pkg/0.1").with_settings(
            "os", "build_type", "arch")
    })
    client.run("create dep dep/0.1@")
    client.run("create pkg pkg/0.1@")
    client.run(
        "install consumer -g CMakeDeps -s arch=x86_64 -s build_type=Release")
    assert "dep/0.1:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Skip" in client.out
    data_cmake = client.load("pkg-release-x86_64-data.cmake")
    assert "set(pkg_FIND_DEPENDENCY_NAMES ${pkg_FIND_DEPENDENCY_NAMES} )" in data_cmake
예제 #18
0
    def test_transitive_py_requires(self):
        # https://github.com/conan-io/conan/issues/5529
        client = TestClient()
        conanfile = textwrap.dedent("""
            from conans import ConanFile
            class Base(ConanFile):
                pass
            """)
        client.save({"conanfile.py": conanfile})
        client.run("export . base/1.0@user/channel")

        conanfile = textwrap.dedent("""
            from conans import ConanFile, python_requires
            py_req = python_requires("base/1.0@user/channel")
            class PackageInfo(ConanFile):
                pass
            """)
        client.save({"conanfile.py": conanfile})
        client.run("export . helper/1.0@user/channel")

        conanfile = textwrap.dedent("""
            from conans import ConanFile, python_requires
            source = python_requires("helper/1.0@user/channel")
            class MyConanfileBase(ConanFile):
                pass
            """)
        client.save({"conanfile.py": conanfile})
        client.run("install . pkg/0.1@user/channel")
        lockfile = client.load("conan.lock")
        if client.cache.config.revisions_enabled:
            self.assertIn(
                "base/1.0@user/channel#e41727b922c6ae54b216a58442893f3a",
                lockfile)
            self.assertIn(
                "helper/1.0@user/channel#98457e1f8d9174ed053747634ce0ea1a",
                lockfile)
        else:
            self.assertIn("base/1.0@user/channel", lockfile)
            self.assertIn("helper/1.0@user/channel", lockfile)
        client.run("source .")
        self.assertIn(
            "conanfile.py (pkg/0.1@user/channel): Configuring sources in",
            client.out)
예제 #19
0
    def test(self):
        client = TestClient()
        sysroot = """from conans import ConanFile
class Pkg(ConanFile):
    def package_info(self):
        self.cpp_info.sysroot = "HelloSysRoot"
"""
        client.save({"conanfile.py": sysroot})
        client.run("create . sysroot/0.1@user/testing")

        conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    build_requires = "sysroot/0.1@user/testing"
    def build(self):
        self.output.info("PKG SYSROOT: %s" % self.deps_cpp_info.sysroot)
    def package_info(self):
        self.cpp_info.sysroot = "HelloSysRoot"
"""
        test_conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    def build(self):
        self.output.info("Test SYSROOT: %s" % self.deps_cpp_info.sysroot)
    def test(self):
        pass
"""
        client.save({
            "conanfile.py": conanfile,
            "test_package/conanfile.py": test_conanfile
        })
        client.run("create . Pkg/0.1@user/testing")
        self.assertIn("Pkg/0.1@user/testing: PKG SYSROOT: HelloSysRoot",
                      client.out)
        self.assertIn(
            "Pkg/0.1@user/testing (test package): Test SYSROOT: HelloSysRoot",
            client.out)

        # Install conanfile and check conaninfo.txt
        client.run("install .")
        bili = client.load("conanbuildinfo.txt")
        self.assertIn(os.linesep.join(["[sysroot_sysroot]", "HelloSysRoot"]),
                      bili)
        self.assertIn(os.linesep.join(["[sysroot]", "HelloSysRoot"]), bili)
예제 #20
0
    def test_version_ranges(self):
        client = self.client
        initial_lockfile = client.load("conan.lock")
        # Do a change in python_require
        client.save({"conanfile.py": self.python_req.format("ByePyWorld")})
        client.run("export . pyreq/0.2@user/channel")

        # Go back to main orchestrator
        client.run("lock create --reference=PkgD/0.1@user/channel --lockfile-out=conan.lock")
        client.run("lock build-order conan.lock --json=build_order.json")
        master_lockfile = client.load("conan.lock")
        json_file = client.load("build_order.json")
        to_build = json.loads(json_file)
        lock_fileaux = master_lockfile
        while to_build:
            for ref, _, _, _ in to_build[0]:
                client_aux = TestClient(cache_folder=client.cache_folder)
                client_aux.save({"conan.lock": lock_fileaux})
                client_aux.run("install %s --build=%s --lockfile=conan.lock "
                               "--lockfile-out=conan.lock" % (ref, ref))
                lock_fileaux = client_aux.load("conan.lock")
                client.save({"new_lock/conan.lock": lock_fileaux})
                client.run("lock update conan.lock new_lock/conan.lock")

            client.run("lock build-order conan.lock --json=bo.json")
            lock_fileaux = client.load("conan.lock")
            to_build = json.loads(client.load("bo.json"))

        new_lockfile = client.load("conan.lock")
        client.run("install PkgD/0.1@user/channel --lockfile=conan.lock")
        for pkg in ("PkgA", "PkgB", "PkgC", "PkgD"):
            self.assertIn("{}/0.1@user/channel: ByePyWorld".format(pkg), client.out)

        client.save({"conan.lock": initial_lockfile})
        client.run("install PkgD/0.1@user/channel --lockfile=conan.lock")
        for pkg in ("PkgA", "PkgB", "PkgC", "PkgD"):
            self.assertIn("{}/0.1@user/channel: HelloPyWorld".format(pkg), client.out)

        client.save({"conan.lock": new_lockfile})
        client.run("install PkgD/0.1@user/channel --lockfile=conan.lock")
        for pkg in ("PkgA", "PkgB", "PkgC", "PkgD"):
            self.assertIn("{}/0.1@user/channel: ByePyWorld".format(pkg), client.out)
예제 #21
0
    def recipe_with_components_requiring_recipe_without_components_test(self):
        client = TestClient()
        self._create_greetings(client, components=False)

        conanfile = textwrap.dedent("""
            from conans import ConanFile, CMake

            class WorldConan(ConanFile):
                name = "world"
                version = "0.0.1"
                settings = "os", "compiler", "build_type", "arch"
                requires = "greetings/0.0.1"

                def package_info(self):
                    self.cpp_info.components["helloworld"].requires = ["greetings::greetings"]
                    self.cpp_info.components["helloworld"].libs = ["helloworld"]
                    self.cpp_info.components["worldall"].requires = ["helloworld",
                                                                     "greetings::greetings"]
                    self.cpp_info.components["worldall"].libs = ["worldall"]
            """)
        self._create_world(client, conanfile=conanfile)
        client.run("install world/0.0.1@ -g pkg_config")
        self.assertFalse(
            os.path.isfile(os.path.join(client.current_folder, "hello.pc")))
        self.assertFalse(
            os.path.isfile(os.path.join(client.current_folder, "bye.pc")))
        greetings_pc = client.load(
            os.path.join(client.current_folder, "greetings.pc"))
        self.assertNotIn("Requires:", greetings_pc)
        libs = self._get_libs_from_pkg_config("greetings",
                                              client.current_folder)
        self.assertListEqual(["-lhello", "-lbye"], libs)
        libs = self._get_libs_from_pkg_config("world", client.current_folder)
        self.assertListEqual(
            ["-lworldall", "-lhelloworld", "-lhello", "-lbye"], libs)
        libs = self._get_libs_from_pkg_config("helloworld",
                                              client.current_folder)
        self.assertListEqual(["-lhelloworld", "-lhello", "-lbye"], libs)
        libs = self._get_libs_from_pkg_config("worldall",
                                              client.current_folder)
        self.assertListEqual(
            ["-lworldall", "-lhelloworld", "-lhello", "-lbye"], libs)
예제 #22
0
def test_generator_files():
    client = TestClient()
    client.save({
        "hello.py":
        GenConanfile().with_settings("os", "arch", "compiler",
                                     "build_type").with_package_info(
                                         cpp_info={
                                             "libs": ["hello"],
                                             "frameworks": ['framework_hello']
                                         },
                                         env_info={})
    })
    client.run("export hello.py hello/0.1@")
    client.save({
        "goodbye.py":
        GenConanfile().with_settings(
            "os", "arch", "compiler",
            "build_type").with_package_info(cpp_info={
                "libs": ["goodbye"],
                "frameworks": ['framework_goodbye']
            },
                                            env_info={})
    })
    client.run("export goodbye.py goodbye/0.1@")
    client.save({"conanfile.txt": "[requires]\nhello/0.1\ngoodbye/0.1\n"},
                clean_first=True)

    for build_type in ["Release", "Debug"]:

        client.run(
            "install . -g XcodeDeps -s build_type={} -s arch=x86_64 --build missing"
            .format(build_type))

        for config_file in expected_files(client.current_folder, build_type,
                                          "x86_64"):
            assert os.path.isfile(config_file)

        conandeps = client.load("conandeps.xcconfig")
        assert '#include "conan_hello.xcconfig"' in conandeps
        assert '#include "conan_goodbye.xcconfig"' in conandeps

        check_contents(client, ["hello", "goodbye"], build_type, "x86_64")
예제 #23
0
    def test_python_requires(self):
        client = TestClient()
        client.save({"conanfile.py": GenConanfile()})
        client.run("export . tool/0.1@")
        conanfile = textwrap.dedent("""
            from conans import ConanFile
            class Pkg(ConanFile):
                python_requires = "tool/0.1"
            """)
        client.save({"conanfile.py": conanfile})

        client.run("info .")
        assert "Python-requires:" in client.out
        assert "tool/0.1#f3367e0e7d170aa12abccb175fee5f97" in client.out

        client.run("info . --json=file.json")
        info = json.loads(client.load("file.json"))
        assert info[0]["python_requires"] == [
            'tool/0.1#f3367e0e7d170aa12abccb175fee5f97'
        ]
예제 #24
0
 def test_c_project(self):
     conanfile = textwrap.dedent("""
                 from conans import ConanFile
                 class HelloConan(ConanFile):
                     settings = "os", "arch", "compiler", "build_type"
                     def configure(self):
                         del self.settings.compiler.libcxx
                         del self.settings.compiler.cppstd
                     def package_info(self):
                         self.cpp_info.set_property("cmake_file_name", "FooBar")
                         self.cpp_info.set_property("cmake_target_name", "foobar")
                         self.cpp_info.set_property("pkg_config_name", "foobar_cfg")
                 """)
     client = TestClient()
     client.save({"conanfile.py": conanfile})
     client.run("create . bar/0.1.0@user/testing")
     client.run("install bar/0.1.0@user/testing -g markdown")
     content = client.load("bar.md")
     self.assertIn("main.c", content)
     self.assertIn("project(bar_project C)", content)
예제 #25
0
    def test_srcdirs(self):
        client = TestClient()
        conanfile = """from conans import ConanFile
from conans.tools import save
import os
class TestConan(ConanFile):
    def package(self):
        save(os.path.join(self.package_folder, "src/file.h"), "//header")
    def package_info(self):
        self.cpp_info.srcdirs = ["src"]
"""

        client.save({"conanfile.py": conanfile})
        client.run("create . mysrc/0.1@user/testing")
        client.run("install mysrc/0.1@user/testing -g cmake")

        cmake = client.load("conanbuildinfo.cmake")
        src_dirs = re.search('set\(CONAN_SRC_DIRS_MYSRC "(.*)"\)', cmake).group(1)
        self.assertIn("mysrc/0.1/user/testing/package/%s/src" % NO_SETTINGS_PACKAGE_ID,
                      src_dirs)
예제 #26
0
    def test_install_transitive_build_requires(self):
        # https://github.com/conan-io/conan/issues/8170
        client = TestClient()
        client.save({"conanfile.py": GenConanfile()})
        client.run("export . dep/1.0@")
        client.run("export . tool_build/1.0@")
        client.run("export . tool_test/1.0@")
        conanfile = GenConanfile().with_requires("dep/1.0").with_build_requires("tool_build/1.0").\
            with_build_requirement("tool_test/1.0", force_host_context=True)
        client.save({"conanfile.py": conanfile})
        client.run("export . pkg/1.0@")

        client.save({"conanfile.py": GenConanfile().
                    with_settings("os", "compiler", "arch", "build_type").
                    with_requires("pkg/1.0")}, clean_first=True)
        client.run("install . -g MSBuildDeps -pr:b=default -pr:h=default --build=missing")
        pkg = client.load("conan_pkg_release_x64.props")
        assert "conan_dep.props" in pkg
        assert "tool_test" not in pkg  # test requires are not there
        assert "tool_build" not in pkg
예제 #27
0
def test_cmakedeps_cppinfo_complex_strings():
    client = TestClient(path_with_spaces=False)
    conanfile = textwrap.dedent(r'''
        from conans import ConanFile
        class HelloLib(ConanFile):
            def package_info(self):
                self.cpp_info.defines.append("escape=partially \"escaped\"")
                self.cpp_info.defines.append("spaces=me you")
                self.cpp_info.defines.append("foobar=bazbuz")
                self.cpp_info.defines.append("answer=42")
        ''')
    client.save({"conanfile.py": conanfile})
    client.run("export . hello/1.0@")
    client.save({"conanfile.txt": "[requires]\nhello/1.0\n"}, clean_first=True)
    client.run("install . --build=missing -g CMakeDeps")
    deps = client.load("hello-release-x86_64-data.cmake")
    assert r"escape=partially \"escaped\"" in deps
    assert r"spaces=me you" in deps
    assert r"foobar=bazbuz" in deps
    assert r"answer=42" in deps
예제 #28
0
def test_toolchain_loads_config_from_profile():
    client = TestClient(path_with_spaces=False)

    profile = textwrap.dedent("""
    include(default)
    [conf]
    tools.google.bazel:config=test_config
    tools.google.bazel:bazelrc_path=/path/to/bazelrc
    """)

    conanfile = GenConanfile().with_settings("os", "compiler", "build_type", "arch").\
        with_generator("BazelToolchain")

    client.save({"conanfile.py": conanfile, "test_profile": profile})
    client.run("install . -pr=test_profile")

    config = json.loads(client.load("conanbuild.json"))

    assert config['bazel_config'] == "test_config"
    assert config['bazelrc_path'] == "/path/to/bazelrc"
예제 #29
0
    def same_names_test(self):
        client = TestClient()
        conanfile_greetings = textwrap.dedent("""
            from conans import ConanFile, CMake

            class HelloConan(ConanFile):
                name = "hello"
                version = "0.0.1"
                settings = "os", "compiler", "build_type", "arch"

                def package_info(self):
                    self.cpp_info.components["global"].name = "hello"
                    self.cpp_info.components["global"].libs = ["hello"]
            """)
        client.save({"conanfile.py": conanfile_greetings})
        client.run("create .")
        client.run("install hello/0.0.1@ -g pkg_config")
        self.assertNotIn(
            "Requires:",
            client.load(os.path.join(client.current_folder, "hello.pc")))
예제 #30
0
    def conditional_env_var_test(self):
        client = TestClient()
        client.save({"conanfile.py": GenConanfile()})
        client.run("create . dep/1.0@")
        conanfile = textwrap.dedent("""
            from conans import ConanFile
            import os
            class Pkg(ConanFile):
                def requirements(self):
                    if os.getenv("USE_DEP"):
                        self.requires("dep/1.0")
            """)
        client.save({"conanfile.py": conanfile})
        with environment_append({"USE_DEP": "1"}):
            client.run("lock create conanfile.py --name=pkg --version=1.0")
        lock = client.load("conan.lock")
        self.assertIn("dep/1.0", lock)

        client.run("create . pkg/1.0@ --lockfile=conan.lock", assert_error=True)
        self.assertIn("ERROR: 'pkg/1.0' locked requirement 'dep/1.0' not found", client.out)