Ejemplo n.º 1
0
def test_invalid_target_triple():
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({"os": "Linux", "arch": "UNKNOWN_ARCH"})
    conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
    with pytest.raises(ConanException) as excinfo:
        AutotoolsToolchain(conanfile)
    assert "Unknown 'UNKNOWN_ARCH' machine, Conan doesn't know how " \
           "to translate it to the GNU triplet," in str(excinfo)
Ejemplo n.º 2
0
    def test_sysroot_flag(self):
        sysroot = sysroot_flag(sysroot=None, settings=MockSettings({}))
        self.assertEqual(sysroot, "")

        sysroot = sysroot_flag(sysroot='sys/root',
                               settings=MockSettings({"compiler": "Visual Studio"}))
        self.assertEqual(sysroot, "")

        sysroot = sysroot_flag(sysroot='sys/root', settings=MockSettings({}))
        self.assertEqual(sysroot, "--sysroot=sys/root")
Ejemplo n.º 3
0
    def test_adjust_path(self):
        settings = MockSettings({"compiler": 'gcc'})
        self.assertEqual('home/www', adjust_path('home\\www',
                                                 MockSettings({})))
        self.assertEqual('home/www', adjust_path('home\\www', settings))

        self.assertEqual('"home/www root"',
                         adjust_path('home\\www root', MockSettings({})))
        self.assertEqual('"home/www root"',
                         adjust_path('home\\www root', settings))
Ejemplo n.º 4
0
    def test_cross_build_command(self):
        runner = RunnerMock()
        conanfile = MockConanfile(MockSettings({}), None, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        self.assertFalse(ab.build)
        self.assertFalse(ab.host)
        self.assertFalse(ab.target)

        ab.configure()
        self.assertEqual(runner.command_called, "./configure  ")

        ab.configure(host="x86_64-apple-darwin")
        self.assertEqual(runner.command_called, "./configure  --host=x86_64-apple-darwin")

        ab.configure(build="arm-apple-darwin")
        self.assertEqual(runner.command_called, "./configure  --build=arm-apple-darwin")

        ab.configure(target="i686-apple-darwin")
        self.assertEqual(runner.command_called, "./configure  --target=i686-apple-darwin")

        conanfile = MockConanfile(MockSettings({"build_type": "Debug",
                                                "arch": "x86_64",
                                                "os": "Windows",
                                                "compiler": "gcc",
                                                "compiler.libcxx": "libstdc++"}),
                                  None, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        ab.configure()
        if platform.system() == "Windows":
            # Not crossbuilding
            self.assertFalse(ab.host)
            self.assertFalse(ab.build)
            self.assertIn("./configure", runner.command_called)
            self.assertNotIn("--build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32",
                             runner.command_called)
        elif platform.system() == "Linux":
            self.assertIn("x86_64-w64-mingw32", ab.host)
            self.assertIn("x86_64-linux-gnu", ab.build)
            self.assertIn("./configure  --build=x86_64-linux-gnu --host=x86_64-w64-mingw32",
                          runner.command_called)
        else:
            self.assertIn("x86_64-w64-mingw32", ab.host)
            self.assertIn("x86_64-apple-darwin", ab.build)
            self.assertIn("./configure  --build=x86_64-apple-darwin --host=x86_64-w64-mingw32",
                          runner.command_called)

        ab.configure(build="fake_build_triplet", host="fake_host_triplet")
        self.assertIn("./configure  --build=fake_build_triplet --host=fake_host_triplet",
                      runner.command_called)

        ab.build = "superfake_build_triplet"
        ab.host = "superfake_host_triplet"
        ab.configure()
        self.assertIn("./configure  --build=superfake_build_triplet --host=superfake_host_triplet",
                      runner.command_called)
Ejemplo n.º 5
0
def test_cppstd():
    # Using "cppstd" is discarded
    conanfile = ConanFileMock()
    conanfile.settings = MockSettings({
        "build_type": "Release",
        "arch": "x86",
        "compiler": "gcc",
        "compiler.libcxx": "libstdc++11",
        "compiler.version": "7.1",
        "cppstd": "17"
    })
    be = AutotoolsToolchain(conanfile)
    env = be.vars()
    assert "-std=c++17" not in env["CXXFLAGS"]

    # Using "compiler.cppstd" works
    conanfile.settings = MockSettings({
        "build_type": "Release",
        "arch": "x86",
        "compiler": "gcc",
        "compiler.libcxx": "libstdc++11",
        "compiler.version": "7.1",
        "compiler.cppstd": "17"
    })
    be = AutotoolsToolchain(conanfile)
    env = be.vars()
    assert "-std=c++17" in env["CXXFLAGS"]

    # With visual
    conanfile.settings = MockSettings({
        "build_type": "Release",
        "arch": "x86",
        "compiler": "Visual Studio",
        "compiler.version": "14",
        "compiler.cppstd": "17"
    })
    be = AutotoolsToolchain(conanfile)
    env = be.vars()
    assert "/std:c++latest" in env["CXXFLAGS"]

    # With MSVC
    conanfile.settings = MockSettings({
        "build_type": "Release",
        "arch": "x86",
        "compiler": "msvc",
        "compiler.version": "193",
        "compiler.cppstd": "17"
    })
    be = AutotoolsToolchain(conanfile)
    env = be.vars()
    assert "/std:c++17" in env["CXXFLAGS"]
Ejemplo n.º 6
0
def test_ndebug():
    conanfile = ConanFileMock()
    for bt in ['Release', 'RelWithDebInfo', 'MinSizeRel']:
        conanfile.settings = MockSettings({"build_type": bt})
        be = AutotoolsToolchain(conanfile)
        assert be.ndebug == "NDEBUG"
        env = be.vars()
        assert "-DNDEBUG" in env["CPPFLAGS"]
    for bt in ['Debug', 'DebWithDebInfo']:
        conanfile.settings = MockSettings({"build_type": bt})
        be = AutotoolsToolchain(conanfile)
        assert be.ndebug is None
        env = be.vars()
        assert "-DNDEBUG" not in env["CPPFLAGS"]
Ejemplo n.º 7
0
    def test_pic_flags(self):
        flag = pic_flag(MockSettings({}))
        self.assertEqual(flag, '')

        flags = pic_flag(MockSettings({"compiler": 'gcc'}))
        self.assertEqual(flags, '-fPIC')

        flags = pic_flag(MockSettings({"compiler": 'Visual Studio'}))
        self.assertEqual(flags, "")

        flags = pic_flag(MockSettings({"compiler": 'intel', "compiler.base": "gcc"}))
        self.assertEqual(flags, '-fPIC')

        flags = pic_flag(MockSettings({"compiler": 'intel', "compiler.base": "Visual Studio"}))
        self.assertEqual(flags, '')
Ejemplo n.º 8
0
    def test_convert_target_platform(self):
        conanfile = MockConanfileWithFolders(MockSettings({'compiler': 'gcc'}))

        qbs_toolchain = qbs.QbsToolchain(conanfile)
        self.assertEqual(qbs_toolchain._target_platform, None)

        for os, target_platform in qbs._target_platform.items():
            conanfile = MockConanfileWithFolders(
                MockSettings({
                    'os': os,
                    'compiler': 'gcc'
                }))

            qbs_toolchain = qbs.QbsToolchain(conanfile)
            self.assertEqual(qbs_toolchain._target_platform, target_platform)
Ejemplo n.º 9
0
    def test_read_qbs_toolchain_from_qbs_config_output(self):
        expected_config = {
            'cpp.cCompilerName': '"gcc"',
            'cpp.compilerName': '"g++"',
            'cpp.cxxCompilerName': '"g++"',
            'cpp.driverFlags':
            '["-march=armv7e-m", "-mtune=cortex-m4", "--specs=nosys.specs"]',
            'cpp.platformCommonCompilerFlags': 'undefined',
            'cpp.platformLinkerFlags': 'undefined',
            'cpp.toolchainInstallPath': '"/usr/bin"',
            'cpp.toolchainPrefix': '"arm-none-eabi-"',
            'qbs.someBoolProp': 'true',
            'qbs.someIntProp': '13',
            'qbs.toolchain': '["gcc"]'
        }

        conanfile = MockConanfileWithFolders(
            MockSettings({}),
            runner=RunnerMock(expectations=[
                RunnerMock.Expectation(
                    output=self._generate_qbs_config_output())
            ]))
        config = qbs._read_qbs_toolchain_from_config(conanfile)
        self.assertEqual(len(conanfile.runner.command_called), 1)
        self.assertEqual(
            conanfile.runner.command_called[0],
            'qbs-config --settings-dir "%s" --list' %
            (qbs._settings_dir(conanfile)))
        self.assertEqual(config, expected_config)
Ejemplo n.º 10
0
 def test_negative(self):
     self.assertIsNone(
         tools.msvs_toolset(
             MockSettings({
                 "compiler": "Visual Studio",
                 "compiler.version": "666"
             })))
Ejemplo n.º 11
0
 def test_custom(self, compiler_version, expected_toolset):
     settings = MockSettings({
         "compiler": "Visual Studio",
         "compiler.version": compiler_version,
         "compiler.toolset": expected_toolset
     })
     self.assertEqual(expected_toolset, tools.msvs_toolset(settings))
 def test_solaris(self):
     with mock.patch("platform.system", mock.MagicMock(return_value='SunOS')), \
          mock.patch("platform.machine", mock.MagicMock(return_value="x86_64")):
         conanfile = MockConanfile(MockSettings({}))
         build_os, build_arch, _, _ = get_cross_building_settings(conanfile)
         self.assertEqual("SunOS", build_os)
         self.assertEqual("x86_64", build_arch)
Ejemplo n.º 13
0
 def test_arch_flag(self, compiler, arch, the_os, flag):
     settings = MockSettings({
         "compiler": compiler,
         "arch": arch,
         "os": the_os
     })
     self.assertEqual(architecture_flag(settings), flag)
Ejemplo n.º 14
0
    def test_read_qbs_toolchain_from_qbs_config_output_msvc(self):
        expected_config = {
            'cpp.compilerVersion': '"19.28.29333"',
            'cpp.toolchainInstallPath':
            '"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64"',
            'qbs.architecture': '"x86_64"',
            'qbs.targetPlatform': '"windows"',
            'qbs.toolchainType': '"msvc"',
            'cpp.driverFlags':
            '["-march=armv7e-m", "-mtune=cortex-m4", "--specs=nosys.specs"]',
            'qbs.someBoolProp': 'true',
            'qbs.someIntProp': '13',
        }

        conanfile = MockConanfileWithFolders(
            MockSettings({}),
            runner=RunnerMock(expectations=[
                RunnerMock.Expectation(
                    output=self._generate_qbs_config_output_msvc())
            ]))
        config = qbs._read_qbs_toolchain_from_config(conanfile)
        self.assertEqual(len(conanfile.runner.command_called), 1)
        self.assertEqual(
            conanfile.runner.command_called[0],
            'qbs-config --settings-dir "%s" --list' %
            (qbs._settings_dir(conanfile)))
        self.assertEqual(config, expected_config)
Ejemplo n.º 15
0
 def test_construct_build_helper_without_project_file(self):
     conanfile = MockConanfile(
         MockSettings({'os': 'Linux', 'compiler': 'gcc'}))
     conanfile.source_folder = '.'
     build_helper = qbs.Qbs(conanfile)
     self.assertEqual(build_helper.jobs, tools.cpu_count())
     self.assertEqual(build_helper._project_file, conanfile.source_folder)
Ejemplo n.º 16
0
 def test_rpath_optin(self):
     settings = MockSettings({
         "os_build": "Linux",
         "build_type": "Release",
         "arch": "x86_64",
         "compiler": "gcc",
         "compiler.libcxx": "libstdc++11"
     })
     conanfile = MockConanfile(settings)
     conanfile.settings = settings
     self._set_deps_info(conanfile)
     expected = {
         'CFLAGS':
         'a_c_flag -m64 -O3 -s --sysroot=/path/to/folder',
         'CPPFLAGS':
         '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG '
         '-D_GLIBCXX_USE_CXX11_ABI=1',
         'CXXFLAGS':
         'a_c_flag -m64 -O3 -s --sysroot=/path/to/folder a_cxx_flag',
         'LDFLAGS':
         'shared_link_flag exe_link_flag -framework oneframework -framework twoframework '
         '-F one/framework/path -m64 --sysroot=/path/to/folder '
         '-Wl,-rpath,"one/lib/path" -Lone/lib/path',
         'LIBS':
         '-lonelib -ltwolib -lonesystemlib -ltwosystemlib'
     }
     be = AutoToolsBuildEnvironment(conanfile, include_rpath_flags=True)
     self.assertEqual(be.vars, expected)
Ejemplo n.º 17
0
    def test_modify_values(self):
        settings = MockSettings({
            "build_type": "Debug",
            "arch": "x86_64",
            "compiler": "gcc",
            "compiler.libcxx": "libstdc++"
        })
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        be = AutoToolsBuildEnvironment(conanfile)

        # Alter some things
        be.defines.append("OtherDefinition=23")
        be.link_flags = ["-inventedflag"]
        be.cxx_flags.append("-onlycxx")
        be.fpic = True
        be.flags.append("cucucu")

        expected = {
            'CFLAGS':
            'a_c_flag -m64 -g --sysroot=/path/to/folder cucucu -fPIC',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition'
            ' -D_GLIBCXX_USE_CXX11_ABI=0 -DOtherDefinition=23',
            'CXXFLAGS':
            'a_c_flag -m64 -g --sysroot=/path/to/folder cucucu -fPIC a_cxx_flag -onlycxx',
            'LDFLAGS':
            '-inventedflag -Lone/lib/path',
            'LIBS':
            '-lonelib -ltwolib -lonesystemlib -ltwosystemlib'
        }
        self.assertEqual(be.vars, expected)
Ejemplo n.º 18
0
    def test_environment_append(self):
        settings = MockSettings({"build_type": "Debug",
                                 "arch": "x86_64",
                                 "compiler": "gcc",
                                 "compiler.libcxx": "libstdc++"})
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        env_vars = {"CFLAGS": "-additionalcflag",
                    "CXXFLAGS": "-additionalcxxflag",
                    "LDFLAGS": "-additionalldflag",
                    "LIBS": "-additionallibs",
                    "CPPFLAGS": "-additionalcppflag"}

        with(tools.environment_append(env_vars)):
            be = AutoToolsBuildEnvironment(conanfile)
            expected = {'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -'
                                    'Dtwodefinition -D_GLIBCXX_USE_CXX11_ABI=0 -additionalcppflag',
                        'CXXFLAGS': 'a_c_flag -m64 -g --sysroot=/path/to/folder a_cxx_flag -additionalcxxflag',
                        'LIBS': '-lonelib -ltwolib -lonesystemlib -ltwosystemlib -additionallibs',
                        'LDFLAGS': 'shared_link_flag exe_link_flag -framework oneframework '
                                   '-framework twoframework -F one/framework/path -m64 '
                                   '--sysroot=/path/to/folder -Lone/lib/path -additionalldflag',
                        'CFLAGS': 'a_c_flag -m64 -g --sysroot=/path/to/folder -additionalcflag'}
            self.assertEqual(be.vars, expected)
Ejemplo n.º 19
0
def _make_cppstd_flag(compiler, compiler_version, cppstd=None, compiler_base=None):
    settings = MockSettings({"compiler": compiler,
                             "compiler.version": compiler_version,
                             "compiler.cppstd": cppstd})
    if compiler_base:
        settings.values["compiler.base"] = compiler_base
    return cppstd_flag(settings)
Ejemplo n.º 20
0
 def test_arch_flag_mcst_lcc(self, arch, flag):
     settings = MockSettings({
         "compiler": "mcst-lcc",
         "compiler.base": "gcc",
         "arch": arch
     })
     self.assertEqual(architecture_flag(settings), flag)
Ejemplo n.º 21
0
 def test_arch_flag_intel(self, base, arch, flag):
     settings = MockSettings({
         "compiler": "intel",
         "compiler.base": base,
         "arch": arch
     })
     self.assertEqual(architecture_flag(settings), flag)
Ejemplo n.º 22
0
    def test_skip_toolset(self):
        settings = MockSettings({"build_type": "Debug",
                                 "compiler": "Visual Studio",
                                 "compiler.version": "15",
                                 "arch": "x86_64"})

        class Runner(object):

            def __init__(self):
                self.commands = []

            def __call__(self, *args, **kwargs):
                self.commands.append(args[0])

        with chdir(tools.mkdir_tmp()):
            runner = Runner()
            conanfile = MockConanfile(settings, runner=runner)
            msbuild = MSBuild(conanfile)
            msbuild.build("myproject", toolset=False)
            self.assertEqual(len(runner.commands), 1)
            self.assertNotIn("PlatformToolset", runner.commands[0])

            runner = Runner()
            conanfile = MockConanfile(settings, runner=runner)
            msbuild = MSBuild(conanfile)
            msbuild.build("myproject", toolset="mytoolset")
            self.assertEqual(len(runner.commands), 1)
            self.assertIn('/p:PlatformToolset="mytoolset"', runner.commands[0])
Ejemplo n.º 23
0
    def test_convert_runtime_library(self):
        conanfile = MockConanfileWithFolders(
            MockSettings({'compiler': 'Visual Studio'}))

        qbs_toolchain = qbs.QbsProfile(conanfile)
        self.assertEqual(qbs_toolchain._runtime_library, None)

        for runtime, runtime_library in qbs._runtime_library.items():
            conanfile = MockConanfileWithFolders(
                MockSettings({
                    'compiler': 'Visual Studio',
                    'compiler.runtime': runtime
                }))

            qbs_toolchain = qbs.QbsProfile(conanfile)
            self.assertEqual(qbs_toolchain._runtime_library, runtime_library)
Ejemplo n.º 24
0
    def toolset_test(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            new_out = StringIO()
            command = build_sln_command(MockSettings({
                "compiler": "Visual Studio",
                "compiler.version": "17",
                "build_type": "Debug",
                "compiler.runtime": "MDd",
                "cppstd": "17"
            }),
                                        sln_path='dummy.sln',
                                        targets=None,
                                        upgrade_project=False,
                                        build_type='Debug',
                                        arch='armv7',
                                        parallel=False,
                                        toolset="v110",
                                        output=ConanOutput(new_out))

            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))

        self.assertTrue(
            command.startswith('msbuild "dummy.sln" /p:Configuration="Debug" '
                               '/p:UseEnv=false '
                               '/p:Platform="ARM" '
                               '/p:PlatformToolset="v110" '
                               '/verbosity:minimal '
                               '/p:ForceImportBeforeCppTargets='), command)
Ejemplo n.º 25
0
    def test_autotools_configure_vars(self):
        from mock import patch

        runner = RunnerMock()
        settings = MockSettings({"build_type": "Debug",
                                 "arch": "x86_64",
                                 "compiler": "gcc",
                                 "compiler.libcxx": "libstdc++"})
        conanfile = MockConanfile(settings, None, runner)
        conanfile.settings = settings
        self._set_deps_info(conanfile)

        def custom_configure(obj, configure_dir=None, args=None, build=None, host=None, target=None,
                             pkg_config_paths=None, vars=None):  # @UnusedVariable
            self.assertNotEqual(obj.vars, vars)
            return vars or obj.vars

        with patch.object(AutoToolsBuildEnvironment, 'configure', new=custom_configure):
            be = AutoToolsBuildEnvironment(conanfile)

            # Get vars and modify them
            my_vars = be.vars
            my_vars["fake_var"] = "fake"
            my_vars["super_fake_var"] = "fakefake"

            # TEST with default vars
            mocked_result = be.configure()
            self.assertEqual(mocked_result, be.vars)

            # TEST with custom vars
            mocked_result = be.configure(vars=my_vars)
            self.assertEqual(mocked_result, my_vars)
Ejemplo n.º 26
0
 def test_build_type_flags(self, compiler, build_type, vs_toolset, flags):
     settings = MockSettings({
         "compiler": compiler,
         "build_type": build_type,
         "compiler.toolset": vs_toolset
     })
     self.assertEqual(' '.join(build_type_flags(settings)), flags)
Ejemplo n.º 27
0
 def test_build_with_custom_configuration(self):
     conanfile = MockConanfile(
         MockSettings({'os': 'Linux', 'compiler': 'gcc'}),
         runner=RunnerMock())
     conanfile.source_folder = '.'
     conanfile.build_folder = '.'
     build_helper = qbs.Qbs(conanfile)
     config_name = 'debug'
     config_values = {
         'product.App.boolProperty': True,
         'product.App.intProperty': 1337,
         'product.App.stringProperty': 'Hello World',
         'product.App.stringListProperty': ['Hello', 'World']
     }
     build_helper.add_configuration(config_name, config_values)
     build_helper.build()
     self.assertEqual(
         conanfile.runner.command_called,
         ('qbs build --no-install --build-directory %s '
          '--file %s --jobs %s profile:%s '
          'config:%s %s:%s %s:%s %s:%s %s:%s') % (
             conanfile.build_folder, build_helper._project_file,
             build_helper.jobs, build_helper.use_toolchain_profile,
             config_name,
             'product.App.boolProperty',
             'true',
             'product.App.intProperty',
             config_values['product.App.intProperty'],
             'product.App.stringProperty',
             config_values['product.App.stringProperty'],
             'product.App.stringListProperty',
             config_values['product.App.stringListProperty']))
Ejemplo n.º 28
0
 def test_target_triple(self):
     conan_file = ConanFileMock()
     conan_file.deps_cpp_info = self._creat_deps_cpp_info()
     conan_file.settings = MockSettings({"os_target":"Linux", "arch_target":"x86_64"})
     be = AutoToolsBuildEnvironment(conan_file)
     expected = "x86_64-linux-gnu"
     self.assertEqual(be.target, expected)
Ejemplo n.º 29
0
 def test_construct_build_helper_with_project_file(self):
     conanfile = MockConanfile(
         MockSettings({'os': 'Linux', 'compiler': 'gcc'}))
     # just asume that the test is called from repo root
     profile_file_path = temp_folder()
     build_helper = qbs.Qbs(conanfile, project_file=profile_file_path)
     self.assertEqual(build_helper._project_file, profile_file_path)
Ejemplo n.º 30
0
 def test_warn_when_no_triplet(self):
     conan_file = ConanFileMock()
     conan_file.deps_cpp_info = self._creat_deps_cpp_info()
     conan_file.settings = MockSettings({"arch": "UNKNOWN_ARCH", "os": "Linux"})
     AutoToolsBuildEnvironment(conan_file)
     self.assertIn("Unknown 'UNKNOWN_ARCH' machine, Conan doesn't know "
                   "how to translate it to the GNU triplet", conan_file.output)