예제 #1
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)
예제 #2
0
    def binary_logging_not_supported_test(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))
예제 #3
0
    def dont_mess_with_build_type_test(self):
        settings = MockSettings({"build_type": "Debug",
                                 "compiler": "Visual Studio",
                                 "arch": "x86_64"})
        conanfile = MockConanfile(settings)
        msbuild = MSBuild(conanfile)
        self.assertEquals(msbuild.build_env.flags, ["-Zi", "-Ob0", "-Od"])
        template = msbuild._get_props_file_contents()

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

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

        self.assertNotIn("-Ob0", template)
        self.assertNotIn("-Od", template)
예제 #4
0
 def rpath_optin_test(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 -m64 --sysroot=/path/to/folder '
                            '-Wl,-rpath="one/lib/path" -Lone/lib/path',
                 'LIBS': '-lonelib -ltwolib'}
     be = AutoToolsBuildEnvironment(conanfile, include_rpath_flags=True)
     self.assertEqual(be.vars, expected)
예제 #5
0
    def cross_build_command_test(self):
        runner = RunnerMock()
        conanfile = MockConanfile(MockSettings({}), None, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        ab.configure()
        self.assertEquals(runner.command_called, "./configure  ")

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

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

        ab.configure(target="i686-apple-darwin")
        self.assertEquals(runner.command_called,
                          "./configure  --target=i686-apple-darwin")
예제 #6
0
    def test_mocked_methods(self):

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

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

        ab.make(args=["things"])
        things = "'things'" if platform.system() != "Windows" else "things"
        self.assertEquals(runner.command_called,
                          "make %s -j%s" % (things, cpu_count()))
예제 #7
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))
예제 #8
0
    def autotools_configure_vars_test(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)
예제 #9
0
    def properties_injection_test(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")
예제 #10
0
    def dont_mess_with_build_type_test(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)
예제 #11
0
    def environment_append_test(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 -additionallibs',
                        'LDFLAGS': 'shared_link_flag exe_link_flag -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)
예제 #12
0
    def modify_values_test(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'}
        self.assertEqual(be.vars, expected)
예제 #13
0
    def autotools_fpic_test(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"])
예제 #14
0
 def test_already_set(self):
     with environment_append({"PSTLROOT": "1"}):
         settings = Settings.loads(get_default_settings_yml())
         cvars = compilervars_command(MockConanfile(settings))
         self.assertEqual("echo Conan:compilervars already set", cvars)
예제 #15
0
    def cross_build_command_test(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.assertEquals(runner.command_called, "./configure  ")

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

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

        ab.configure(target="i686-apple-darwin")
        self.assertEquals(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)
예제 #16
0
    def test_variables(self):
        # Visual Studio
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "Visual Studio",
            "compiler.version": "14",
            "compiler.runtime": "MD"
        })
        conanfile = MockConanfile(settings)
        self._set_deps_info(conanfile)

        be = AutoToolsBuildEnvironment(conanfile)
        expected = {
            'CFLAGS': 'a_c_flag -O2 -Ob2',
            'CPPFLAGS':
            '-Ipath\\includes -Iother\\include\\path -Donedefinition -Dtwodefinition -DNDEBUG',
            'CXXFLAGS': 'a_c_flag -O2 -Ob2 a_cpp_flag',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -LIBPATH:one\\lib\\path',
            'LIBS': 'onelib.lib twolib.lib'
        }

        self.assertEquals(be.vars, expected)
        # GCC 32
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "gcc",
            "compiler.libcxx": "libstdc++"
        })
        conanfile = MockConanfile(settings)
        self._set_deps_info(conanfile)

        be = AutoToolsBuildEnvironment(conanfile)
        expected = {
            'CFLAGS':
            'a_c_flag -m32 -O3 -s --sysroot=/path/to/folder',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG '
            '-D_GLIBCXX_USE_CXX11_ABI=0',
            'CXXFLAGS':
            'a_c_flag -m32 -O3 -s --sysroot=/path/to/folder a_cpp_flag',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m32 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS':
            '-lonelib -ltwolib'
        }

        self.assertEquals(be.vars, expected)

        # GCC 64
        settings = MockSettings({
            "build_type": "Debug",
            "arch": "x86_64",
            "compiler": "gcc",
            "compiler.libcxx": "libstdc++"
        })
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        expected = {
            'CFLAGS':
            'a_c_flag -m64 -g --sysroot=/path/to/folder',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition'
            ' -D_GLIBCXX_USE_CXX11_ABI=0',
            'CXXFLAGS':
            'a_c_flag -m64 -g --sysroot=/path/to/folder a_cpp_flag',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m64 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS':
            '-lonelib -ltwolib'
        }
        be = AutoToolsBuildEnvironment(conanfile)
        self.assertEquals(be.vars, expected)

        # With clang, we define _GLIBCXX_USE_CXX11_ABI
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86_64",
            "compiler": "clang",
            "compiler.libcxx": "libstdc++"
        })
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        expected = {
            'CFLAGS':
            'a_c_flag -m64 -O3 --sysroot=/path/to/folder',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition'
            ' -DNDEBUG -D_GLIBCXX_USE_CXX11_ABI=0',
            'CXXFLAGS':
            'a_c_flag -m64 -O3 --sysroot=/path/to/folder a_cpp_flag -stdlib=libstdc++',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m64 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS':
            '-lonelib -ltwolib'
        }
        be = AutoToolsBuildEnvironment(conanfile)
        self.assertEquals(be.vars, expected)

        # Change libcxx
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86_64",
            "compiler": "clang",
            "compiler.libcxx": "libc++"
        })
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        expected = {
            'CFLAGS': 'a_c_flag -m64 -O3 --sysroot=/path/to/folder',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG',
            'CXXFLAGS':
            'a_c_flag -m64 -O3 --sysroot=/path/to/folder a_cpp_flag -stdlib=libc++',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m64 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS': '-lonelib -ltwolib'
        }
        be = AutoToolsBuildEnvironment(conanfile)
        self.assertEquals(be.vars, expected)

        # gcc libcxx
        settings = MockSettings({
            "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_cpp_flag',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m64 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS':
            '-lonelib -ltwolib'
        }
        be = AutoToolsBuildEnvironment(conanfile)
        self.assertEquals(be.vars, expected)

        # Sun CC libCstd
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86_64",
            "compiler": "sun-cc",
            "compiler.libcxx": "libCstd"
        })
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        expected = {
            'CFLAGS': 'a_c_flag -m64 -xO3 --sysroot=/path/to/folder',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG',
            'CXXFLAGS':
            'a_c_flag -m64 -xO3 --sysroot=/path/to/folder a_cpp_flag -library=Cstd',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m64 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS': '-lonelib -ltwolib'
        }
        be = AutoToolsBuildEnvironment(conanfile)
        self.assertEquals(be.vars, expected)

        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86_64",
            "compiler": "sun-cc",
            "compiler.libcxx": "libstdcxx"
        })
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        expected = {
            'CFLAGS': 'a_c_flag -m64 -xO3 --sysroot=/path/to/folder',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG',
            'CXXFLAGS':
            'a_c_flag -m64 -xO3 --sysroot=/path/to/folder a_cpp_flag -library=stdcxx4',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m64 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS': '-lonelib -ltwolib'
        }
        be = AutoToolsBuildEnvironment(conanfile)
        self.assertEquals(be.vars, expected)

        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86_64",
            "compiler": "sun-cc",
            "compiler.libcxx": "libstlport"
        })
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        expected = {
            'CFLAGS': 'a_c_flag -m64 -xO3 --sysroot=/path/to/folder',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG',
            'CXXFLAGS':
            'a_c_flag -m64 -xO3 --sysroot=/path/to/folder a_cpp_flag -library=stlport4',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m64 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS': '-lonelib -ltwolib'
        }
        be = AutoToolsBuildEnvironment(conanfile)
        self.assertEquals(be.vars, expected)

        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86_64",
            "compiler": "sun-cc",
            "compiler.libcxx": "libstdc++"
        })
        conanfile = MockConanfile(settings)
        conanfile.settings = settings
        self._set_deps_info(conanfile)
        expected = {
            'CFLAGS': 'a_c_flag -m64 -xO3 --sysroot=/path/to/folder',
            'CPPFLAGS':
            '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG',
            'CXXFLAGS':
            'a_c_flag -m64 -xO3 --sysroot=/path/to/folder a_cpp_flag -library=stdcpp',
            'LDFLAGS':
            'shared_link_flag exe_link_flag -m64 --sysroot=/path/to/folder -Lone/lib/path',
            'LIBS': '-lonelib -ltwolib'
        }
        be = AutoToolsBuildEnvironment(conanfile)
        self.assertEquals(be.vars, expected)
예제 #17
0
    def test_visual(self):
        settings = MockSettings({
            "build_type": "Debug",
            "compiler": "Visual Studio",
            "compiler.runtime": "MDd"
        })
        conanfile = MockConanfile(settings)
        conanfile.deps_cpp_info.include_paths.append("/one/include/path")
        conanfile.deps_cpp_info.include_paths.append("/two/include/path")
        conanfile.deps_cpp_info.lib_paths.append("/one/lib/path")
        conanfile.deps_cpp_info.lib_paths.append("/two/lib/path")
        conanfile.deps_cpp_info.cflags.append("-mycflag")
        conanfile.deps_cpp_info.cflags.append("-mycflag2")
        conanfile.deps_cpp_info.cppflags.append("-mycppflag")
        conanfile.deps_cpp_info.cppflags.append("-mycppflag2")
        conanfile.deps_cpp_info.exelinkflags.append("-myexelinkflag")
        conanfile.deps_cpp_info.sharedlinkflags.append("-mysharedlinkflag")

        tool = VisualStudioBuildEnvironment(conanfile)
        self.assertEquals(
            tool.vars_dict, {
                "CL": [
                    "-I/one/include/path", "-I/two/include/path", '-MDd',
                    '-mycflag', '-mycflag2', '-Zi', '-Ob0', '-Od',
                    '-mycppflag', '-mycppflag2', '-myexelinkflag',
                    '-mysharedlinkflag'
                ],
                "LIB": ["/one/lib/path", "/two/lib/path"],
            })

        # Now alter the paths before the vars_dict call
        tool.include_paths.append("/three/include/path")
        tool.lib_paths.append("/three/lib/path")

        self.assertEquals(
            tool.vars_dict, {
                "CL": [
                    "-I/one/include/path", "-I/two/include/path",
                    "-I/three/include/path", '-MDd', '-mycflag', '-mycflag2',
                    '-Zi', '-Ob0', '-Od', '-mycppflag', '-mycppflag2',
                    '-myexelinkflag', '-mysharedlinkflag'
                ],
                "LIB": ["/one/lib/path", "/two/lib/path", "/three/lib/path"],
            })

        # Now try appending to environment
        with tools.environment_append({
                "CL": "-I/four/include/path -I/five/include/path",
                "LIB": "/four/lib/path;/five/lib/path"
        }):
            self.assertEquals(
                tool.vars_dict, {
                    "CL": [
                        "-I/one/include/path", "-I/two/include/path",
                        "-I/three/include/path", '-MDd', '-mycflag',
                        '-mycflag2', '-Zi', '-Ob0', '-Od', '-mycppflag',
                        '-mycppflag2', '-myexelinkflag', '-mysharedlinkflag',
                        "-I/four/include/path -I/five/include/path"
                    ],
                    "LIB": [
                        "/one/lib/path", "/two/lib/path", "/three/lib/path",
                        "/four/lib/path;/five/lib/path"
                    ],
                })

            self.assertEquals(
                tool.vars, {
                    "CL":
                    '-I"/one/include/path" -I"/two/include/path" -I"/three/include/path" -MDd '
                    '-mycflag -mycflag2 -Zi -Ob0 -Od '
                    '-mycppflag -mycppflag2 -myexelinkflag -mysharedlinkflag '
                    '-I/four/include/path -I/five/include/path',
                    "LIB":
                    "/one/lib/path;/two/lib/path;/three/lib/path;/four/lib/path;/five/lib/path",
                })
예제 #18
0
 def setUp(self):
     self.output = TestBufferConanOutput()
     self.conanfile = MockConanfile(None)
예제 #19
0
    def system_package_tool_test(self, patched_with_apt):

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}):
            runner = RunnerMock()
            # fake os info to linux debian, default sudo
            os_info = OSInfo()
            os_info.is_macos = False
            os_info.is_linux = True
            os_info.is_windows = False
            patched_with_apt.return_value = True

            os_info.linux_distro = "debian"

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "ubuntu"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "knoppix"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "neon"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            # We'll be testing non-Ubuntu and non-Debian-based distros.
            patched_with_apt.return_value = False

            with mock.patch("conans.client.tools.oss.which",
                            return_value=True):
                os_info.linux_distro = "fedora"
                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out)
                spt.update()
                self.assertEqual(runner.command_called,
                                 "sudo -A dnf check-update -y")

            # Without DNF in the path,
            os_info.linux_distro = "fedora"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called,
                             "sudo -A yum check-update -y")

            os_info.linux_distro = "opensuse"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called,
                             "sudo -A zypper --non-interactive ref")

            os_info.linux_distro = "redhat"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "rpm -q a_package")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "sudo -A yum install -y a_package")

            settings = MockSettings({
                "arch": "x86",
                "arch_build": "x86_64",
                "os": "Linux",
                "os_build": "Linux"
            })
            conanfile = MockConanfile(settings)
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out,
                                    conanfile=conanfile)
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "rpm -q a_package.i?86")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "sudo -A yum install -y a_package.i?86")

            os_info.linux_distro = "debian"
            patched_with_apt.return_value = True
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            with self.assertRaises(ConanException):
                runner.return_ok = False
                spt.install("a_package")
                self.assertEqual(
                    runner.command_called,
                    "sudo -A apt-get install -y --no-install-recommends a_package"
                )

            runner.return_ok = True
            spt.install("a_package", force=False)
            self.assertEqual(
                runner.command_called,
                'dpkg-query -W -f=\'${Status}\' a_package | grep -q "ok installed"'
            )

            os_info.is_macos = True
            os_info.is_linux = False
            os_info.is_windows = False
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "brew update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "brew install a_package")

            os_info.is_freebsd = True
            os_info.is_macos = False
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A pkg update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "sudo -A pkg install -y a_package")
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "pkg info a_package")

            # Chocolatey is an optional package manager on Windows
            if platform.system() == "Windows" and which("choco.exe"):
                os_info.is_freebsd = False
                os_info.is_windows = True
                patched_with_apt.return_value = False
                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out,
                                        tool=ChocolateyTool(output=self.out))
                spt.update()
                self.assertEqual(runner.command_called, "choco outdated")
                spt.install("a_package", force=True)
                self.assertEqual(runner.command_called,
                                 "choco install --yes a_package")
                spt.install("a_package", force=False)
                self.assertEqual(
                    runner.command_called,
                    'choco search --local-only --exact a_package | '
                    'findstr /c:"1 packages installed."')

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "False"}):

            os_info = OSInfo()
            os_info.is_linux = True
            os_info.linux_distro = "redhat"
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "yum install -y a_package")
            spt.update()
            self.assertEqual(runner.command_called, "yum check-update -y")

            os_info.linux_distro = "ubuntu"
            patched_with_apt.return_value = True
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.install("a_package", force=True)
            self.assertEqual(
                runner.command_called,
                "apt-get install -y --no-install-recommends a_package")

            spt.update()
            self.assertEqual(runner.command_called, "apt-get update")

            for arch, distro_arch in {
                    "x86_64": "",
                    "x86": ":i386",
                    "ppc32": ":powerpc",
                    "ppc64le": ":ppc64el",
                    "armv7": ":arm",
                    "armv7hf": ":armhf",
                    "armv8": ":arm64",
                    "s390x": ":s390x"
            }.items():
                settings = MockSettings({
                    "arch": arch,
                    "arch_build": "x86_64",
                    "os": "Linux",
                    "os_build": "Linux"
                })
                conanfile = MockConanfile(settings)
                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out,
                                        conanfile=conanfile)
                spt.install("a_package", force=True)
                self.assertEqual(
                    runner.command_called,
                    "apt-get install -y --no-install-recommends a_package%s" %
                    distro_arch)

            for arch, distro_arch in {"x86_64": "", "x86": ":all"}.items():
                settings = MockSettings({
                    "arch": arch,
                    "arch_build": "x86_64",
                    "os": "Linux",
                    "os_build": "Linux"
                })
                conanfile = MockConanfile(settings)
                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out,
                                        conanfile=conanfile)
                spt.install("a_package", force=True, arch_names={"x86": "all"})
                self.assertEqual(
                    runner.command_called,
                    "apt-get install -y --no-install-recommends a_package%s" %
                    distro_arch)

            os_info.is_macos = True
            os_info.is_linux = False
            os_info.is_windows = False
            patched_with_apt.return_value = False
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)

            spt.update()
            self.assertEqual(runner.command_called, "brew update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "brew install a_package")

            os_info.is_freebsd = True
            os_info.is_macos = False
            os_info.is_windows = False
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "pkg update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "pkg install -y a_package")
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "pkg info a_package")

            os_info.is_solaris = True
            os_info.is_freebsd = False
            os_info.is_windows = False
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "pkgutil --catalog")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "pkgutil --install --yes a_package")

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}):

            # Chocolatey is an optional package manager on Windows
            if platform.system() == "Windows" and which("choco.exe"):
                os_info.is_solaris = False
                os_info.is_windows = True
                patched_with_apt.return_value = False

                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out,
                                        tool=ChocolateyTool(output=self.out))
                spt.update()
                self.assertEqual(runner.command_called, "choco outdated")
                spt.install("a_package", force=True)
                self.assertEqual(runner.command_called,
                                 "choco install --yes a_package")
                spt.install("a_package", force=False)
                self.assertEqual(
                    runner.command_called,
                    'choco search --local-only --exact a_package | '
                    'findstr /c:"1 packages installed."')
예제 #20
0
 def error_targets_argument_Test(self):
     conanfile = MockConanfile(MockSettings({}))
     msbuild = MSBuild(conanfile)
     with self.assertRaises(TypeError):
         msbuild.get_command("dummy.sln", targets="sometarget")
예제 #21
0
 def get_values(this_os, this_arch, setting_os, setting_arch):
     settings = MockSettings({"arch": setting_arch, "os": setting_os})
     conanfile = MockConanfile(settings)
     conanfile.settings = settings
     be = AutoToolsBuildEnvironment(conanfile)
     return be._get_host_build_target_flags(this_arch, this_os)
예제 #22
0
    def test_visual(self):
        settings = MockSettings({
            "build_type": "Debug",
            "compiler": "Visual Studio",
            "compiler.runtime": "MDd"
        })
        conanfile = MockConanfile(settings)
        conanfile.deps_cpp_info.include_paths.append("/one/include/path")
        conanfile.deps_cpp_info.include_paths.append("/two/include/path")
        conanfile.deps_cpp_info.lib_paths.append("/one/lib/path")
        conanfile.deps_cpp_info.lib_paths.append("/two/lib/path")
        conanfile.deps_cpp_info.cflags.append("-mycflag")
        conanfile.deps_cpp_info.cflags.append("-mycflag2")
        conanfile.deps_cpp_info.cxxflags.append("-mycxxflag")
        conanfile.deps_cpp_info.cxxflags.append("-mycxxflag2")
        conanfile.deps_cpp_info.exelinkflags.append("-myexelinkflag")
        conanfile.deps_cpp_info.sharedlinkflags.append("-mysharedlinkflag")
        conanfile.deps_cpp_info.libs.extend(['gdi32', 'user32.lib'])

        tool = VisualStudioBuildEnvironment(conanfile)
        self.assertEqual(
            tool.vars_dict, {
                "CL": [
                    "-I/one/include/path", "-I/two/include/path", '-MDd',
                    '-mycflag', '-mycflag2', '-Zi', '-Ob0', '-Od',
                    '-mycxxflag', '-mycxxflag2'
                ],
                "LIB": ["/one/lib/path", "/two/lib/path"],
                "UseEnv":
                "True",
                "_LINK_": [
                    '-myexelinkflag', '-mysharedlinkflag', 'gdi32.lib',
                    'user32.lib'
                ]
            })
        tool.parallel = True
        self.assertEqual(
            tool.vars_dict, {
                "CL": [
                    "-I/one/include/path", "-I/two/include/path", '-MDd',
                    '-mycflag', '-mycflag2', '-Zi', '-Ob0', '-Od',
                    '-mycxxflag', '-mycxxflag2',
                    '/MP%s' % tools.cpu_count(output=conanfile.output)
                ],
                "LIB": ["/one/lib/path", "/two/lib/path"],
                "UseEnv":
                "True",
                "_LINK_": [
                    '-myexelinkflag', '-mysharedlinkflag', 'gdi32.lib',
                    'user32.lib'
                ]
            })
        tool.parallel = False

        # Now alter the paths before the vars_dict call
        tool.include_paths.append("/three/include/path")
        tool.lib_paths.append("/three/lib/path")

        self.assertEqual(
            tool.vars_dict, {
                "CL": [
                    "-I/one/include/path", "-I/two/include/path",
                    "-I/three/include/path", '-MDd', '-mycflag', '-mycflag2',
                    '-Zi', '-Ob0', '-Od', '-mycxxflag', '-mycxxflag2'
                ],
                "LIB": ["/one/lib/path", "/two/lib/path", "/three/lib/path"],
                "UseEnv":
                "True",
                "_LINK_": [
                    '-myexelinkflag', '-mysharedlinkflag', 'gdi32.lib',
                    'user32.lib'
                ]
            })

        # Now try appending to environment
        with tools.environment_append({
                "CL": "-I/four/include/path -I/five/include/path",
                "LIB": "/four/lib/path;/five/lib/path"
        }):
            self.assertEqual(
                tool.vars_dict, {
                    "CL": [
                        "-I/one/include/path", "-I/two/include/path",
                        "-I/three/include/path", '-MDd', '-mycflag',
                        '-mycflag2', '-Zi', '-Ob0', '-Od', '-mycxxflag',
                        '-mycxxflag2',
                        "-I/four/include/path -I/five/include/path"
                    ],
                    "LIB": [
                        "/one/lib/path", "/two/lib/path", "/three/lib/path",
                        "/four/lib/path;/five/lib/path"
                    ],
                    "UseEnv":
                    "True",
                    "_LINK_": [
                        '-myexelinkflag', '-mysharedlinkflag', 'gdi32.lib',
                        'user32.lib'
                    ]
                })

            self.assertEqual(
                tool.vars, {
                    "CL":
                    '-I"/one/include/path" -I"/two/include/path" -I"/three/include/path" -MDd '
                    '-mycflag -mycflag2 -Zi -Ob0 -Od '
                    '-mycxxflag -mycxxflag2 '
                    '-I/four/include/path -I/five/include/path',
                    "LIB":
                    "/one/lib/path;/two/lib/path;/three/lib/path;/four/lib/path;/five/lib/path",
                    "UseEnv":
                    "True",
                    "_LINK_":
                    "-myexelinkflag -mysharedlinkflag gdi32.lib user32.lib"
                })
예제 #23
0
    def test_cppstd(self):
        options = MockOptions({})
        # Valid one for GCC
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "gcc",
            "compiler.libcxx": "libstdc++11",
            "compiler.version": "7.1",
            "cppstd": "17"
        })
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertIn("-std=c++17", expected)

        # Invalid one for GCC
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "gcc",
            "compiler.libcxx": "libstdc++11",
            "compiler.version": "4.9",
            "cppstd": "17"
        })
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertNotIn("-std", expected)

        # Valid one for Clang
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "clang",
            "compiler.libcxx": "libstdc++11",
            "compiler.version": "4.0",
            "cppstd": "17"
        })
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertIn("-std=c++1z", expected)

        # Invalid one for Clang
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "clang",
            "compiler.libcxx": "libstdc++11",
            "compiler.version": "3.3",
            "cppstd": "17"
        })
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertNotIn("-std=", expected)

        # Visual Activate 11 is useless
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "Visual Studio",
            "compiler.version": "15",
            "cppstd": "11"
        })
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertNotIn("-std=c++", expected)

        # Visual Activate 17 in VS 2017
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "Visual Studio",
            "compiler.version": "15",
            "cppstd": "17"
        })
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertIn("/std:c++17", expected)

        # Visual Activate 17 in VS 2015
        settings = MockSettings({
            "build_type": "Release",
            "arch": "x86",
            "compiler": "Visual Studio",
            "compiler.version": "14",
            "cppstd": "17"
        })
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertIn("/std:c++latest", expected)
예제 #24
0
 def test_bas_os(self):
     settings = Settings.loads(get_default_settings_yml())
     settings.os = "SunOS"
     with self.assertRaises(ConanException):
         compilervars_command(MockConanfile(settings))