def test_aix(self):
        with mock.patch("platform.machine", mock.MagicMock(return_value='00FB91F44C00')),\
                mock.patch("platform.processor", mock.MagicMock(return_value='powerpc')),\
                mock.patch("platform.system", mock.MagicMock(return_value='AIX')),\
                mock.patch("conans.client.tools.oss.OSInfo.get_aix_conf", mock.MagicMock(return_value='32')),\
                mock.patch('subprocess.check_output', mock.MagicMock(return_value='7.1.0.0')):
            self.assertEqual('ppc32', detected_architecture())

        with mock.patch("platform.machine", mock.MagicMock(return_value='00FB91F44C00')),\
                mock.patch("platform.processor", mock.MagicMock(return_value='powerpc')),\
                mock.patch("platform.system", mock.MagicMock(return_value='AIX')),\
                mock.patch("conans.client.tools.oss.OSInfo.get_aix_conf", mock.MagicMock(return_value='64')),\
                mock.patch('subprocess.check_output', mock.MagicMock(return_value='7.1.0.0')):
            self.assertEqual('ppc64', detected_architecture())
    def test_solaris(self):
        with mock.patch("platform.machine", mock.MagicMock(return_value='sun4v')),\
                mock.patch("platform.processor", mock.MagicMock(return_value='sparc')),\
                mock.patch("platform.system", mock.MagicMock(return_value='SunOS')),\
                mock.patch("platform.architecture", mock.MagicMock(return_value=('64bit', 'ELF'))),\
                mock.patch("platform.release", mock.MagicMock(return_value='5.11')):
            self.assertEqual('sparcv9', detected_architecture())

        with mock.patch("platform.machine", mock.MagicMock(return_value='i86pc')),\
                mock.patch("platform.processor", mock.MagicMock(return_value='i386')),\
                mock.patch("platform.system", mock.MagicMock(return_value='SunOS')),\
                mock.patch("platform.architecture", mock.MagicMock(return_value=('64bit', 'ELF'))),\
                mock.patch("platform.release", mock.MagicMock(return_value='5.11')):
            self.assertEqual('x86_64', detected_architecture())
    def test_various(self, mocked_machine, expected_arch):

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value=mocked_machine)):
            self.assertEqual(
                expected_arch, detected_architecture(),
                "given '%s' expected '%s'" % (mocked_machine, expected_arch))
Exemple #4
0
    def _get_host_build_target_flags(self):
        """Based on google search for build/host triplets, it could need a lot
        and complex verification"""

        arch_detected = detected_architecture() or platform.machine()
        os_detected = detected_os() or platform.system()

        if self._os_target and self._arch_target:
            try:
                target = get_gnu_triplet(self._os_target, self._arch_target,
                                         self._compiler)
            except ConanException as exc:
                self._conanfile.output.warn(str(exc))
                target = None
        else:
            target = None

        if os_detected is None or arch_detected is None or self._arch is None or self._os is None:
            return False, False, target
        if not cross_building(self._conanfile.settings, os_detected,
                              arch_detected):
            return False, False, target

        try:
            build = get_gnu_triplet(os_detected, arch_detected, self._compiler)
        except ConanException as exc:
            self._conanfile.output.warn(str(exc))
            build = None
        try:
            host = get_gnu_triplet(self._os, self._arch, self._compiler)
        except ConanException as exc:
            self._conanfile.output.warn(str(exc))
            host = None
        return build, host, target
Exemple #5
0
 def _get_build_os_arch(self):
     if hasattr(self._conanfile, 'settings_build'):
         os_build, arch_build = get_build_os_arch(self._conanfile)
     else:
         # FIXME: Why not use 'os_build' and 'arch_build' from conanfile.settings?
         os_build = detected_os() or platform.system()
         arch_build = detected_architecture() or platform.machine()
     return arch_build, os_build
Exemple #6
0
def vcvars_command(settings,
                   arch=None,
                   compiler_version=None,
                   force=False,
                   vcvars_ver=None,
                   winsdk_version=None,
                   output=None):
    output = default_output(output, 'conans.client.tools.win.vcvars_command')

    arch_setting = arch or settings.get_safe("arch")

    compiler = settings.get_safe("compiler")
    if compiler == 'Visual Studio':
        compiler_version = compiler_version or settings.get_safe(
            "compiler.version")
    else:
        # vcvars might be still needed for other compilers, e.g. clang-cl or Intel C++,
        # as they might be using Microsoft STL and other tools
        # (e.g. resource compiler, manifest tool, etc)
        # in this case, use the latest Visual Studio available on the machine
        last_version = latest_vs_version_installed(output=output)

        compiler_version = compiler_version or last_version
    os_setting = settings.get_safe("os")
    if not compiler_version:
        raise ConanException(
            "compiler.version setting required for vcvars not defined")

    # https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx
    arch_setting = arch_setting or 'x86_64'
    arch_build = settings.get_safe("arch_build") or detected_architecture()
    if arch_build == 'x86_64':
        # Only uses x64 tooling if arch_build explicitly defines it, otherwise
        # Keep the VS default, which is x86 toolset
        # This will probably be changed in conan 2.0
        if ((settings.get_safe("arch_build")
             or os.getenv("PreferredToolArchitecture") == "x64")
                and int(compiler_version) >= 12):
            x86_cross = "amd64_x86"
        else:
            x86_cross = "x86"
        vcvars_arch = {
            'x86': x86_cross,
            'x86_64': 'amd64',
            'armv7': 'amd64_arm',
            'armv8': 'amd64_arm64'
        }.get(arch_setting)
    elif arch_build == 'x86':
        vcvars_arch = {
            'x86': 'x86',
            'x86_64': 'x86_amd64',
            'armv7': 'x86_arm',
            'armv8': 'x86_arm64'
        }.get(arch_setting)

    if not vcvars_arch:
        raise ConanException('unsupported architecture %s' % arch_setting)

    existing_version = os.environ.get("VisualStudioVersion")

    if existing_version:
        command = ["echo Conan:vcvars already set"]
        existing_version = existing_version.split(".")[0]
        if existing_version != compiler_version:
            message = "Visual environment already set to %s\n " \
                      "Current settings visual version: %s" % (existing_version, compiler_version)
            if not force:
                raise ConanException("Error, %s" % message)
            else:
                output.warn(message)
    else:
        vs_path = vs_installation_path(str(compiler_version))

        if not vs_path or not os.path.isdir(vs_path):
            raise ConanException(
                "VS non-existing installation: Visual Studio %s" %
                str(compiler_version))
        else:
            if int(compiler_version) > 14:
                vcvars_path = os.path.join(vs_path,
                                           "VC/Auxiliary/Build/vcvarsall.bat")
                command = [
                    'set "VSCMD_START_DIR=%%CD%%" && '
                    'call "%s" %s' % (vcvars_path, vcvars_arch)
                ]
            else:
                vcvars_path = os.path.join(vs_path, "VC/vcvarsall.bat")
                command = ['call "%s" %s' % (vcvars_path, vcvars_arch)]
        if int(compiler_version) >= 14:
            if winsdk_version:
                command.append(winsdk_version)
            if vcvars_ver:
                command.append("-vcvars_ver=%s" % vcvars_ver)

    if os_setting == 'WindowsStore':
        os_version_setting = settings.get_safe("os.version")
        if os_version_setting == '8.1':
            command.append('store 8.1')
        elif os_version_setting == '10.0':
            windows_10_sdk = find_windows_10_sdk()
            if not windows_10_sdk:
                raise ConanException(
                    "cross-compiling for WindowsStore 10 (UWP), "
                    "but Windows 10 SDK wasn't found")
            command.append('store %s' % windows_10_sdk)
        else:
            raise ConanException('unsupported Windows Store version %s' %
                                 os_version_setting)
    return " ".join(command)
Exemple #7
0
def vcvars_command(settings, arch=None, compiler_version=None, force=False):
    arch_setting = arch or settings.get_safe("arch")
    compiler_version = compiler_version or settings.get_safe("compiler.version")
    os_setting = settings.get_safe("os")
    if not compiler_version:
        raise ConanException("compiler.version setting required for vcvars not defined")

    # https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx
    arch_setting = arch_setting or 'x86_64'
    if detected_architecture() == 'x86_64':
        vcvars_arch = {'x86': 'x86',
                       'x86_64': 'amd64',
                       'armv7': 'amd64_arm',
                       'armv8': 'amd64_arm64'}.get(arch_setting)
    elif detected_architecture() == 'x86':
        vcvars_arch = {'x86': 'x86',
                       'x86_64': 'x86_amd64',
                       'armv7': 'x86_arm',
                       'armv8': 'x86_arm64'}.get(arch_setting)
    if not vcvars_arch:
        raise ConanException('unsupported architecture %s' % arch_setting)

    command = ""
    existing_version = os.environ.get("VisualStudioVersion")

    if existing_version:
        command = "echo Conan:vcvars already set"
        existing_version = existing_version.split(".")[0]
        if existing_version != compiler_version:
            message = "Visual environment already set to %s\n " \
                      "Current settings visual version: %s" % (existing_version, compiler_version)
            if not force:
                raise ConanException("Error, %s" % message)
            else:
                _global_output.warn(message)
    else:
        vs_path = vs_installation_path(str(compiler_version))

        if not vs_path or not os.path.isdir(vs_path):
            _global_output.warn("VS non-existing installation")
        else:
            vcvars_path = ""
            if int(compiler_version) > 14:
                vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")
                command = ('set "VSCMD_START_DIR=%%CD%%" && '
                           'call "%s" %s' % (vcvars_path, vcvars_arch))
            else:
                vcvars_path = os.path.join(vs_path, "VC/vcvarsall.bat")
                command = ('call "%s" %s' % (vcvars_path, vcvars_arch))

    if os_setting == 'WindowsStore':
        os_version_setting = settings.get_safe("os.version")
        if os_version_setting == '8.1':
            command += ' store 8.1'
        elif os_version_setting == '10.0':
            windows_10_sdk = find_windows_10_sdk()
            if not windows_10_sdk:
                raise ConanException("cross-compiling for WindowsStore 10 (UWP), "
                                     "but Windows 10 SDK wasn't found")
            command += ' store ' + windows_10_sdk
        else:
            raise ConanException('unsupported Windows Store version %s' % os_version_setting)
    return command
Exemple #8
0
def vcvars_command(conanfile=None,
                   arch=None,
                   compiler_version=None,
                   force=False,
                   vcvars_ver=None,
                   winsdk_version=None,
                   output=None,
                   settings=None):
    # Handle input arguments (backwards compatibility with 'settings' as first argument)
    # TODO: This can be promoted to a decorator pattern for any function
    if conanfile and settings:
        raise ConanException(
            "Do not set both arguments, 'conanfile' and 'settings',"
            " to call 'vcvars_command' function")

    from conans.model.conan_file import ConanFile
    if conanfile and not isinstance(conanfile, ConanFile):
        return vcvars_command(settings=conanfile,
                              arch=arch,
                              compiler_version=compiler_version,
                              force=force,
                              vcvars_ver=vcvars_ver,
                              winsdk_version=winsdk_version,
                              output=output)

    if settings:
        warnings.warn(
            "argument 'settings' has been deprecated, use 'conanfile' instead")

    if not conanfile:
        # TODO: If Conan is using 'profile_build' here we don't have any information about it,
        #   we are falling back to the old behavior (which is probably wrong here)
        conanfile = namedtuple('_ConanFile', ['settings'])(settings)
    del settings

    # Here starts the actual implementation for this function
    output = default_output(output, 'conans.client.tools.win.vcvars_command')

    arch_setting = arch or conanfile.settings.get_safe("arch")

    compiler = conanfile.settings.get_safe("compiler")
    compiler_base = conanfile.settings.get_safe("compiler.base")
    if compiler == 'Visual Studio':
        compiler_version = compiler_version or conanfile.settings.get_safe(
            "compiler.version")
    elif compiler_base == "Visual Studio":
        compiler_version = compiler_version or conanfile.settings.get_safe(
            "compiler.base.version")
    else:
        # vcvars might be still needed for other compilers, e.g. clang-cl or Intel C++,
        # as they might be using Microsoft STL and other tools
        # (e.g. resource compiler, manifest tool, etc)
        # in this case, use the latest Visual Studio available on the machine
        last_version = latest_vs_version_installed(output=output)

        compiler_version = compiler_version or last_version
    os_setting = conanfile.settings.get_safe("os")
    if not compiler_version:
        raise ConanException(
            "compiler.version setting required for vcvars not defined")

    # https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx
    vcvars_arch = None
    arch_setting = arch_setting or 'x86_64'

    _, settings_arch_build = get_build_os_arch(conanfile)
    arch_build = settings_arch_build
    if not hasattr(conanfile, 'settings_build'):
        arch_build = arch_build or detected_architecture()

    if os_setting == 'WindowsCE':
        vcvars_arch = "x86"
    elif arch_build == 'x86_64':
        # Only uses x64 tooling if arch_build explicitly defines it, otherwise
        # Keep the VS default, which is x86 toolset
        # This will probably be changed in conan 2.0
        if ((settings_arch_build
             or os.getenv("PreferredToolArchitecture") == "x64")
                and int(compiler_version) >= 12):
            x86_cross = "amd64_x86"
        else:
            x86_cross = "x86"
        vcvars_arch = {
            'x86': x86_cross,
            'x86_64': 'amd64',
            'armv7': 'amd64_arm',
            'armv8': 'amd64_arm64'
        }.get(arch_setting)
    elif arch_build == 'x86':
        vcvars_arch = {
            'x86': 'x86',
            'x86_64': 'x86_amd64',
            'armv7': 'x86_arm',
            'armv8': 'x86_arm64'
        }.get(arch_setting)

    if not vcvars_arch:
        raise ConanException('unsupported architecture %s' % arch_setting)

    existing_version = os.environ.get("VisualStudioVersion")

    if existing_version:
        command = ["echo Conan:vcvars already set"]
        existing_version = existing_version.split(".")[0]
        if existing_version != compiler_version:
            message = "Visual environment already set to %s\n " \
                      "Current settings visual version: %s" % (existing_version, compiler_version)
            if not force:
                raise ConanException("Error, %s" % message)
            else:
                output.warn(message)
    else:
        vs_path = vs_installation_path(str(compiler_version))

        if not vs_path or not os.path.isdir(vs_path):
            raise ConanException(
                "VS non-existing installation: Visual Studio %s" %
                str(compiler_version))
        else:
            if int(compiler_version) > 14:
                vcvars_path = os.path.join(vs_path,
                                           "VC/Auxiliary/Build/vcvarsall.bat")
                command = [
                    'set "VSCMD_START_DIR=%%CD%%" && '
                    'call "%s" %s' % (vcvars_path, vcvars_arch)
                ]
            else:
                vcvars_path = os.path.join(vs_path, "VC/vcvarsall.bat")
                command = ['call "%s" %s' % (vcvars_path, vcvars_arch)]
        if int(compiler_version) >= 14:
            if winsdk_version:
                command.append(winsdk_version)
            if vcvars_ver:
                command.append("-vcvars_ver=%s" % vcvars_ver)

        if os_setting == 'WindowsStore':
            os_version_setting = conanfile.settings.get_safe("os.version")
            if os_version_setting == '8.1':
                winsdk_version = winsdk_version or "8.1"
                command.append('store %s' % winsdk_version)
            elif os_version_setting == '10.0':
                winsdk_version = winsdk_version or find_windows_10_sdk()
                if not winsdk_version:
                    raise ConanException(
                        "cross-compiling for WindowsStore 10 (UWP), "
                        "but Windows 10 SDK wasn't found")
                command.append('store %s' % winsdk_version)
            else:
                raise ConanException('unsupported Windows Store version %s' %
                                     os_version_setting)
    return " ".join(command)
Exemple #9
0
def vcvars_command(settings, arch=None, compiler_version=None, force=False):
    arch_setting = arch or settings.get_safe("arch")
    compiler_version = compiler_version or settings.get_safe("compiler.version")
    os_setting = settings.get_safe("os")
    if not compiler_version:
        raise ConanException("compiler.version setting required for vcvars not defined")

    # https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx
    arch_setting = arch_setting or 'x86_64'
    if detected_architecture() == 'x86_64':
        vcvars_arch = {'x86': 'x86',
                       'x86_64': 'amd64',
                       'armv7': 'amd64_arm',
                       'armv8': 'amd64_arm64'}.get(arch_setting)
    elif detected_architecture() == 'x86':
        vcvars_arch = {'x86': 'x86',
                       'x86_64': 'x86_amd64',
                       'armv7': 'x86_arm',
                       'armv8': 'x86_arm64'}.get(arch_setting)
    if not vcvars_arch:
        raise ConanException('unsupported architecture %s' % arch_setting)
    existing_version = os.environ.get("VisualStudioVersion")
    if existing_version:
        command = "echo Conan:vcvars already set"
        existing_version = existing_version.split(".")[0]
        if existing_version != compiler_version:
            message = "Visual environment already set to %s\n " \
                      "Current settings visual version: %s" % (existing_version, compiler_version)
            if not force:
                raise ConanException("Error, %s" % message)
            else:
                _global_output.warn(message)
    else:
        env_var = "vs%s0comntools" % compiler_version

        if env_var == 'vs150comntools':
            vs_path = os.getenv(env_var)
            if not vs_path:  # Try to locate with vswhere
                vs_root = vs_installation_path("15")
                if vs_root:
                    vs_path = os.path.join(vs_root, "Common7", "Tools")
                else:
                    raise ConanException("VS2017 '%s' variable not defined, "
                                         "and vswhere didn't find it" % env_var)
            if not os.path.isdir(vs_path):
                _global_output.warn('VS variable %s points to the non-existing path "%s",'
                    'please check that you have set it correctly' % (env_var, vs_path))
            vcvars_path = os.path.join(vs_path, "../../VC/Auxiliary/Build/vcvarsall.bat")
            command = ('set "VSCMD_START_DIR=%%CD%%" && '
                       'call "%s" %s' % (vcvars_path, vcvars_arch))
        else:
            try:
                vs_path = os.environ[env_var]
            except KeyError:
                raise ConanException("VS '%s' variable not defined. Please install VS" % env_var)
            if not os.path.isdir(vs_path):
                _global_output.warn('VS variable %s points to the non-existing path "%s",'
                    'please check that you have set it correctly' % (env_var, vs_path))
            vcvars_path = os.path.join(vs_path, "../../VC/vcvarsall.bat")
            command = ('call "%s" %s' % (vcvars_path, vcvars_arch))

    if os_setting == 'WindowsStore':
        os_version_setting = settings.get_safe("os.version")
        if os_version_setting == '8.1':
            command += ' store 8.1'
        elif os_version_setting == '10.0':
            windows_10_sdk = find_windows_10_sdk()
            if not windows_10_sdk:
                raise ConanException("cross-compiling for WindowsStore 10 (UWP), "
                                     "but Windows 10 SDK wasn't found")
            command += ' store ' + windows_10_sdk
        else:
            raise ConanException('unsupported Windows Store version %s' % os_version_setting)
    return command
 def test_e2k(self, processor, expected_arch):
     with mock.patch("platform.machine", mock.MagicMock(return_value='e2k')), \
             mock.patch("platform.processor", mock.MagicMock(return_value=processor)):
         self.assertEqual(expected_arch, detected_architecture())
Exemple #11
0
def vcvars_command(settings, arch=None, compiler_version=None, force=False):
    arch_setting = arch or settings.get_safe("arch")
    compiler_version = compiler_version or settings.get_safe("compiler.version")
    os_setting = settings.get_safe("os")
    if not compiler_version:
        raise ConanException("compiler.version setting required for vcvars not defined")

    # https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx
    arch_setting = arch_setting or 'x86_64'
    if detected_architecture() == 'x86_64':
        vcvars_arch = {'x86': 'x86',
                       'x86_64': 'amd64',
                       'armv7': 'amd64_arm',
                       'armv8': 'amd64_arm64'}.get(arch_setting)
    elif detected_architecture() == 'x86':
        vcvars_arch = {'x86': 'x86',
                       'x86_64': 'x86_amd64',
                       'armv7': 'x86_arm',
                       'armv8': 'x86_arm64'}.get(arch_setting)
    if not vcvars_arch:
        raise ConanException('unsupported architecture %s' % arch_setting)

    command = ""
    existing_version = os.environ.get("VisualStudioVersion")

    if existing_version:
        command = "echo Conan:vcvars already set"
        existing_version = existing_version.split(".")[0]
        if existing_version != compiler_version:
            message = "Visual environment already set to %s\n " \
                      "Current settings visual version: %s" % (existing_version, compiler_version)
            if not force:
                raise ConanException("Error, %s" % message)
            else:
                _global_output.warn(message)
    else:
        vs_path = vs_installation_path(str(compiler_version))

        if not vs_path or not os.path.isdir(vs_path):
            raise ConanException("VS non-existing installation: Visual Studio %s" % str(compiler_version))
        else:
            vcvars_path = ""
            if int(compiler_version) > 14:
                vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")
                command = ('set "VSCMD_START_DIR=%%CD%%" && '
                           'call "%s" %s' % (vcvars_path, vcvars_arch))
            else:
                vcvars_path = os.path.join(vs_path, "VC/vcvarsall.bat")
                command = ('call "%s" %s' % (vcvars_path, vcvars_arch))

    if os_setting == 'WindowsStore':
        os_version_setting = settings.get_safe("os.version")
        if os_version_setting == '8.1':
            command += ' store 8.1'
        elif os_version_setting == '10.0':
            windows_10_sdk = find_windows_10_sdk()
            if not windows_10_sdk:
                raise ConanException("cross-compiling for WindowsStore 10 (UWP), "
                                     "but Windows 10 SDK wasn't found")
            command += ' store ' + windows_10_sdk
        else:
            raise ConanException('unsupported Windows Store version %s' % os_version_setting)
    return command
Exemple #12
0
    def test_toolchain_linux(self, build_type, arch, cppstd, libcxx, shared,
                             fpic):
        settings_mock = _MockSettings(build_type, arch, cppstd, libcxx)
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.options = {"shared": [True, False], "fPIC": [True, False]}
        conanfile.default_options = {"shared": shared, "fPIC": fpic}
        conanfile.initialize(settings_mock, EnvValues())
        toolchain = MakeToolchain(conanfile)
        content = toolchain.content

        expected_template = Template(
            textwrap.dedent("""
            # Conan generated toolchain file
            ifndef CONAN_TOOLCHAIN_INCLUDED
                CONAN_TOOLCHAIN_INCLUDED = TRUE
                CONAN_TC_BUILD_TYPE = {{build_type}}
                CONAN_TC_OS_HOST = None
                CONAN_TC_ARCH_HOST = {{arch_host}}
                CONAN_TC_TRIPLET_HOST = False
                CONAN_TC_OS_BUILD = Linux
                CONAN_TC_ARCH_BUILD = {{arch_build}}
                CONAN_TC_TRIPLET_BUILD = False
                CONAN_TC_OS_TARGET = None
                CONAN_TC_ARCH_TARGET = None
                CONAN_TC_TRIPLET_TARGET = None
                CONAN_TC_COMPILER = {{compiler}}
                CONAN_TC_COMPILER_VERSION = {{compiler_version}}
                CONAN_TC_COMPILER_RUNTIME = None
                CONAN_TC_LIBCXX = {{libcxx}}
                CONAN_TC_CPPSTD_FLAG = {{cppstd_flag}}
                CONAN_TC_ARCH_FLAG = {{arch_flag}}
                CONAN_TC_BUILD_TYPE_FLAGS = {{build_type_flags}}
                CONAN_TC_DEFINES ={{preserved_space}}

                CONAN_TC_SET_LIBCXX = True
                CONAN_TC_SET_CPPSTD = True
                CONAN_TC_SET_ARCH = True
                CONAN_TC_SET_FPIC = {{set_fpic}}
                CONAN_TC_SET_SHARED = {{set_shared}}

                CONAN_TC_CFLAGS += $(CONAN_TC_BUILD_TYPE_FLAGS)
                CONAN_TC_CXXFLAGS += $(CONAN_TC_BUILD_TYPE_FLAGS)

                ifeq ($(CONAN_TC_BUILD_TYPE),Release)
                    CONAN_TC_DEFINES += NDEBUG
                endif

                ifeq ($(CONAN_TC_SET_LIBCXX),True)
                    CONAN_TC_CLANG_BASED := $(if $(filter $(CONAN_TC_COMPILER),clang apple-clang),true)
                    ifeq ($(CONAN_TC_CLANG_BASED),True)
                        CONAN_TC_LIBSTDCXX_BASED := $(if $(filter $(CONAN_TC_LIBCXX),libstdc++ libstdc++11),true)
                        ifeq ($(CONAN_TC_LIBSTDCXX_BASED),True)
                            CONAN_TC_CXXFLAGS += -stdlib=libstdc++
                        else ifeq ($(CONAN_TC_LIBCXX),libc++)
                            CONAN_TC_CXXFLAGS += -stdlib=libc++
                        endif
                    else ifeq ($(CONAN_TC_COMPILER),sun-cc)
                        ifeq ($(CONAN_TC_LIBCXX),libCstd)
                            CONAN_TC_CXXFLAGS += -library=Cstd++
                        else ifeq ($(CONAN_TC_LIBCXX),libstdcxx)
                            CONAN_TC_CXXFLAGS += -library=stdcxx4
                        else ifeq ($(CONAN_TC_LIBCXX),libstlport)
                            CONAN_TC_CXXFLAGS += -library=stlport4
                        else ifeq ($(CONAN_TC_LIBCXX),libstdc++)
                            CONAN_TC_CXXFLAGS += -library=stdcpp
                        endif
                    endif
                    ifeq ($(CONAN_TC_LIBCXX),libstdc++11)
                        CONAN_TC_DEFINES += GLIBCXX_USE_CXX11_ABI=1
                    else ifeq ($(CONAN_TC_LIBCXX),libstdc++)
                        CONAN_TC_DEFINES += GLIBCXX_USE_CXX11_ABI=0
                    endif
                endif
                ifeq ($(CONAN_TC_SET_CPPSTD),True)
                    CONAN_TC_CXXFLAGS += $(CONAN_TC_CPPSTD_FLAG)
                endif
                ifeq ($(CONAN_TC_SET_ARCH),True)
                    CONAN_TC_CFLAGS += $(CONAN_TC_ARCH_FLAG)
                    CONAN_TC_CXXFLAGS += $(CONAN_TC_ARCH_FLAG)
                    CONAN_TC_SHARED_LINKER_FLAGS += $(CONAN_TC_ARCH_FLAG)
                    CONAN_TC_EXE_LINKER_FLAGS += $(CONAN_TC_ARCH_FLAG)
                endif
                ifeq ($(CONAN_TC_SET_FPIC),True)
                    CONAN_TC_CFLAGS += -fPIC
                    CONAN_TC_CXXFLAGS += -fPIC
                    CONAN_TC_SHARED_LINKER_FLAGS += -fPIC
                    CONAN_TC_EXE_LINKER_FLAGS += -pie
                endif
                ifeq ($(CONAN_TC_SET_SHARED),True)
                    CONAN_TC_LDFLAGS += -shared
                    CONAN_TC_LDFLAGS += $(CONAN_TC_SHARED_LINKER_FLAGS)
                else
                    CONAN_TC_LDFLAGS += $(CONAN_TC_EXE_LINKER_FLAGS)
                endif
            endif

            CONAN_TC_CPPFLAGS += $(addprefix -D,$(CONAN_TC_DEFINES))

            # Call this function in your Makefile to have Conan variables added to the standard variables
            # Example:  $(call CONAN_TC_SETUP)

            CONAN_TC_SETUP =  \\
                $(eval CFLAGS += $(CONAN_TC_CFLAGS)) ; \\
                $(eval CXXFLAGS += $(CONAN_TC_CXXFLAGS)) ; \\
                $(eval CPPFLAGS += $(CONAN_TC_CPPFLAGS)) ; \\
                $(eval LDFLAGS += $(CONAN_TC_LDFLAGS)) ;
        """))

        context = {
            "arch_host": conanfile.settings.get_safe("arch"),
            "arch_build": detected_architecture(),
            "compiler": conanfile.settings.get_safe("compiler"),
            "compiler_version":
            conanfile.settings.get_safe("compiler.version"),
            "arch_flag": architecture_flag(settings_mock),
            "cppstd_flag": cppstd_flag_new(conanfile.settings),
            "build_type_flags": " ".join(build_type_flags(conanfile.settings)),
            "build_type": build_type,
            "libcxx": libcxx,
            "set_shared": shared,
            "set_fpic": fpic,
            "preserved_space": " ",
        }
        #
        expected_content = expected_template.render(context)

        self.maxDiff = None
        self.assertIn(expected_content, content)
    def test_various(self):

        # x86
        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='i386')):
            self.assertEqual('x86', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='i686')):
            self.assertEqual('x86', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='x86_64')):
            self.assertEqual('x86_64', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='amd64')):
            self.assertEqual('x86_64', detected_architecture())

        # ARM
        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='aarch64_be')):
            self.assertEqual('armv8', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='armv8b')):
            self.assertEqual('armv8', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='armv7l')):
            self.assertEqual('armv7', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='armv6l')):
            self.assertEqual('armv6', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='arm')):
            self.assertEqual('armv6', detected_architecture())

        # PowerPC
        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='ppc64le')):
            self.assertEqual('ppc64le', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='ppc64')):
            self.assertEqual('ppc64', detected_architecture())

        # MIPS
        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='mips')):
            self.assertEqual('mips', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='mips64')):
            self.assertEqual('mips64', detected_architecture())

        # SPARC
        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='sparc')):
            self.assertEqual('sparc', detected_architecture())

        with mock.patch("platform.machine",
                        mock.MagicMock(return_value='sparc64')):
            self.assertEqual('sparcv9', detected_architecture())