Esempio n. 1
0
 def test_binary_logging_on(self):
     settings = MockSettings({
         "build_type": "Debug",
         "compiler": "Visual Studio",
         "compiler.version": "15",
         "arch": "x86_64",
         "compiler.runtime": "MDd"
     })
     conanfile = MockConanfile(settings)
     msbuild = MSBuild(conanfile)
     command = msbuild.get_command("dummy.sln", output_binary_log=True)
     self.assertIn("/bl", command)
Esempio n. 2
0
 def windows_ce_test(self):
     settings = MockSettings({
         "build_type": "Debug",
         "compiler": "Visual Studio",
         "compiler.version": "9",
         "os": "WindowsCE",
         "os.platform": "YOUR PLATFORM SDK (ARMV4)",
         "arch": "armv4"
     })
     conanfile = MockConanfile(settings)
     msbuild = MSBuild(conanfile)
     command = msbuild.get_command("test.sln")
     self.assertIn('/p:Platform="YOUR PLATFORM SDK (ARMV4)"', command)
Esempio n. 3
0
 def _create_conanfile(self, compiler, version, os, cppstd, libcxx=None):
     settings = MockSettings({
         "arch": "x86_64",
         "build_type": "Debug",
         "os": os,
         "compiler": compiler,
         "compiler.version": version,
         "compiler.cppstd": cppstd
     })
     if libcxx:
         settings.values["compiler.libcxx"] = libcxx
     conanfile = MockConanfile(settings)
     return conanfile
Esempio n. 4
0
def test_is_msvc_static_runtime(compiler, shared, runtime, build_type,
                                expected):
    options = MockOptions({"shared": shared})
    settings = MockSettings({
        "build_type": build_type,
        "arch": "x86_64",
        "compiler": compiler,
        "compiler.runtime": runtime,
        "compiler.version": "17",
        "cppstd": "17"
    })
    conanfile = MockConanfile(settings, options)
    assert is_msvc_static_runtime(conanfile) == expected
Esempio n. 5
0
    def test_make_targets_install(self):
        runner = RunnerMock()
        conanfile = MockConanfile(MockSettings({}), None, runner)

        ab = AutoToolsBuildEnvironment(conanfile)
        ab.configure()

        ab.make(target="install")
        self.assertEqual(runner.command_called, "make install -j%s" %
                          cpu_count(output=conanfile.output))
        ab.install()
        self.assertEqual(runner.command_called, "make install -j%s" %
                          cpu_count(output=conanfile.output))
Esempio n. 6
0
def test_unzip():
    tmp_dir = temp_folder()
    file_path = os.path.join(tmp_dir, "foo.txt")
    save(os.path.join(tmp_dir, "foo.txt"), "bar")
    zf = zipfile.ZipFile(os.path.join(tmp_dir, 'zipfile.zip'), mode='w')
    zf.write(file_path, basename(file_path))
    zf.close()

    conanfile = MockConanfile({})

    # Unzip and check permissions are kept
    dest_dir = temp_folder()
    unzip(conanfile, os.path.join(tmp_dir, 'zipfile.zip'), dest_dir)
    assert os.path.exists(os.path.join(dest_dir, "foo.txt"))
Esempio n. 7
0
 def test_intel(self):
     settings = MockSettings({
         "build_type": "Debug",
         "compiler": "intel",
         "compiler.version": "19.1",
         "compiler.base": "Visual Studio",
         "compiler.base.version": "15",
         "arch": "x86_64"
     })
     expected_toolset = "Intel C++ Compiler 19.1"
     conanfile = MockConanfile(settings)
     msbuild = MSBuild(conanfile)
     command = msbuild.get_command("project_should_flags_test_file.sln")
     self.assertIn('/p:PlatformToolset="%s"' % expected_toolset, command)
Esempio n. 8
0
 def test_add_configuration(self):
     conanfile = MockConanfile(
         MockSettings({'os': 'Linux', 'compiler': 'gcc'}))
     conanfile.source_folder = '.'
     build_helper = qbs.Qbs(conanfile)
     configurations = {
         'debug':  {'products.MyLib.specialFlags': ['-frtti',
                                                    '-fexceptions']},
         'release': {'products.MyLib.specialFlags': ['-fno-exceptions',
                                                     '-fno-rtti']}
     }
     for name, config in configurations.items():
         build_helper.add_configuration(name, config)
     self.assertEqual(build_helper._configuration, configurations)
Esempio n. 9
0
 def binary_logging_on_with_filename_test(self):
     bl_filename = "a_special_log.log"
     settings = MockSettings({
         "build_type": "Debug",
         "compiler": "Visual Studio",
         "compiler.version": "15",
         "arch": "x86_64",
         "compiler.runtime": "MDd"
     })
     conanfile = MockConanfile(settings)
     msbuild = MSBuild(conanfile)
     command = msbuild.get_command("dummy.sln",
                                   output_binary_log=bl_filename)
     expected_command = '/bl:"%s"' % bl_filename
     self.assertIn(expected_command, command)
Esempio n. 10
0
    def test_binary_logging_not_supported(self, mock_get_version):
        mock_get_version.return_value = Version("14")

        mocked_settings = MockSettings({"build_type": "Debug",
                                        "compiler": "Visual Studio",
                                        "compiler.version": "15",
                                        "arch": "x86_64",
                                        "compiler.runtime": "MDd"})
        conanfile = MockConanfile(mocked_settings)
        except_text = "MSBuild version detected (14) does not support 'output_binary_log' ('/bl')"
        msbuild = MSBuild(conanfile)

        with self.assertRaises(ConanException) as exc:
            msbuild.get_command("dummy.sln", output_binary_log=True)
        self.assertIn(except_text, str(exc.exception))
Esempio n. 11
0
    def test_build_all(self):
        conanfile = MockConanfile(
            MockSettings({'os': 'Linux', 'compiler': 'gcc'}),
            runner=RunnerMock())
        conanfile.source_folder = '.'
        conanfile.build_folder = '.'
        build_helper = qbs.Qbs(conanfile)

        build_helper.build_all()
        self.assertEqual(
            conanfile.runner.command_called,
            ('qbs build --no-install --build-directory %s '
             '--file %s --all-products --jobs %s profile:%s') % (
                conanfile.build_folder, build_helper._project_file,
                build_helper.jobs, build_helper.use_toolchain_profile))
Esempio n. 12
0
 def custom_properties_test(self):
     settings = MockSettings({
         "build_type": "Debug",
         "compiler": "Visual Studio",
         "arch": "x86_64"
     })
     conanfile = MockConanfile(settings)
     msbuild = MSBuild(conanfile)
     command = msbuild.get_command("project_file.sln",
                                   properties={
                                       "MyProp1": "MyValue1",
                                       "MyProp2": "MyValue2"
                                   })
     self.assertIn('/p:MyProp1="MyValue1"', command)
     self.assertIn('/p:MyProp2="MyValue2"', command)
Esempio n. 13
0
    def build_vs_project_test(self, generator, props):
        client = TestClient()
        files = {}
        files["conanfile.py"] = hello_conanfile_py
        files["hello.h"] = hello_h
        client.save(files)
        client.run("create . lasote/testing")

        files = get_vs_project_files()
        files["MyProject/main.cpp"] = main_cpp
        files["conanfile.txt"] = conanfile_txt.format(generator=generator)
        props = os.path.join(client.current_folder, props)
        old = '<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />'
        new = old + '<Import Project="{props}" />'.format(props=props)
        files["MyProject/MyProject.vcxproj"] = files[
            "MyProject/MyProject.vcxproj"].replace(old, new)
        client.save(files, clean_first=True)

        for build_type in ["Debug", "Release"]:
            arch = "x86"
            runner = ConanRunner(print_commands_to_output=True,
                                 generate_run_log_file=False,
                                 log_run_to_output=True,
                                 output=TestBufferConanOutput())
            settings = MockSettings({
                "os": "Windows",
                "build_type": build_type,
                "arch": arch,
                "compiler": "Visual Studio",
                "compiler.version": "15",
                "compiler.toolset": "v141"
            })
            conanfile = MockConanfile(settings, runner=runner)
            settings = " -s os=Windows " \
                       " -s build_type={build_type} " \
                       " -s arch={arch}" \
                       " -s compiler=\"Visual Studio\"" \
                       " -s compiler.toolset=v141" \
                       " -s compiler.version=15".format(build_type=build_type, arch=arch)
            client.run("install . %s" % settings)
            with tools.chdir(client.current_folder):
                msbuild = MSBuild(conanfile)
                msbuild.build(project_file="MyProject.sln",
                              build_type=build_type,
                              arch=arch)
                output = TestBufferConanOutput()
                runner("%s\MyProject.exe" % build_type, output)
                self.assertIn("Hello %s!!!" % build_type, output)
Esempio n. 14
0
    def test_install(self):
        conanfile = MockConanfile(MockSettings({
            'os': 'Linux',
            'compiler': 'gcc'
        }),
                                  runner=RunnerMock())
        conanfile.source_folder = '.'
        conanfile.package_folder = 'pkg'
        build_helper = qbs.Qbs(conanfile)

        build_helper.install()
        self.assertEqual(
            conanfile.runner.command_called,
            ('qbs install --no-build --install-root %s '
             '--file %s') %
            (conanfile.package_folder, build_helper._project_file))
Esempio n. 15
0
    def definitions_no_value_test(self):
        settings = MockSettings({
            "build_type": "Debug",
            "compiler": "Visual Studio",
            "arch": "x86_64",
            "compiler.runtime": "MDd"
        })
        conanfile = MockConanfile(settings)
        msbuild = MSBuild(conanfile)
        template = msbuild._get_props_file_contents(
            definitions={'_DEBUG': None})

        self.assertIn(
            "<PreprocessorDefinitions>"
            "_DEBUG;"
            "%(PreprocessorDefinitions)</PreprocessorDefinitions>", template)
Esempio n. 16
0
    def test_definitions(self):
        settings = MockSettings({
            "build_type": "Debug",
            "compiler": "Visual Studio",
            "arch": "x86_64",
            "compiler.runtime": "MDd"
        })
        conanfile = MockConanfile(settings)
        msbuild = MSBuild(conanfile)
        template = msbuild._get_props_file_contents(
            definitions={'_WIN32_WINNT': "0x0501"})

        self.assertIn(
            "<PreprocessorDefinitions>"
            "_WIN32_WINNT=0x0501;"
            "%(PreprocessorDefinitions)</PreprocessorDefinitions>", template)
Esempio n. 17
0
    def test_properties_injection(self):
        # https://github.com/conan-io/conan/issues/4471
        settings = MockSettings({"build_type": "Debug",
                                 "compiler": "Visual Studio",
                                 "arch": "x86_64"})
        conanfile = MockConanfile(settings)
        msbuild = MSBuild(conanfile)
        command = msbuild.get_command("dummy.sln", props_file_path="conan_build.props")

        match = re.search('/p:ForceImportBeforeCppTargets="(.+?)"', command)
        self.assertTrue(
            match, "Haven't been able to find the ForceImportBeforeCppTargets")

        props_file_path = match.group(1)
        self.assertTrue(os.path.isabs(props_file_path))
        self.assertEqual(os.path.basename(props_file_path), "conan_build.props")
Esempio n. 18
0
 def test_skip_only_none_definitions(self):
     # https://github.com/conan-io/conan/issues/6728
     settings = MockSettings({
         "build_type": "Debug",
         "compiler": "Visual Studio",
         "arch": "x86_64",
         "compiler.runtime": "MDd"
     })
     conanfile = MockConanfile(settings)
     msbuild = MSBuild(conanfile)
     template = msbuild._get_props_file_contents(definitions={
         "foo": 0,
         "bar": False
     })
     self.assertIn(
         "<PreprocessorDefinitions>foo=0;bar=False;%(PreprocessorDefinitions)",
         template)
Esempio n. 19
0
    def test_mocked_methods(self):

        runner = RunnerMock()
        conanfile = MockConanfile(MockSettings({}), None, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        ab.make(make_program="othermake")
        self.assertEqual(runner.command_called, "othermake -j%s" %
                          cpu_count(output=conanfile.output))

        with tools.environment_append({"CONAN_MAKE_PROGRAM": "mymake"}):
            ab.make(make_program="othermake")
            self.assertEqual(runner.command_called, "mymake -j%s" %
                              cpu_count(output=conanfile.output))

        ab.make(args=["things"])
        things = "'things'" if platform.system() != "Windows" else "things"
        self.assertEqual(runner.command_called, "make %s -j%s" %
                          (things, cpu_count(output=conanfile.output)))
Esempio n. 20
0
    def test_stdcpp_library(self):
        settings = Settings.loads(get_default_settings_yml())
        settings.compiler = "gcc"
        settings.compiler.libcxx = "libstdc++"
        conanfile = MockConanfile(settings)
        self.assertEqual("stdc++", stdcpp_library(conanfile))

        settings.compiler.libcxx = "libstdc++11"
        self.assertEqual("stdc++", stdcpp_library(conanfile))

        settings.compiler = "clang"
        settings.compiler.libcxx = "libc++"
        self.assertEqual("c++", stdcpp_library(conanfile))

        settings.compiler.libcxx = "c++_shared"
        self.assertEqual("c++_shared", stdcpp_library(conanfile))

        settings.compiler.libcxx = "c++_static"
        self.assertEqual("c++_static", stdcpp_library(conanfile))
Esempio n. 21
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)
Esempio n. 22
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)
Esempio n. 23
0
    def test_dont_mess_with_build_type(self):
        settings = MockSettings({"build_type": "Debug",
                                 "compiler": "Visual Studio",
                                 "arch": "x86_64",
                                 "compiler.runtime": "MDd"})
        conanfile = MockConanfile(settings)
        msbuild = MSBuild(conanfile)
        self.assertEqual(msbuild.build_env.flags, [])
        template = msbuild._get_props_file_contents()

        self.assertNotIn("-Ob0", template)
        self.assertNotIn("-Od", template)

        msbuild.build_env.flags = ["-Zi"]
        template = msbuild._get_props_file_contents()

        self.assertNotIn("-Ob0", template)
        self.assertNotIn("-Od", template)
        self.assertIn("-Zi", template)
        self.assertIn("<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>", template)
Esempio n. 24
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)
Esempio n. 25
0
    def test_build(self):
        conanfile = MockConanfile(MockSettings({
            'os': 'Linux',
            'compiler': 'gcc'
        }),
                                  runner=RunnerMock())
        conanfile.folders.set_base_source('.')
        conanfile.folders.set_base_build('.')
        build_helper = qbs.Qbs(conanfile)

        build_helper.build()
        self.assertEqual(conanfile.runner.command_called,
                         ('qbs build --no-install --build-directory %s '
                          '--file %s --jobs %s profile:%s') %
                         (conanfile.build_folder, build_helper._project_file,
                          build_helper.jobs, build_helper.profile))

        build_helper.build(products=['app1', 'app2', 'lib'])
        self.assertEqual(
            conanfile.runner.command_called,
            ('qbs build --no-install --build-directory %s '
             '--file %s --products app1,app2,lib --jobs %s profile:%s') %
            (conanfile.build_folder, build_helper._project_file,
             build_helper.jobs, build_helper.profile))
Esempio n. 26
0
    def test_install_with_custom_configuration(self):
        conanfile = MockConanfile(MockSettings({
            'os': 'Linux',
            'compiler': 'gcc'
        }),
                                  runner=RunnerMock())
        conanfile.source_folder = '.'
        conanfile.package_folder = 'pkg'
        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.install()
        self.assertEqual(conanfile.runner.command_called,
                         ('qbs install --no-build --install-root %s '
                          '--file %s config:%s') %
                         (conanfile.package_folder, build_helper._project_file,
                          config_name))
def test_save_and_load_encoding():
    conanfile = MockConanfile({})
    tmp = temp_folder()
    file_path = os.path.join(tmp, "file.txt")

    # By default utf-8 is used
    save(conanfile, file_path, "你很重,伙計")
    contents = load(conanfile, file_path)
    assert isinstance(contents, str)
    assert contents == "你很重,伙計"

    # But you can save bytes directly with an encoding
    save(conanfile, file_path, bytes("你很重,伙計", "utf-16"))
    contents = load(conanfile, file_path, encoding="utf-16")
    assert contents == "你很重,伙計"

    # And you can specify different encoding
    save(conanfile, file_path, "你很重,伙計", encoding="utf-16")
    contents = load(conanfile, file_path, encoding="utf-16")
    assert contents == "你很重,伙計"

    save(conanfile, file_path, "regular contents")
    contents = load(conanfile, file_path)
    assert contents == "regular contents"
Esempio n. 28
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)
Esempio n. 29
0
    def test_autotools_fpic(self):
        runner = None
        settings = MockSettings({"os": "Linux"})
        options = MockOptions({"fPIC": True, "shared": False})
        conanfile = MockConanfile(settings, options, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        self.assertTrue(ab.fpic)

        options = MockOptions({"fPIC": True, "shared": True})
        conanfile = MockConanfile(settings, options, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        self.assertTrue(ab.fpic)

        options = MockOptions({"fPIC": False, "shared": True})
        conanfile = MockConanfile(settings, options, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        self.assertTrue(ab.fpic)

        options = MockOptions({"fPIC": False, "shared": False})
        conanfile = MockConanfile(settings, options, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        self.assertFalse(ab.fpic)

        settings = MockSettings({"os": "Windows"})
        options = MockOptions({"fPIC": True, "shared": True})
        conanfile = MockConanfile(settings, options, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        self.assertFalse(ab.fpic)

        settings = MockSettings({"os": "Macos", "compiler": "clang"})
        options = MockOptions({"fPIC": False, "shared": False})
        conanfile = MockConanfile(settings, options, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        self.assertFalse(ab.fpic)
        ab.fpic = True
        self.assertIn("-fPIC", ab.vars["CXXFLAGS"])
Esempio n. 30
0
 def test_construct_build_helper_with_wrong_project_file_path(self):
     conanfile = MockConanfile(
         MockSettings({'os': 'Linux', 'compiler': 'gcc'}))
     with self.assertRaises(ConanException):
         qbs.Qbs(conanfile, project_file='random/file/path')