From 2601cff17c8c0383a962f05ef16105d0cfab5b2a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 2 Oct 2024 14:39:34 +0100 Subject: [PATCH] env2mfile: Base cpu on DEB_HOST_GNU_CPU unless DEB_HOST_ARCH is special `DEB_HOST_ARCH` encodes both the CPU family and the OS, so using it to get the CPU type gives the wrong answer for non-Linux ports. However, `DEB_HOST_GNU_CPU` gives less detailed information about the CPU: it's `arm` for all 32-bit ARM CPUs, and doesn't distinguish between the differing baselines of `armel` (ARMv5 softfloat) and `armhf` (ARMv7 hardfloat). When cross-compiling for x86_64 Linux, this changes the `cpu()` from `amd64` to `x86_64`, which is consistent with the answer we get during native builds on that architecture. When cross-compiling for `ppc64el`, this changes the `cpu()` from `ppc64el` to `ppc64`, which is a reasonable change but is still not consistent with what we see during native builds (which is `ppc64le`): see #13741 for that. Signed-off-by: Simon McVittie --- mesonbuild/scripts/env2mfile.py | 13 ++++++++++--- unittests/internaltests.py | 13 ++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/mesonbuild/scripts/env2mfile.py b/mesonbuild/scripts/env2mfile.py index 190f23419fa8..f42c282d9e1c 100755 --- a/mesonbuild/scripts/env2mfile.py +++ b/mesonbuild/scripts/env2mfile.py @@ -143,14 +143,20 @@ def get_args_from_envvars(infos: MachineInfo) -> None: if objcpp_link_args: infos.link_args['objcpp'] = objcpp_link_args +# map from DEB_HOST_GNU_CPU to Meson machine.cpu_family() deb_cpu_family_map = { 'mips64el': 'mips64', 'i686': 'x86', 'powerpc64le': 'ppc64', } -deb_cpu_map = { +# map from DEB_HOST_ARCH to Meson machine.cpu() +deb_arch_cpu_map = { 'armhf': 'arm7hlf', +} + +# map from DEB_HOST_GNU_CPU to Meson machine.cpu() +deb_cpu_map = { 'mips64el': 'mips64', 'powerpc64le': 'ppc64', } @@ -212,8 +218,9 @@ def dpkg_architecture_to_machine_info(output: str, options: T.Any) -> MachineInf data['DEB_HOST_ARCH_OS']) host_cpu_family = deb_cpu_family_map.get(data['DEB_HOST_GNU_CPU'], data['DEB_HOST_GNU_CPU']) - host_cpu = deb_cpu_map.get(data['DEB_HOST_ARCH'], - data['DEB_HOST_ARCH']) + host_cpu = deb_arch_cpu_map.get(data['DEB_HOST_ARCH'], + deb_cpu_map.get(data['DEB_HOST_GNU_CPU'], + data['DEB_HOST_GNU_CPU'])) host_endian = data['DEB_HOST_ARCH_ENDIAN'] compilerstems = [('c', 'gcc'), diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 40cfe55cc139..f7e5076576fd 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -1846,9 +1846,7 @@ def locate_path(program: str) -> T.List[str]: system='linux', subsystem='linux', kernel='linux', - # TODO: In native builds we get x86_64, but in - # cross-builds it's amd64 - cpu='TODO', + cpu='x86_64', cpu_family='x86_64', endian='little', ), @@ -1981,8 +1979,7 @@ def locate_path(program: str) -> T.List[str]: # fail when kernel() is called. # https://github.com/mesonbuild/meson/issues/13740 kernel='TODO', - # TODO: Currently hurd-i386, but should be i686 - cpu='TODO', + cpu='i686', cpu_family='x86', endian='little', ), @@ -2037,8 +2034,7 @@ def locate_path(program: str) -> T.List[str]: system='kfreebsd', subsystem='kfreebsd', kernel='freebsd', - # TODO: Currently kfreebsd-amd64 but should be x86_64 - cpu='TODO', + cpu='x86_64', cpu_family='x86_64', endian='little', ), @@ -2148,8 +2144,7 @@ def locate_path(program: str) -> T.List[str]: system='linux', subsystem='linux', kernel='linux', - # TODO: Currently ppc64el, but native builds have ppc64le, - # and maybe it should be ppc64 in both cases? + # TODO: Currently ppc64, but native builds have ppc64le # https://github.com/mesonbuild/meson/issues/13741 cpu='TODO', cpu_family='ppc64',