Example #1
0
def test_do_not_mix_cflags_cxxflags():
    # TODO: Verify with components too
    client = TestClient()
    cpp_info = {"cflags": ["one", "two"], "cxxflags": ["three", "four"]}
    client.save({"conanfile.py": GenConanfile("upstream", "1.0").with_package_info(cpp_info=cpp_info,
                                                                                   env_info={})})
    client.run("create .")

    consumer_conanfile = textwrap.dedent("""
        from conans import ConanFile
        from conan.tools.cmake import CMake

        class Consumer(ConanFile):
            name = "consumer"
            version = "1.0"
            settings = "os", "compiler", "arch", "build_type"
            exports_sources = "CMakeLists.txt"
            requires = "upstream/1.0"
            generators = "CMakeDeps", "CMakeToolchain"

            def build(self):
                cmake = CMake(self)
                cmake.configure()
        """)
    cmakelists = textwrap.dedent("""
       cmake_minimum_required(VERSION 3.15)
       project(consumer NONE)
       find_package(upstream CONFIG REQUIRED)
       get_target_property(tmp upstream::upstream INTERFACE_COMPILE_OPTIONS)
       message("compile options: ${tmp}")
       message("cflags: ${upstream_COMPILE_OPTIONS_C_RELEASE}")
       message("cxxflags: ${upstream_COMPILE_OPTIONS_CXX_RELEASE}")
       """)
    client.save({"conanfile.py": consumer_conanfile,
                 "CMakeLists.txt": cmakelists}, clean_first=True)
    client.run("create .")
    assert "compile options: $<$<CONFIG:Release>:" \
           "$<$<COMPILE_LANGUAGE:CXX>:three;four>;$<$<COMPILE_LANGUAGE:C>:one;two>>" in client.out
    assert "cflags: one;two" in client.out
    assert "cxxflags: three;four" in client.out
Example #2
0
def test_auto_package_only_one_destination():
    """If the layout declares more than one destination folder it fails, because it cannot guess
    where to put the artifacts (very weird situation a package with two include/)"""
    client = TestClient()
    conan_file = str(GenConanfile().with_settings("build_type").with_import(
        "from conans import tools").with_import("import os").with_import(
            "from conan.tools.layout import LayoutPackager"))
    conan_file += """
    def source(self):
        tools.save("myincludes/mylib.header","")

    def build(self):
       tools.save("ugly_build/mylib.a", "")

    def layout(self):
       self.cpp.source.includedirs = ["myincludes"]
       self.cpp.build.libdirs = ["ugly_build"]
       self.cpp.build.bindirs = ["ugly_build"]
       self.cpp.build.frameworkdirs = ["ugly_build"]
       self.cpp.build.srcdirs = ["ugly_build"]
       self.cpp.build.builddirs = ["ugly_build"]
       self.cpp.build.resdirs = ["ugly_build"]

       self.patterns.source.include = ["*.header"]
       self.patterns.build.lib = ["*.a"]

       self.cpp.package.{} = ["folder1", "folder2"]

    def package(self):
        LayoutPackager(self).package()

    """
    for dirs in [
            "includedirs", "builddirs", "bindirs", "srcdirs", "frameworkdirs",
            "libdirs", "resdirs"
    ]:
        client.save({"conanfile.py": conan_file.format(dirs)})
        client.run("create . lib/1.0@", assert_error=True)
        assert "The package has more than 1 cpp_info.{}, " \
               "cannot package automatically".format(dirs) in client.out
Example #3
0
    def test_build_policies_in_conanfile(self):
        client = TestClient(default_server_user=True)
        base = GenConanfile("Hello0", "1.0").with_exports("*")
        conanfile = str(base) + "\n    build_policy = 'missing'"
        client.save({"conanfile.py": conanfile})
        client.run("export . lasote/stable")

        # Install, it will build automatically if missing (without the --build missing option)
        client.run("install Hello0/1.0@lasote/stable")
        self.assertIn("Building", client.out)

        # Try to do it again, now we have the package, so no build is done
        client.run("install Hello0/1.0@lasote/stable")
        self.assertNotIn("Building", client.out)

        # Try now to upload all packages, should not crash because of the "missing" build policy
        client.run("upload Hello0/1.0@lasote/stable --all")

        #  --- Build policy to always ---
        conanfile = str(base) + "\n    build_policy = 'always'"
        client.save({"conanfile.py": conanfile}, clean_first=True)
        client.run("export . lasote/stable")

        # Install, it will build automatically if missing (without the --build missing option)
        client.run("install Hello0/1.0@lasote/stable")
        self.assertIn(
            "Detected build_policy 'always', trying to remove source folder",
            client.out)
        self.assertIn("Building", client.out)

        # Try to do it again, now we have the package, but we build again
        client.run("install Hello0/1.0@lasote/stable")
        self.assertIn("Building", client.out)
        self.assertIn(
            "Detected build_policy 'always', trying to remove source folder",
            client.out)

        # Try now to upload all packages, should crash because of the "always" build policy
        client.run("upload Hello0/1.0@lasote/stable --all", assert_error=True)
        self.assertIn("no packages can be uploaded", client.out)
Example #4
0
def test_local_static_generators_folder():
    """If we configure a generators folder in the layout, the generator files:
      - If belong to new generators: go to the specified folder: "my_generators"
      - If belong to old generators or txt: remains in the install folder
    """
    client = TestClient()
    conan_file = str(GenConanfile().with_settings("build_type"))
    conan_file += """
    generators = "cmake", "CMakeToolchain"
    def layout(self):
        self.folders.build = "build-{}".format(self.settings.build_type)
        self.folders.generators = "{}/generators".format(self.folders.build)
    """
    client.save({"conanfile.py": conan_file})
    client.run("install . -if=my_install")

    old_install_folder = os.path.join(client.current_folder, "my_install")
    conaninfo = os.path.join(old_install_folder, "conaninfo.txt")
    conanbuildinfo = os.path.join(old_install_folder, "conanbuildinfo.txt")
    cmake_generator_path = os.path.join(old_install_folder,
                                        "conanbuildinfo.cmake")
    cmake_toolchain_generator_path = os.path.join(old_install_folder,
                                                  "conan_toolchain.cmake")
    assert os.path.exists(conaninfo)
    assert os.path.exists(conanbuildinfo)
    assert os.path.exists(cmake_generator_path)
    assert not os.path.exists(cmake_toolchain_generator_path)

    build_folder = os.path.join(client.current_folder, "build-Release")
    generators_folder = os.path.join(build_folder, "generators")
    conaninfo = os.path.join(generators_folder, "conaninfo.txt")
    conanbuildinfo = os.path.join(generators_folder, "conanbuildinfo.txt")
    cmake_generator_path = os.path.join(generators_folder,
                                        "conanbuildinfo.cmake")
    cmake_toolchain_generator_path = os.path.join(generators_folder,
                                                  "conan_toolchain.cmake")
    assert not os.path.exists(conaninfo)
    assert not os.path.exists(conanbuildinfo)
    assert not os.path.exists(cmake_generator_path)
    assert os.path.exists(cmake_toolchain_generator_path)
    def test_install_as_requirement(self):
        t = self._get_test_client()
        t.save({'conanfile.py': GenConanfile().with_requires('name/version@user/channel'),
                'profile': self.profile})

        # Requirement is found
        t.run('install . consumer/version@ --profile=profile')
        settings_header = self._get_header(t.api.http_requester, CONAN_REQUEST_HEADER_SETTINGS)
        self._assert_settings_headers(settings_header)
        options_headers = self._get_header(t.api.http_requester, CONAN_REQUEST_HEADER_OPTIONS)
        self._assert_options_headers(options_headers)

        # Requirement is not found (settings)
        t.run('install . consumer/version@ --profile=profile -s compiler.version=12.0',
              assert_error=True)
        settings_header = self._get_header(t.api.http_requester, CONAN_REQUEST_HEADER_SETTINGS)
        self._assert_settings_headers(settings_header, compiler_version='12.0')

        # Requirement is not found (options)
        t.run('install . consumer/version@ --profile=profile -o name:shared=True', assert_error=True)
        options_headers = self._get_header(t.api.http_requester, CONAN_REQUEST_HEADER_OPTIONS)
        self._assert_options_headers(options_headers, shared_value='True')
Example #6
0
    def test_frameworks_no_compiler(self):
        client = TestClient()
        client.save({
            "conanfile.py":
            textwrap.dedent("""
            from conans import ConanFile
            class Pkg(ConanFile):
                def package_info(self):
                    self.cpp_info.frameworks = ["CoreAudio"]
            """)
        })
        client.run("export . Hello/0.1@lasote/stable")

        client.save({
            "conanfile.py":
            GenConanfile().with_requires(
                "Hello/0.1@lasote/stable").with_generator("xcode")
        })
        client.run('install . --build missing')
        xcode = client.load(BUILD_INFO_XCODE)
        self.assertIn('OTHER_LDFLAGS = $(inherited)    -framework CoreAudio',
                      xcode)
Example #7
0
def test_no_cross_build():
    windows_profile = textwrap.dedent("""
        [settings]
        os=Windows
        arch=x86_64
        compiler=gcc
        compiler.version=6
        compiler.libcxx=libstdc++11
        build_type=Release
        """)

    client = TestClient(path_with_spaces=False)

    conanfile = GenConanfile().with_settings("os", "arch", "compiler", "build_type")\
        .with_generator("CMakeToolchain")
    client.save({"conanfile.py": conanfile,
                 "windows": windows_profile})
    client.run("install . --profile:build=windows --profile:host=windows")
    toolchain = client.load("conan_toolchain.cmake")

    assert "CMAKE_SYSTEM_NAME " not in toolchain
    assert "CMAKE_SYSTEM_PROCESSOR" not in toolchain
Example #8
0
    def test_info_options(self):
        # packages with dash
        client = TestClient()
        client.save({"conanfile.py":
                         GenConanfile("My-Package", "1.3").with_option("shared", [True, False])
                                                          .with_default_option("shared", False)})
        # assert they are correct at least
        client.run("export . myuser/testing")
        client.run("search")
        self.assertIn("My-Package/1.3@myuser/testing", client.out)

        # Check that I can pass options to info
        client.run("info . -o shared=True")
        self.assertIn("conanfile.py (My-Package/1.3)", client.out)
        client.run("info . -o My-Package:shared=True")
        self.assertIn("conanfile.py (My-Package/1.3)", client.out)

        # errors
        client.run("info . -o shared2=True", assert_error=True)
        self.assertIn("option 'shared2' doesn't exist", client.out)
        client.run("info . -o My-Package:shared2=True", assert_error=True)
        self.assertIn("option 'shared2' doesn't exist", client.out)
Example #9
0
def test_same_conanfile_local(conanfile):
    client = TestClient()
    client.save({"conanfile.py": GenConanfile()})
    client.run("create . base/1.0@")

    client.save({"conanfile.py": conanfile})

    source_folder = os.path.join(client.current_folder, "my_sources")
    build_folder = os.path.join(client.current_folder, "my_build")

    client.run("install . lib/1.0@ -if=install")
    client.run("source .  -if=install")
    assert "Source folder: {}".format(source_folder) in client.out
    assert os.path.exists(os.path.join(source_folder, "source.h"))

    client.run("build .  -if=install")
    assert "Build folder: {}".format(build_folder) in client.out
    assert os.path.exists(os.path.join(build_folder, "build.lib"))

    client.run("package .  -if=install", assert_error=True)
    assert "The usage of the 'conan package' local method is disabled when using " \
           "layout()" in client.out
Example #10
0
def test_reuse_uploaded_tgz():
    client = TestClient(default_server_user=True)
    # Download packages from a remote, then copy to another channel
    # and reupload them. Because they have not changed, the tgz is not created again

    # UPLOAD A PACKAGE
    ref = ConanFileReference.loads("Hello0/0.1@user/stable")
    files = {
        "conanfile.py": GenConanfile("Hello0", "0.1").with_exports("*"),
        "another_export_file.lib": "to compress"
    }
    client.save(files)
    client.run("create . user/stable")
    client.run("upload %s --all" % str(ref))
    assert "Compressing recipe" in client.out
    assert "Compressing package" in client.out

    # UPLOAD TO A DIFFERENT CHANNEL WITHOUT COMPRESS AGAIN
    client.run("copy %s user/testing --all" % str(ref))
    client.run("upload Hello0/0.1@user/testing --all")
    assert "Compressing recipe" not in client.out
    assert "Compressing package" not in client.out
Example #11
0
def test_token_expired():
    server_folder = temp_folder()
    server_conf = textwrap.dedent("""
       [server]
       jwt_expire_minutes: 0.01
       authorize_timeout: 0
       disk_authorize_timeout: 0
       disk_storage_path: ./data
       updown_secret: 12345
       jwt_secret: mysecret
       port: 12345
       [read_permissions]
       */*@*/*: *
       [write_permissions]
       */*@*/*: admin
       """)
    save(os.path.join(server_folder, ".conan_server", "server.conf"),
         server_conf)
    server = TestServer(base_path=server_folder, users={"admin": "password"})

    c = TestClient(servers={"default": server},
                   users={"default": [("admin", "password")]})
    c.save({"conanfile.py": GenConanfile()})
    c.run("create . pkg/0.1@user/stable")
    c.run("upload * -r=default --all -c")
    user, token, _ = c.cache.localdb.get_login(server.fake_url)
    assert user == "admin"
    assert token is not None

    import time
    time.sleep(2)
    c.users = {}
    c.run("config set general.non_interactive=1")
    c.run("remove * -f")
    c.run("install pkg/0.1@user/stable")
    user, token, _ = c.cache.localdb.get_login(server.fake_url)
    assert user == "admin"
    assert token is None
Example #12
0
    def setUp(self):
        self.client = TestClient()
        conanfile = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    build_policy = "missing"

    def build(self):
        self.output.info("Building %s")
"""
        for channel in ("lasote/stable", "other/testing"):
            self.client.save({"conanfile.py": conanfile % channel})
            self.client.run("export . %s" % channel)

        self.conanfile = """
from conans import ConanFile

class HelloConan(ConanFile):
    name = "Hello"
    version = "0.1"
    build_policy = "missing"

    def requirements(self):
        self.requires("Say/0.1@%s/%s" % (self.user, self.channel))

    def build(self):
        self.output.info("Building %s/%s" % (self.user, self.channel) )
"""

        self.test_conanfile = str(GenConanfile().with_require(
            "Hello/0.1@lasote/stable").with_test("pass"))
        self.client.save({
            "conanfile.py": self.conanfile,
            "test/conanfile.py": self.test_conanfile
        })
Example #13
0
def test_pkg_with_component_requires():
    client = TestClient()
    client.save({
        "conanfile.py":
        GenConanfile("other", "0.1").with_package_file("file.h", "0.1")
    })
    client.run("create . user/channel")

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

        class PkgConfigConan(ConanFile):
            requires = "other/0.1@user/channel"

            def package_info(self):
                self.cpp_info.components["mycomponent"].requires.append("other::other")
                self.cpp_info.components["myothercomp"].requires.append("mycomponent")

        """)
    client.save({"conanfile.py": conanfile})
    client.run("create . pkg/0.1@")

    client2 = TestClient(cache_folder=client.cache_folder)
    conanfile = textwrap.dedent("""
        [requires]
        pkg/0.1

        [generators]
        PkgConfigDeps
        """)
    client2.save({"conanfile.txt": conanfile})
    client2.run("install .")
    pc_content = client2.load("pkg.pc")
    assert "Requires: pkg-mycomponent" in pc_content
    pc_content = client2.load("pkg-mycomponent.pc")
    assert "Requires: other" in pc_content
    pc_content = client2.load("pkg-myothercomp.pc")
    assert "Requires: pkg-mycomponent" in pc_content
Example #14
0
def test_scm_with_source_layout():
    """If we have the sources in git repository"""
    conan_file = GenConanfile() \
        .with_name("app").with_version("1.0") \
        .with_settings("os", "arch", "build_type", "compiler") \
        .with_scm({"type": "git", "revision": "auto", "url": "auto"})\
        .with_cmake_build()

    conan_file = str(conan_file)
    conan_file += """
    def layout(self):
        self.folders.source = "my_src"
        self.folders.build = "build_{}".format(self.settings.build_type)
    """
    cmake = gen_cmakelists(appname="my_app", appsources=["main.cpp"])
    app = gen_function_cpp(name="main")

    remote_path, _ = create_local_git_repo({"foo": "var"}, branch="my_release")

    client = TestClient()

    client.save({
        "conanfile.py": conan_file,
        "my_src/main.cpp": app,
        "my_src/CMakeLists.txt": cmake,
        ".gitignore": "build_*\n"
    })
    client.init_git_repo()
    client.run_command('git remote add origin "%s"' %
                       remote_path.replace("\\", "/"))
    client.run_command('git push origin master')

    client.run("install . -if=install")
    client.run("build . -if=install")
    assert os.path.exists(
        os.path.join(client.current_folder, "build_Release", app_name))
    client.run("create . ")
    assert "Created package revision" in client.out
Example #15
0
def test_upload_parallel_error():
    """Cause an error in the parallel transfer and see some message"""
    class FailOnReferencesUploader(TestRequester):
        fail_on = ["lib1", "lib3"]

        def put(self, *args, **kwargs):
            if any(ref in args[0] for ref in self.fail_on):
                raise ConnectionError(
                    "Connection fails with lib2 and lib4 references!")
            else:
                return super(FailOnReferencesUploader,
                             self).put(*args, **kwargs)

    client = TestClient(requester_class=FailOnReferencesUploader,
                        default_server_user=True)
    client.save({"conanfile.py": GenConanfile()})
    client.run('user -p password -r default user')
    for index in range(4):
        client.run('create . lib{}/1.0@user/channel'.format(index))
    client.run('upload lib* --parallel -c --all -r default --retry-wait=0',
               assert_error=True)
    assert "Connection fails with lib2 and lib4 references!" in client.out
    assert "Execute upload again to retry upload the failed files" in client.out
Example #16
0
    def test_dirty_download(self):
        # https://github.com/conan-io/conan/issues/8578
        client = TestClient(default_server_user=True)
        cache_folder = temp_folder()
        client.run('config set storage.download_cache="%s"' % cache_folder)
        client.save({
            "conanfile.py":
            GenConanfile().with_package_file("file.txt", "content")
        })
        client.run("create . pkg/0.1@")
        client.run("upload * --all -c")
        client.run("remove * -f")
        client.run("install pkg/0.1@")
        for f in os.listdir(cache_folder):
            # damage the file
            path = os.path.join(cache_folder, f)
            if os.path.isfile(path):
                save(path, "broken!")
                set_dirty(path)

        client.run("remove * -f")
        client.run("install pkg/0.1@")
        assert "pkg/0.1: Downloaded package" in client.out
def test_local_build():
    """If we configure a build folder in the layout, the installed files in a "conan build ."
    go to the specified folder: "my_build"
    """
    client = TestClient()
    conan_file = str(GenConanfile().with_import("from conans import tools"))
    conan_file += """

    def layout(self):
        self.folders.generators = "my_generators"
        self.folders.build = "my_build"

    def build(self):
        self.output.warn("Generators folder: {}".format(self.folders.generators_folder))
        tools.save("build_file.dll", "bar")

"""
    client.save({"conanfile.py": conan_file})
    client.run("install . -if=my_install")
    # FIXME: This should change to "build ." when "conan build" computes the graph
    client.run("build . -if=my_install")
    dll = os.path.join(client.current_folder, "my_build", "build_file.dll")
    assert os.path.exists(dll)
Example #18
0
def test_local_build():
    """If we configure a build folder in the layout, the installed files in a "conan build ."
    go to the specified folder: "my_build"
    """
    # FIXME: The configure is not valid to change the layout, we need the settings and options
    #        ready
    client = TestClient()
    conan_file = str(GenConanfile().with_import("from conans import tools"))
    conan_file += """

    def configure(self):
        self.layout.build.folder = "my_build"

    def build(self):
        tools.save("build_file.dll", "bar")

"""
    client.save({"conanfile.py": conan_file})
    client.run("install . -if=my_install")
    # FIXME: This should change to "build ." when "conan build" computes the graph
    client.run("build . -if=my_install")
    dll = os.path.join(client.current_folder, "my_build", "build_file.dll")
    assert os.path.exists(dll)
Example #19
0
    def _upload_package(self, package_reference, base_files=None):

        files = {
            "conanfile.py":
            GenConanfile("3").with_requires("1", "12").with_exports("*"),
            "hello.cpp":
            "hello"
        }
        if base_files:
            files.update(base_files)

        tmp_dir = temp_folder()
        abs_paths = {}
        for filename, content in files.items():
            abs_path = os.path.join(tmp_dir, filename)
            save(abs_path, str(content))
            abs_paths[filename] = abs_path

        self.api.upload_package(package_reference,
                                abs_paths,
                                None,
                                retry=1,
                                retry_wait=0)
Example #20
0
    def test_install_build_requires(self):
        # https://github.com/conan-io/conan/issues/8170
        client = TestClient()
        client.save({"conanfile.py": GenConanfile()})
        client.run("create . tool/1.0@")

        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            class HelloConan(ConanFile):
                settings = "os", "build_type", "compiler", "arch"
                build_requires = "tool/1.0"
                generators = "MSBuildDeps"
                def build(self):
                    deps = load("conandeps.props")
                    assert "conan_tool.props" not in deps
                    self.output.info("Conan_tools.props not in deps")
            """)
        client.save({"conanfile.py": conanfile})
        client.run("install .")
        deps = client.load("conandeps.props")
        self.assertNotIn("conan_tool.props", deps)
        client.run("create . pkg/0.1@")
        self.assertIn("Conan_tools.props not in deps", client.out)
Example #21
0
def test_create_test_package_with_layout(conanfile):
    """The test package using the new generators work (having the generated files in the build
    folder)"""
    client = TestClient()
    conanfile_test = textwrap.dedent("""
        import os

        from conans import ConanFile, tools
        from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps

        class HelloTestConan(ConanFile):
            settings = "os", "compiler", "build_type", "arch"

            def generate(self):
                deps = CMakeDeps(self)
                deps.generate()
                tc = CMakeToolchain(self)
                tc.generate()

            def layout(self):
                self.folders.generators = "my_generators"

            def build(self):
                assert os.path.exists("my_generators/conan_toolchain.cmake")
                self.output.warn("hey! building")
                self.output.warn(os.getcwd())

            def test(self):
                self.output.warn("hey! testing")
    """)
    client.save({
        "conanfile.py": GenConanfile(),
        "test_package/conanfile.py": conanfile_test
    })
    client.run("create . lib/1.0@")
    assert "hey! building" in client.out
    assert "hey! testing" in client.out
    def test_put_properties(self):
        test_server = TestServer()
        servers = {"default": test_server}

        wanted_vars = {
            "key0": "value",
            "key1": "with space",
            "key2": "with/slash",
            "key3": "with.dot",
            "key4": "with;semicolon",
            "key5": "with~virgul",
            "key6": "with#hash"
        }

        class RequesterCheckArtifactProperties(TestRequester):
            def put(self_requester, url, **kwargs):
                # Check headers
                for name, value in wanted_vars.items():
                    value1 = kwargs["headers"][name]
                    self.assertEqual(value1, value)

                # Check matrix params
                self.assertNotIn(';', url)
                mp = re.match(r"^[^;\s]+;(?P<matrix_params>[^/]+)/.*", url)
                self.assertFalse(mp)

                return super(RequesterCheckArtifactProperties,
                             self_requester).put(url, **kwargs)

        client = TestClient(requester_class=RequesterCheckArtifactProperties,
                            servers=servers,
                            users={"default": [("lasote", "mypass")]})
        _create_property_files(client, wanted_vars)

        client.save({"conanfile.py": GenConanfile("Hello0", "0.1")})
        client.run("export . lasote/stable")
        client.run("upload Hello0/0.1@lasote/stable -c")
Example #23
0
def test_extra_flags_via_conf():
    os_ = platform.system()
    os_ = "Macos" if os_ == "Darwin" else os_

    profile = textwrap.dedent("""
        [settings]
        os=%s
        compiler=gcc
        compiler.version=6
        compiler.libcxx=libstdc++11
        arch=armv8
        build_type=Release

        [conf]
        tools.build:cxxflags=["--flag1", "--flag2"]
        tools.build:cflags+=["--flag3", "--flag4"]
        tools.build:sharedlinkflags+=["--flag5"]
        tools.build:exelinkflags+=["--flag6"]
        tools.build:defines+=["DEF1", "DEF2"]
        """ % os_)
    client = TestClient()
    conanfile = GenConanfile().with_settings("os", "arch", "compiler", "build_type")\
        .with_generator("AutotoolsToolchain")
    client.save({"conanfile.py": conanfile,
                "profile": profile})
    client.run("install . --profile:build=profile --profile:host=profile")
    toolchain = client.load("conanautotoolstoolchain{}".format('.bat' if os_ == "Windows" else '.sh'))
    if os_ == "Windows":
        assert 'set "CPPFLAGS=%CPPFLAGS% -DNDEBUG -DDEF1 -DDEF2"' in toolchain
        assert 'set "CXXFLAGS=%CXXFLAGS% -O3 -s --flag1 --flag2"' in toolchain
        assert 'set "CFLAGS=%CFLAGS% -O3 -s --flag3 --flag4"' in toolchain
        assert 'set "LDFLAGS=%LDFLAGS% --flag5 --flag6"' in toolchain
    else:
        assert 'export CPPFLAGS="$CPPFLAGS -DNDEBUG -DDEF1 -DDEF2"' in toolchain
        assert 'export CXXFLAGS="$CXXFLAGS -O3 -s --flag1 --flag2"' in toolchain
        assert 'export CFLAGS="$CFLAGS -O3 -s --flag3 --flag4"' in toolchain
        assert 'export LDFLAGS="$LDFLAGS --flag5 --flag6"' in toolchain
Example #24
0
 def test_metadata_editable_packages(self):
     """
     Check that 'conan remote' commands work with editable packages
     """
     self.client.save({"conanfile.py": GenConanfile()})
     self.client.run("create . pkg/1.1@lasote/stable")
     self.client.run("upload pkg/1.1@lasote/stable --all -c --remote remote1")
     self.client.run("remove -f pkg/1.1@lasote/stable")
     self.client.run("install pkg/1.1@lasote/stable")
     self.assertIn("pkg/1.1@lasote/stable: Package installed", self.client.out)
     self.client.run("remote list_ref")
     self.assertIn("pkg/1.1@lasote/stable: remote1", self.client.out)
     self.client.run("editable add . pkg/1.1@lasote/stable")
     # Check add --force, update and rename
     self.client.run("remote add remote2 %s --force" % self.servers["remote1"].fake_url)
     self.client.run("remote update remote2 %sfake" % self.servers["remote1"].fake_url)
     self.client.run("remote rename remote2 remote-fake")
     self.client.run("editable remove pkg/1.1@lasote/stable")
     # Check associated remote has changed name
     self.client.run("remote list_ref")
     self.assertIn("pkg/1.1@lasote/stable: remote-fake", self.client.out)
     # Check remove
     self.client.run("editable add . pkg/1.1@lasote/stable")
     self.client.run("remote remove remote-fake")
     self.client.run("remote list")
     self.assertIn("remote0: %s" % self.servers["remote0"].fake_url, self.client.out)
     self.assertNotIn("remote-fake", self.client.out)
     # Check clean
     self.client.run("editable remove pkg/1.1@lasote/stable")
     self.client.run("remove -f pkg/1.1@lasote/stable")
     self.client.run("remote add remote1 %s" % self.servers["remote1"].fake_url)
     self.client.run("install pkg/1.1@lasote/stable")
     self.client.run("editable add . pkg/1.1@lasote/stable")
     self.client.run("remote clean")
     self.client.run("remote list")
     self.assertNotIn("remote1", self.client.out)
     self.assertNotIn("remote0", self.client.out)
Example #25
0
def test_cmake_toolchain_win_toolset(compiler, version, update, runtime):
    client = TestClient(path_with_spaces=False)
    settings = {"compiler": compiler,
                "compiler.version": version,
                "compiler.update": update,
                "compiler.cppstd": "17",
                "compiler.runtime": runtime,
                "build_type": "Release",
                "arch": "x86_64"}

    # Build the profile according to the settings provided
    settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v)

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

    client.save({"conanfile.py": conanfile})
    client.run("install . {}".format(settings))
    toolchain = client.load("conan_toolchain.cmake")
    if update is not None:  # Fullversion
        value = "version=14.{}{}".format(version[-1], update)
    else:
        value = "v14{}".format(version[-1])
    assert 'set(CMAKE_GENERATOR_TOOLSET "{}" CACHE STRING "" FORCE)'.format(value) in toolchain
Example #26
0
    def test_custom_configuration_errors(self):
        client = TestClient()
        client.save({"conanfile.py": GenConanfile()})
        client.run("create . pkg/1.0@")

        conanfile = textwrap.dedent("""
            from conans import ConanFile
            from conan.tools.microsoft import MSBuildDeps
            class Pkg(ConanFile):
                settings = "os", "compiler", "arch", "build_type"
                requires = "pkg/1.0"
                def generate(self):
                    ms = MSBuildDeps(self)
                    ms.configuration = None
                    ms.generate()
            """)
        client.save({"conanfile.py": conanfile})

        client.run(
            'install . -s os=Windows -s compiler="Visual Studio"'
            ' -s compiler.version={vs_version}'
            ' -s compiler.runtime=MD'.format(vs_version=self.vs_version),
            assert_error=True)
        self.assertIn(
            "MSBuildDeps.configuration is None, it should have a value",
            client.out)
        client.save(
            {"conanfile.py": conanfile.replace("configuration", "platform")})

        client.run(
            'install . -s os=Windows -s compiler="Visual Studio"'
            ' -s compiler.version={vs_version}'
            ' -s compiler.runtime=MD'.format(vs_version=self.vs_version),
            assert_error=True)
        self.assertIn("MSBuildDeps.platform is None, it should have a value",
                      client.out)
Example #27
0
def test_same_conanfile_local(conanfile):
    client = TestClient()
    client.save({"conanfile.py": GenConanfile()})
    client.run("create . base/1.0@")

    client.save({"conanfile.py": conanfile})

    source_folder = os.path.join(client.current_folder, "my_sources")
    build_folder = os.path.join(client.current_folder, "my_build")

    client.run("install . lib/1.0@ -if=install")
    client.run("source .  -if=install")
    assert "Source folder: {}".format(source_folder) in client.out
    assert os.path.exists(os.path.join(source_folder, "source.h"))

    client.run("build .  -if=install")
    assert "Build folder: {}".format(build_folder) in client.out
    assert os.path.exists(os.path.join(build_folder, "build.lib"))

    client.run("package .  -if=install")
    # By default, the "package" folder is still used (not breaking)
    pf = os.path.join(client.current_folder, "package")
    assert "Package folder: {}".format(pf) in client.out
    assert os.path.exists(os.path.join(pf, "LICENSE"))
Example #28
0
def test_frameworks():
    client = TestClient(path_with_spaces=False)

    client.save({
        "hello.py":
        GenConanfile().with_settings(
            "os", "arch", "compiler", "build_type").with_package_info(
                cpp_info={"frameworks": ['CoreFoundation']}, env_info={})
    })
    client.run("export hello.py hello/0.1@")

    main = textwrap.dedent("""
        #include <CoreFoundation/CoreFoundation.h>
        int main(int argc, char *argv[]) {
            CFShow(CFSTR("Hello!"));
        }
        """)

    project_name = "app"
    client.save(
        {
            "conanfile.txt": "[requires]\nhello/0.1\n",
            "main.cpp": main,
            "project.yml": xcode_project
        },
        clean_first=True)

    client.run(
        "install . -s build_type=Release -s arch=x86_64 --build=missing -g XcodeDeps"
    )
    client.run_command("xcodegen generate")
    client.run_command(
        "xcodebuild -project app.xcodeproj -configuration Release -arch x86_64"
    )
    client.run_command("./build/Release/{}".format(project_name))
    assert "Hello!" in client.out
Example #29
0
def test_xcodedeps_dashes_names_and_arch():
    # https://github.com/conan-io/conan/issues/9949
    client = TestClient(path_with_spaces=False)
    client.save({
        "conanfile.py":
        GenConanfile().with_name("hello-dashes").with_version("0.1")
    })
    client.run("export .")
    main = "int main(int argc, char *argv[]) { return 0; }"
    client.save(
        {
            "conanfile.txt": "[requires]\nhello-dashes/0.1\n",
            "main.cpp": main,
            "project.yml": xcode_project
        },
        clean_first=True)
    client.run("install . -s arch=armv8 --build=missing -g XcodeDeps")
    assert os.path.exists(
        os.path.join(
            client.current_folder,
            "conan_hello_dashes_hello_dashes_vars_release_arm64.xcconfig"))
    client.run_command("xcodegen generate")
    client.run_command("xcodebuild -project app.xcodeproj -arch arm64")
    assert "BUILD SUCCEEDED" in client.out
Example #30
0
def test_ninja_conf():
    conanfile = GenConanfile().with_generator("CMakeToolchain").with_settings("os", "compiler",
                                                                              "build_type", "arch")
    profile = textwrap.dedent("""
        [settings]
        os=Windows
        compiler=msvc
        compiler.version=19.1
        compiler.runtime=dynamic
        compiler.cppstd=14
        build_type=Release
        arch=x86_64
        [conf]
        tools.cmake.cmaketoolchain:generator=Ninja
        """)
    client = TestClient()
    client.save({"conanfile.py": conanfile,
                 "profile": profile})
    client.run("install . -pr=profile")
    conanbuild = client.load("conanbuild.json")
    assert '"cmake_generator": "Ninja"' in conanbuild
    if platform.system() == "Windows":
        vcvars = client.load("conanvcvars.bat")
        assert "2017" in vcvars