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)
    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)
示例#3
0
class VirtualBuildEnvGenerator(VirtualEnvGenerator):

    def __init__(self, conanfile):
        super(VirtualBuildEnvGenerator, self).__init__(conanfile)
        self.venv_name = "conanbuildenv"
        compiler = conanfile.settings.get_safe("compiler")
        if compiler == "Visual Studio":
            self.env = VisualStudioBuildEnvironment(conanfile).vars_dict
            settings_vars = vcvars_dict(conanfile.settings, output=conanfile.output)
            # self.env has higher priority, so only extend (append) to it.
            for name, value in self.env.items():
                if isinstance(value, list):
                    value.extend(settings_vars.pop(name, []))

            self.env.update(settings_vars)
        else:
            self.env = AutoToolsBuildEnvironment(conanfile).vars_dict

    @property
    def content(self):
        tmp = super(VirtualBuildEnvGenerator, self).content
        ret = {}
        # The generic virtualenv generator contents, but with the name "xxx_build.xxx"
        for name, value in tmp.items():
            filename, ext = name.split(".")
            ret["%s_build.%s" % (filename, ext)] = value

        return ret
示例#4
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)
示例#5
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)
示例#6
0
    def test_mac_version_min(self):
        options = MockOptions({})
        settings = MockSettings({"os": "Macos"})
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertEqual("", expected)

        settings = MockSettings({"os": "Macos",
                                 "os.version": "10.13",
                                 "compiler.version": "12.0"})
        conanfile = MockConanfile(settings, options)
        be = AutoToolsBuildEnvironment(conanfile)
        expected = be.vars["CXXFLAGS"]
        self.assertIn("10.13", expected)

        with tools.environment_append({"CFLAGS": "-mmacosx-version-min=10.9"}):
            be = AutoToolsBuildEnvironment(conanfile)
            expected = be.vars["CFLAGS"]
            self.assertIn("10.9", expected)
            self.assertNotIn("10.13", expected)

        with tools.environment_append({"CXXFLAGS": "-mmacosx-version-min=10.9"}):
            be = AutoToolsBuildEnvironment(conanfile)
            expected = be.vars["CFLAGS"]
            self.assertNotIn("10.13", expected)
示例#7
0
 def __init__(self, conanfile):
     super(VirtualBuildEnvGenerator, self).__init__(conanfile)
     self.venv_name = "conanbuildenv"
     compiler = conanfile.settings.get_safe("compiler")
     if compiler == "Visual Studio":
         self.env = VisualStudioBuildEnvironment(conanfile).vars_dict
         self.env.update(vcvars_dict(conanfile.settings))
     else:
         self.env = AutoToolsBuildEnvironment(conanfile).vars_dict
def write_cross_file(path: str,
                     conan: ConanFile,
                     pkg_config_paths: Optional[Iterable[str]] = None) -> None:
    pkg_config_paths = (pkg_config_paths if pkg_config_paths is not None else
                        [conan.install_folder])
    env = AutoToolsBuildEnvironment(conan).vars
    if env.get('PKG_CONFIG_PATH') is None:
        env['PKG_CONFIG_PATH'] = ':'.join(pkg_config_paths)
    with tools.environment_append(env):
        _write_cross_file(path, conan.settings)
 def autotools_install_dir_custom_configure_test(self):
     for flag_to_remove in default_dirs_flags:
         flags_available = set(default_dirs_flags) - set([flag_to_remove])
         runner = RunnerMockWithHelp(available_args=flags_available)
         conanfile = MockConanfileWithOutput(MockSettings({}), None, runner)
         conanfile.package_folder = "/package_folder"
         ab = AutoToolsBuildEnvironment(conanfile)
         ab.configure()
         self.assertNotIn(flag_to_remove, runner.command_called)
         for flag_applied in flags_available:
             self.assertIn(flag_applied, runner.command_called)
示例#10
0
 def __init__(self, conanfile):
     super(VirtualBuildEnvGenerator, self).__init__(conanfile)
     self.venv_name = "conanbuildenv"
     compiler = conanfile.settings.get_safe("compiler")
     if compiler == "Visual Studio":
         self.env = VisualStudioBuildEnvironment(conanfile).vars_dict
         settings_vars = vcvars_dict(conanfile.settings,
                                     output=conanfile.output)
         for env_var in self.env:
             self.env[env_var].extend(settings_vars.pop(env_var, []))
         self.env.update(settings_vars)
     else:
         self.env = AutoToolsBuildEnvironment(conanfile).vars_dict
示例#11
0
 def autotools_prefix_test(self):
     runner = RunnerMock()
     conanfile = MockConanfile(MockSettings({}), None, runner)
     # Package folder is not defined
     ab = AutoToolsBuildEnvironment(conanfile)
     ab.configure()
     self.assertNotIn("--prefix", runner.command_called)
     # package folder defined
     conanfile.package_folder = "/package_folder"
     ab.configure()
     if platform.system() == "Windows":
         self.assertIn("./configure --prefix=/package_folder",
                       runner.command_called)
     else:
         self.assertIn("./configure '--prefix=/package_folder'",
                       runner.command_called)
     # --prefix already used in args
     ab.configure(args=["--prefix=/my_package_folder"])
     if platform.system() == "Windows":
         self.assertIn("./configure --prefix=/my_package_folder",
                       runner.command_called)
         self.assertNotIn("--prefix=/package_folder", runner.command_called)
     else:
         self.assertIn("./configure '--prefix=/my_package_folder'",
                       runner.command_called)
         self.assertNotIn("'--prefix=/package_folder'",
                          runner.command_called)
示例#12
0
 def partial_build_test(self):
     conan_file = ConanFileMock()
     deps_cpp_info = namedtuple("Deps", "libs, include_paths, lib_paths, defines, cflags, "
                                "cppflags, sharedlinkflags, exelinkflags, sysroot")
     conan_file.deps_cpp_info = deps_cpp_info([], [], [], [], [], [], [], [], "")
     conan_file.settings = Settings()
     be = AutoToolsBuildEnvironment(conan_file)
     conan_file.should_configure = False
     conan_file.should_build = False
     conan_file.should_install = False
     be.configure()
     self.assertIsNone(conan_file.command)
     be.make()
     self.assertIsNone(conan_file.command)
示例#13
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")
示例#14
0
    def __init__(self, conanfile):
        super(VirtualBuildEnvGenerator, self).__init__(conanfile)
        compiler = conanfile.settings.get_safe("compiler")
        if compiler == "Visual Studio":
            self.env = VisualStudioBuildEnvironment(conanfile).vars_dict
            settings_vars = vcvars_dict(conanfile.settings,
                                        output=conanfile.output)
            # self.env has higher priority, so only extend (append) to it.
            for name, value in self.env.items():
                if isinstance(value, list):
                    value.extend(settings_vars.pop(name, []))

            self.env.update(settings_vars)
        else:
            self.env = AutoToolsBuildEnvironment(conanfile).vars_dict
    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)
示例#16
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)
示例#17
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)
 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_cpp_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.assertEquals(be.vars, expected)
示例#19
0
    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")
示例#20
0
    def failing_configure_help_test(self):

        class RunnerMockWithHelpFailing(RunnerMockWithHelp):
            def __call__(self, command, output=None, win_bash=False, subsystem=None):  # @UnusedVariable
                if "configure --help" in command:
                    raise ConanException("Help not available")
                else:
                    return super(RunnerMockWithHelp, self).__call__(command, output, win_bash, subsystem)

        runner = RunnerMockWithHelpFailing(available_args=default_dirs_flags)
        conanfile = MockConanfileWithOutput(MockSettings({}), None, runner)
        conanfile.package_folder = "/package_folder"
        ab = AutoToolsBuildEnvironment(conanfile)
        ab.configure()
        for flag_applied in default_dirs_flags:
            self.assertNotIn(flag_applied, runner.command_called)
        self.assertIn("Error running `configure --help`: Help not available", conanfile.output)
示例#21
0
 def warn_when_no_triplet_test(self):
     conan_file = ConanFileMock()
     deps_cpp_info = namedtuple("Deps", "libs, include_paths, lib_paths, defines, cflags, "
                                        "cxxflags, sharedlinkflags, exelinkflags, sysroot")
     conan_file.deps_cpp_info = 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)
 def target_triple_test(self):
     conan_file = ConanFileMock()
     deps_cpp_info = namedtuple("Deps", "libs, include_paths, lib_paths, defines, cflags, "
                                        "cxxflags, sharedlinkflags, exelinkflags, sysroot")
     conan_file.deps_cpp_info = 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)
示例#23
0
    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 test_make_targets_install(self):
        runner = RunnerMock()
        conanfile = MockConanfile(MockSettings({}), None, runner)

        ab = AutoToolsBuildEnvironment(conanfile)
        ab.configure()

        ab.make(target="install")
        self.assertEquals(runner.command_called,
                          "make install -j%s" % cpu_count())
        ab.install()
        self.assertEquals(runner.command_called,
                          "make install -j%s" % cpu_count())
示例#25
0
class VirtualBuildEnvGenerator(VirtualEnvGenerator):
    def __init__(self, conanfile):
        super(VirtualBuildEnvGenerator, self).__init__(conanfile)
        self.venv_name = "conanbuildenv"
        compiler = conanfile.settings.get_safe("compiler")
        if compiler == "Visual Studio":
            self.env = VisualStudioBuildEnvironment(conanfile).vars_dict
            self.env.update(vcvars_dict(conanfile.settings))
        else:
            self.env = AutoToolsBuildEnvironment(conanfile).vars_dict

    @property
    def content(self):
        tmp = super(VirtualBuildEnvGenerator, self).content
        ret = {}
        for name, value in tmp.items():
            tmp = name.split(".")
            ret["%s_build.%s" % (tmp[0], tmp[1])] = value

        return ret
示例#26
0
    def test_make_targets_install(self):
        runner = RunnerMock()
        conanfile = MockConanfile(MockSettings({}), None, runner)

        ab = AutoToolsBuildEnvironment(conanfile)
        ab.configure()

        ab.make(target="install")
        self.assertEquals(runner.command_called, "make install -j%s" % cpu_count())
        ab.install()
        self.assertEquals(runner.command_called, "make install -j%s" % cpu_count())
示例#27
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()))
示例#28
0
 def test_nmake_no_parallel(self):
     conan_file = ConanFileMock()
     conan_file.deps_cpp_info = self._creat_deps_cpp_info()
     conan_file.settings = Settings()
     be = AutoToolsBuildEnvironment(conan_file)
     be.make(make_program="nmake")
     assert "-j" not in conan_file.command
     be.make(make_program="make")
     assert "-j" in conan_file.command
示例#29
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_cpp_flag -onlycxx',
                    'LDFLAGS': '-inventedflag -Lone/lib/path',
                    'LIBS': '-lonelib -ltwolib'}
        self.assertEquals(be.vars, expected)
示例#30
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()))
示例#31
0
 def test_partial_build(self):
     conan_file = ConanFileMock()
     conan_file.deps_cpp_info = self._creat_deps_cpp_info()
     conan_file.settings = Settings()
     be = AutoToolsBuildEnvironment(conan_file)
     conan_file.should_configure = False
     conan_file.should_build = False
     conan_file.should_install = False
     be.configure()
     self.assertIsNone(conan_file.command)
     be.make()
     self.assertIsNone(conan_file.command)
示例#32
0
 def partial_build_test(self):
     conan_file = ConanFileMock()
     deps_cpp_info = namedtuple("Deps", "libs, include_paths, lib_paths, defines, cflags, "
                                        "cxxflags, sharedlinkflags, exelinkflags, sysroot")
     conan_file.deps_cpp_info = deps_cpp_info([], [], [], [], [], [], [], [], "")
     conan_file.settings = Settings()
     be = AutoToolsBuildEnvironment(conan_file)
     conan_file.should_configure = False
     conan_file.should_build = False
     conan_file.should_install = False
     be.configure()
     self.assertIsNone(conan_file.command)
     be.make()
     self.assertIsNone(conan_file.command)
示例#33
0
 def autotools_prefix_test(self):
     runner = RunnerMock()
     conanfile = MockConanfile(MockSettings({}), None, runner)
     # Package folder is not defined
     ab = AutoToolsBuildEnvironment(conanfile)
     ab.configure()
     self.assertNotIn("--prefix", runner.command_called)
     # package folder defined
     conanfile.package_folder = "/package_folder"
     ab.configure()
     if platform.system() == "Windows":
         self.assertIn("./configure --prefix=/package_folder", runner.command_called)
     else:
         self.assertIn("./configure '--prefix=/package_folder'", runner.command_called)
     # --prefix already used in args
     ab.configure(args=["--prefix=/my_package_folder"])
     if platform.system() == "Windows":
         self.assertIn("./configure --prefix=/my_package_folder", runner.command_called)
         self.assertNotIn("--prefix=/package_folder", runner.command_called)
     else:
         self.assertIn("./configure '--prefix=/my_package_folder'", runner.command_called)
         self.assertNotIn("'--prefix=/package_folder'", runner.command_called)
    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)
    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"])
    def autotools_install_dirs_test(self):

        runner = RunnerMockWithHelp(available_args=default_dirs_flags)
        conanfile = MockConanfileWithOutput(MockSettings({}), None, runner)
        # Package folder is not defined
        ab = AutoToolsBuildEnvironment(conanfile)
        ab.configure()
        self.assertNotIn("--prefix", runner.command_called)
        self.assertNotIn("--bindir", runner.command_called)
        self.assertNotIn("--libdir", runner.command_called)
        self.assertNotIn("--includedir", runner.command_called)
        self.assertNotIn("--dataroot", runner.command_called)
        # package folder defined
        conanfile.package_folder = "/package_folder"
        ab.configure()
        if platform.system() == "Windows":
            self.assertIn(
                "./configure --prefix=/package_folder --bindir=${prefix}/bin "
                "--sbin=${prefix}/bin --libexec=${prefix}/bin --libdir=${prefix}/lib "
                "--includedir=${prefix}/include --oldincludedir=${prefix}/include "
                "--datarootdir=${prefix}/res", runner.command_called)
        else:
            self.assertIn(
                "./configure '--prefix=/package_folder' '--bindir=${prefix}/bin' "
                "'--sbin=${prefix}/bin' '--libexec=${prefix}/bin' '--libdir=${prefix}/lib' "
                "'--includedir=${prefix}/include' '--oldincludedir=${prefix}/include' "
                "'--datarootdir=${prefix}/res'", runner.command_called)
        # --prefix already used in args
        ab.configure(args=["--prefix=/my_package_folder"])
        self.assertIn("--prefix=/my_package_folder", runner.command_called)
        self.assertNotIn("--prefix=/package_folder", runner.command_called)
        # --bindir, --libdir, --includedir already used in args
        ab.configure(args=[
            "--bindir=/pf/superbindir", "--libdir=/pf/superlibdir",
            "--includedir=/pf/superincludedir"
        ])
        self.assertNotIn("--bindir=${prefix}/bin", runner.command_called)
        self.assertNotIn("--libdir=${prefix}/lib", runner.command_called)
        self.assertNotIn("--includedir=${prefix}/lib", runner.command_called)
        if platform.system() == "Windows":
            self.assertIn(
                "./configure --bindir=/pf/superbindir --libdir=/pf/superlibdir "
                "--includedir=/pf/superincludedir --prefix=/package_folder "
                "--sbin=${prefix}/bin --libexec=${prefix}/bin "
                "--oldincludedir=${prefix}/include --datarootdir=${prefix}/res",
                runner.command_called)
        else:
            self.assertIn(
                "./configure '--bindir=/pf/superbindir' '--libdir=/pf/superlibdir' "
                "'--includedir=/pf/superincludedir' '--prefix=/package_folder' "
                "'--sbin=${prefix}/bin' '--libexec=${prefix}/bin' "
                "'--oldincludedir=${prefix}/include' '--datarootdir=${prefix}/res'",
                runner.command_called)
        # opt-out from default installation dirs
        ab.configure(use_default_install_dirs=False)
        self.assertIn("--prefix=/package_folder", runner.command_called)
        self.assertNotIn("--bindir=${prefix}/bin", runner.command_called)
        self.assertNotIn("--libdir=${prefix}/lib", runner.command_called)
        self.assertNotIn("--includedir=${prefix}/lib", runner.command_called)
示例#37
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)