Exemple #1
0
    def use_wrong_setting_for_compiler_test(self):
        client = TestClient()

        conanfile = """from conans import ConanFile

class TestConan(ConanFile):
    name = "MyLib"
    version = "0.1"
    settings = "compiler", "cppstd"

"""
        client.save({CONANFILE: conanfile})
        with catch_deprecation_warning(self):
            client.run(
                'create . user/testing -s compiler="gcc" '
                '-s compiler.libcxx="libstdc++11" '
                '-s compiler.version="4.6" -s cppstd=17',
                assert_error=True)

        self.assertIn(
            "The specified 'cppstd=17' is not available for 'gcc 4.6'",
            client.out)
        self.assertIn("Possible values are ['11', '98', 'gnu11', 'gnu98']",
                      client.out)

        with catch_deprecation_warning(self):
            client.run(
                'create . user/testing -s compiler="gcc" -s compiler.libcxx="libstdc++11" '
                '-s compiler.version="6.3" -s cppstd=17')
Exemple #2
0
    def test_std_flag_applied(self):
        conanfile = """
import os
from conans import ConanFile, CMake
class MyLib(ConanFile):
    name = "MyLib"
    version = "0.1"
    settings = "arch", "compiler", "cppstd"
    generators = "cmake"

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()
        """
        client = TestClient()
        client.save({
            "conanfile.py":
            conanfile,
            "mylib.cpp":
            "auto myfunc(){return 3;}",  # c++14 feature
            "CMakeLists.txt":
            """
cmake_minimum_required(VERSION 2.8.12)
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_ABI_COMPILED 1)
project(MyHello CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_library(mylib mylib.cpp)
target_link_libraries(mylib ${CONAN_LIBS})
"""
        })

        if platform.system() != "Windows":
            with catch_deprecation_warning(self):
                client.run("install . --install-folder=build -s cppstd=gnu98")
            client.run("build . --build-folder=build", assert_error=True)
            self.assertIn("Error in build()", client.out)

            # Now specify c++14
            with catch_deprecation_warning(self):
                client.run("install . --install-folder=build -s cppstd=gnu14")
            client.run("build . --build-folder=build")
            self.assertIn("CPP STANDARD: 14 WITH EXTENSIONS ON", client.out)
            libname = "libmylib.a" if platform.system(
            ) != "Windows" else "mylib.lib"
            libpath = os.path.join(client.current_folder, "build", "lib",
                                   libname)
            self.assertTrue(os.path.exists(libpath))

        with catch_deprecation_warning(self):
            client.run("install . --install-folder=build -s cppstd=14")
        client.run("build . --build-folder=build")
        self.assertIn("CPP STANDARD: 14 WITH EXTENSIONS OFF", client.out)
        self.assertNotIn("Conan setting CXX_FLAGS flags", client.out)
        libname = "libmylib.a" if platform.system(
        ) != "Windows" else "mylib.lib"
        libpath = os.path.join(client.current_folder, "build", "lib", libname)
        self.assertTrue(os.path.exists(libpath))
Exemple #3
0
    def test_standard_20_as_cxx_flag(self):
        # CMake (1-Jun-2018) do not support the 20 flag in CMAKE_CXX_STANDARD var
        conanfile = """
import os
from conans import ConanFile, CMake
class MyLib(ConanFile):
    name = "MyLib"
    version = "0.1"
    settings = "arch", "compiler", "cppstd"
    exports_sources = "CMakeLists.txt"
    generators = "cmake"

    def build(self):
        cmake = CMake(self)
        cmake.configure()
"""
        cmakelists = """
cmake_minimum_required(VERSION 2.8.12)
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_ABI_COMPILED 1)
project(MyHello CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_set_std()
"""
        client = TestClient()
        client.save({"conanfile.py": conanfile, "CMakeLists.txt": cmakelists})

        def conan_set_std_branch():
            # Replicate logic from cmake_common definition of 'macro(conan_set_std)'
            cmake_version = CMakeBuildHelper.get_version()
            return cmake_version < Version("3.12")

        with catch_deprecation_warning(self):
            client.run("create . user/channel -s cppstd=gnu20 -s compiler=gcc "
                       "-s compiler.version=8 -s compiler.libcxx=libstdc++11")
        if conan_set_std_branch():
            self.assertIn("Conan setting CXX_FLAGS flags: -std=gnu++2a",
                          client.out)
        else:
            self.assertIn("Conan setting CPP STANDARD: 20 WITH EXTENSIONS ON",
                          client.out)

        with catch_deprecation_warning(self):
            client.run(
                "create . user/channel -s cppstd=20 -s compiler=gcc -s compiler.version=8 "
                "-s compiler.libcxx=libstdc++11")
        if conan_set_std_branch():
            self.assertIn("Conan setting CXX_FLAGS flags: -std=c++2a",
                          client.out)
        else:
            self.assertIn("Conan setting CPP STANDARD: 20 WITH EXTENSIONS OFF",
                          client.out)
Exemple #4
0
    def test_custom_compiler_preprocessor(self):
        # https://github.com/conan-io/conan/issues/3842
        settings = """compiler:
    mycomp:
        version: ["2.3", "2.4"]
cppstd: [None, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20]
"""
        client = TestClient()
        save(client.cache.settings_path, settings)
        save(client.cache.default_profile_path, """[settings]
compiler=mycomp
compiler.version=2.3
cppstd=11
""")
        conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    settings = "compiler", "cppstd"
"""
        client.save({"conanfile.py": conanfile})
        with catch_deprecation_warning(self):
            client.run("create . Pkg/0.1@lasote/testing")
        self.assertIn(
            """Configuration:
[settings]
compiler=mycomp
compiler.version=2.3
cppstd=11""", client.out)
        self.assertIn(
            "Pkg/0.1@lasote/testing: Package "
            "'c2f0c2641722089d9b11cd646c47d239af044b5a' created", client.out)
 def test_value_non_default(self):
     # Explicit value (not the default) passed to setting 'cppstd'
     with catch_deprecation_warning(self):
         id_with, output = self._get_id(with_cppstd=True, settings_values={"cppstd": "14"})
     self.assertIn(">>>> settings: ['compiler', 'cppstd', 'os']", output)
     self.assertIn(">>>> cppstd: 14", output)
     self.assertIn(">>>> compiler.cppstd: None", output)
     self.assertNotEqual(self.id_default, id_with)
Exemple #6
0
    def test_value_from_cppstd(self):
        self._save_profile(cppstd="11")

        r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
        with catch_deprecation_warning(self):
            r.process_settings(self.cache)
        self.assertNotIn('compiler.cppstd', r.settings)
        self.assertEqual(r.settings["cppstd"], "11")
Exemple #7
0
    def set_default_package_id_test(self):
        client = TestClient()
        conanfile = """from conans import ConanFile

class TestConan(ConanFile):
    name = "MyLib"
    version = "0.1"
    settings = "compiler", %s

    def build(self):
        self.output.warn("BUILDING!")
"""
        # Without the setting
        client.save({CONANFILE: conanfile % ""})
        client.run(
            'create . user/testing -s compiler="gcc" -s compiler.version="7.1" '
            '-s compiler.libcxx="libstdc++" '
            '--build missing')
        self.assertIn("BUILDING!", client.out)

        # Add the setting but with the default value, should not build again
        client.save({CONANFILE: conanfile % '"cppstd"'})  # With the setting
        with catch_deprecation_warning(self):
            client.run(
                'create . user/testing -s compiler="gcc" -s compiler.version="7.1" '
                '-s compiler.libcxx="libstdc++" '
                '-s cppstd=gnu14 '
                '--build missing')

        if client.cache.config.revisions_enabled:
            self.assertIn(
                "doesn't belong to the installed recipe revision, removing folder",
                client.out)
            self.assertIn("BUILDING!", client.out)
        else:
            self.assertNotIn("BUILDING!", client.out)

        # Add the setting but with a non-default value, should build again
        client.save({CONANFILE: conanfile % '"cppstd"'})  # With the setting
        with catch_deprecation_warning(self):
            client.run(
                'create . user/testing -s compiler="gcc" -s compiler.version="7.1" '
                '-s compiler.libcxx="libstdc++" '
                '-s cppstd=gnu17 '
                '--build missing')
        self.assertIn("BUILDING!", client.out)
 def test_value_default(self):
     # Explicit value (equals to default) passed to setting 'cppstd'
     cppstd = _make_cppstd_default(self.compiler, self.compiler_version)
     with catch_deprecation_warning(self):
         id_with, output = self._get_id(with_cppstd=True, settings_values={"cppstd": cppstd})
     self.assertIn(">>>> settings: ['compiler', 'cppstd', 'os']", output)
     self.assertIn(">>>> cppstd: gnu14", output)
     self.assertIn(">>>> compiler.cppstd: None", output)
     self.assertEqual(self.id_default, id_with)
Exemple #9
0
    def test_value_different(self):
        self._save_profile(cppstd="14", compiler_cppstd="11")

        r = profile_from_args(["default", ], [], [], [], cwd=self.tmp_folder, cache=self.cache)
        with six.assertRaisesRegex(self, ConanException, "Do not use settings 'compiler.cppstd'"
                                                         " together with 'cppstd'. Use only the"
                                                         " former one"):
            with catch_deprecation_warning(self):
                r.process_settings(self.cache)
    def test_standard_version_default_matching(self):
        self._export("Hello",
                     "1.2.0",
                     channel="user/testing",
                     settings=[
                         "compiler",
                     ])

        self.client.run('install Hello/1.2.0@user/testing '
                        ' -s compiler="gcc" -s compiler.libcxx=libstdc++11'
                        ' -s compiler.version=7.2 --build')

        self._export("Hello",
                     "1.2.0",
                     channel="user/testing",
                     settings=[
                         "compiler",
                         "cppstd",
                     ])

        with catch_deprecation_warning(self):
            self.client.run(
                'info Hello/1.2.0@user/testing  -s compiler="gcc" '
                '-s compiler.libcxx=libstdc++11  -s compiler.version=7.2 '
                '-s cppstd=gnu14')
        with catch_deprecation_warning(self):
            self.client.run('install Hello/1.2.0@user/testing'
                            ' -s compiler="gcc" -s compiler.libcxx=libstdc++11'
                            ' -s compiler.version=7.2 -s cppstd=gnu14'
                            )  # Default, already built

        # Should NOT have binary available
        with catch_deprecation_warning(self):
            self.client.run(
                'install Hello/1.2.0@user/testing'
                ' -s compiler="gcc" -s compiler.libcxx=libstdc++11'
                ' -s compiler.version=7.2 -s cppstd=gnu11',
                assert_error=True)

        self.assertIn(
            "Missing prebuilt package for 'Hello/1.2.0@user/testing'",
            self.client.out)
 def test_value_different_with_general_setting(self):
     deprecation_number = 1 if self.recipe_cppstd else 0
     with catch_deprecation_warning(self, n=deprecation_number):
         self.t.run(
             "create . hh/0.1@user/channel"
             " -s cppstd=17"
             " -s hh:compiler=gcc"
             " -s hh:compiler.cppstd=14",
             assert_error=True)
     self.assertIn(
         "ERROR: Error in resulting settings for package 'hh': Do not use settings"
         " 'compiler.cppstd' together with 'cppstd'", self.t.out)
    def test_cppstd_non_defaults(self):
        cppstd_value = "14"  # Not the default
        with catch_deprecation_warning(self):
            id_with_old, _ = self._get_id(with_cppstd=True, settings_values={"cppstd": cppstd_value})
        id_with_new, _ = self._get_id(with_cppstd=False,
                                      settings_values={'compiler.cppstd': cppstd_value})

        # Those are different from the target one (ID using default value or None)
        self.assertNotEqual(self.id_default, id_with_old)
        self.assertNotEqual(self.id_default, id_with_new)

        # They are different between them
        self.assertNotEqual(id_with_new, id_with_old)
Exemple #13
0
    def test_gcc_8_std_20(self):
        client = TestClient()

        conanfile = """from conans import ConanFile

class TestConan(ConanFile):
    name = "MyLib"
    version = "0.1"
    settings = "compiler", "cppstd"

"""
        client.save({CONANFILE: conanfile})
        with catch_deprecation_warning(self):
            client.run('create . user/testing -s compiler="gcc" '
                       '-s compiler.libcxx="libstdc++11" '
                       '-s compiler.version="8" -s cppstd=20')
    def test_std_non_matching_with_cppstd(self):
        self._export("Hello",
                     "1.2.0",
                     package_id_text="self.info.default_std_non_matching()",
                     channel="user/testing",
                     settings='"compiler", "cppstd"')
        self.client.run('install Hello/1.2.0@user/testing'
                        ' -s compiler="gcc" -s compiler.libcxx=libstdc++11'
                        ' -s compiler.version=7.2 --build')

        with catch_deprecation_warning(self, n=1):
            self.client.run('install Hello/1.2.0@user/testing'
                            ' -s compiler="gcc" -s compiler.libcxx=libstdc++11'
                            ' -s compiler.version=7.2 -s cppstd=gnu14',
                            assert_error=True)  # Default
        self.assertIn(
            "Missing prebuilt package for 'Hello/1.2.0@user/testing'",
            self.client.out)
    def test_conanfile_without_compiler(self):
        conanfile = textwrap.dedent("""
            from conans import ConanFile

            class Lib(ConanFile):
                settings = "os", "arch"
        """)
        t = TestClient(base_folder=temp_folder())
        t.save({'conanfile.py': conanfile})

        with catch_deprecation_warning(self):
            # No mismatch, because settings for this conanfile does not include `compiler`
            t.run(
                "create . hh/0.1@user/channel"
                " -s cppstd=17"
                " -s hh:compiler=gcc"
                " -s hh:compiler.cppstd=14",
                assert_error=True)
        self.assertIn(
            "ERROR: Error in resulting settings for package 'hh': Do not use settings"
            " 'compiler.cppstd' together with 'cppstd'", t.out)
 def test_only_cppstd(self):
     with catch_deprecation_warning(self):
         self.t.run("info . -s cppstd=14")
     self.assertNotIn(">>> compiler.cppstd: 14", self.t.out)
     self.assertIn(">>> cppstd: 14", self.t.out)
     self.assertIn(">>> compiler.cppstd: None", self.t.out)
Exemple #17
0
    def build_vs_project_test(self):
        conan_build_vs = """
from conans import ConanFile, MSBuild

class HelloConan(ConanFile):
    name = "Hello"
    version = "1.2.1"
    exports = "*"
    settings = "os", "build_type", "arch", "compiler", "cppstd"

    def build(self):
        msbuild = MSBuild(self)
        msbuild.build("MyProject.sln", verbosity="normal")

    def package(self):
        self.copy(pattern="*.exe")
"""
        client = TestClient()

        # Test cpp standard stuff

        files = get_vs_project_files(std="cpp17_2015")
        files[CONANFILE] = conan_build_vs

        client.save(files)
        with catch_deprecation_warning(self):
            client.run(
                'create . Hello/1.2.1@lasote/stable -s cppstd=11 -s '
                'compiler="Visual Studio" -s compiler.version=14',
                assert_error=True)
        with catch_deprecation_warning(self):
            client.run('create . Hello/1.2.1@lasote/stable -s cppstd=17 '
                       '-s compiler="Visual Studio" -s compiler.version=14')
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)

        files = get_vs_project_files()
        files[CONANFILE] = conan_build_vs

        # Try to not update the project
        client.cache._config = None  # Invalidate cached config

        replace_in_file(client.cache.conan_conf_path,
                        "[general]",
                        "[general]\nskip_vs_projects_upgrade = True",
                        output=client.out)
        client.save(files, clean_first=True)
        client.run("create . Hello/1.2.1@lasote/stable --build")
        self.assertNotIn("devenv", client.user_io.out)
        self.assertIn("Skipped sln project upgrade", client.out)

        # Try with x86_64
        client.save(files)
        client.run("export . lasote/stable")
        client.run("install Hello/1.2.1@lasote/stable --build -s arch=x86_64")
        self.assertIn("Release|x64", client.user_io.out)
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)

        # Try with x86
        client.save(files, clean_first=True)
        client.run("export . lasote/stable")
        client.run("install Hello/1.2.1@lasote/stable --build -s arch=x86")
        self.assertIn("Release|x86", client.user_io.out)
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)

        # Try with x86 debug
        client.save(files, clean_first=True)
        client.run("export . lasote/stable")
        client.run(
            "install Hello/1.2.1@lasote/stable --build -s arch=x86 -s build_type=Debug"
        )
        self.assertIn("Debug|x86", client.user_io.out)
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)

        # Try with a custom property file name
        files[CONANFILE] = conan_build_vs.replace(
            'msbuild.build("MyProject.sln", verbosity="normal")',
            'msbuild.build("MyProject.sln", verbosity="normal", property_file_name="mp.props")'
        )
        client.save(files, clean_first=True)
        client.run(
            "create . Hello/1.2.1@lasote/stable --build -s arch=x86 -s build_type=Debug"
        )
        self.assertIn("Debug|x86", client.user_io.out)
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)
        full_ref = "Hello/1.2.1@lasote/stable:b786e9ece960c3a76378ca4d5b0d0e922f4cedc1"
        pref = PackageReference.loads(full_ref)
        build_folder = client.cache.package_layout(pref.ref).build(pref)
        self.assertTrue(os.path.exists(os.path.join(build_folder, "mp.props")))