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_cpp_flag -onlycxx', 'LDFLAGS': '-inventedflag -Lone/lib/path', 'LIBS': '-lonelib -ltwolib' } self.assertEquals(be.vars, expected)
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)
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_cpp_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.assertEquals(be.vars, expected)
def test_previous_env(self): settings = MockSettings({"arch": "x86", "os": "Linux"}) conanfile = MockConanfile(settings) with tools.environment_append({"CPPFLAGS": "MyCppFlag"}): be = AutoToolsBuildEnvironment(conanfile) self.assertEquals(be.vars["CPPFLAGS"], "MyCppFlag")
def __init__(self, conanfile): super(VirtualBuildEnvGenerator, self).__init__(conanfile) compiler = conanfile.settings.get_safe("compiler") if compiler != "Visual Studio": tools = AutoToolsBuildEnvironment(conanfile) else: tools = VisualStudioBuildEnvironment(conanfile) self.env = tools.vars_dict
def __init__(self, conanfile): super(VirtualBuildEnvGenerator, self).__init__(conanfile) compiler = conanfile.settings.get_safe("compiler") self.env = {} if compiler != "Visual Studio": auto_tools_b = AutoToolsBuildEnvironment(conanfile) tmp = {var: '"%s"' % value for var, value in auto_tools_b.vars.items()} self.env = tmp else: visual_b = VisualStudioBuildEnvironment(conanfile, quote_paths=False) self.env = visual_b.vars
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_cpp_flag -onlycxx', 'LDFLAGS': '-inventedflag -Lone/lib/path', 'LIBS': '-lonelib -ltwolib'} self.assertEquals(be.vars, expected)
def test_mocked_methods(self): runner = RunnerMock() conanfile = MockConanfile(MockSettings({}), 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()))
def test_variables(self): # 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': '-m32 -s', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG ' '-D_GLIBCXX_USE_CXX11_ABI=0', 'CXXFLAGS': '-m32 -s', 'LDFLAGS': '-m32 -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': '-m64 -g', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition' ' -D_GLIBCXX_USE_CXX11_ABI=0', 'CXXFLAGS': '-m64 -g', 'LDFLAGS': '-m64 -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': '-m64', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition' ' -D_GLIBCXX_USE_CXX11_ABI=0', 'CXXFLAGS': '-m64 -stdlib=libstdc++', 'LDFLAGS': '-m64 -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': '-m64', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition', 'CXXFLAGS': '-m64 -stdlib=libc++', 'LDFLAGS': '-m64 -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': '-m64 -s', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition -DNDEBUG ' '-D_GLIBCXX_USE_CXX11_ABI=1', 'CXXFLAGS': '-m64 -s', 'LDFLAGS': '-m64 -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': '-m64', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition', 'CXXFLAGS': '-m64 -library=Cstd', 'LDFLAGS': '-m64 -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': '-m64', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition', 'CXXFLAGS': '-m64 -library=stdcxx4', 'LDFLAGS': '-m64 -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': '-m64', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition', 'CXXFLAGS': '-m64 -library=stlport4', 'LDFLAGS': '-m64 -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': '-m64', 'CPPFLAGS': '-Ipath/includes -Iother/include/path -Donedefinition -Dtwodefinition', 'CXXFLAGS': '-m64 -library=stdcpp', 'LDFLAGS': '-m64 -Lone/lib/path', 'LIBS': '-lonelib -ltwolib'} be = AutoToolsBuildEnvironment(conanfile) self.assertEquals(be.vars, expected)