poky/meta/lib/oe/go.py
Ross Burton 18319c08ad lib/oe/go: document map_arch, and raise an error on unknown architecture
Add a comment explaining what this function does and where the values
come from.

If the architecture isn't know, instead of returning an empty string
which could fail mysteriously, raise a KeyError so it fails quickly.

(From OE-Core rev: 025414c16319b068df1cd757ad9a3c987a6b871d)

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2025-06-23 21:42:54 +01:00

39 lines
984 B
Python

#
# Copyright OpenEmbedded Contributors
#
# SPDX-License-Identifier: MIT
#
import re
def map_arch(a):
"""
Map our architecture names to Go's GOARCH names.
See https://github.com/golang/go/blob/master/src/internal/syslist/syslist.go for the complete list.
"""
if re.match('i.86', a):
return '386'
elif a == 'x86_64':
return 'amd64'
elif re.match('arm.*', a):
return 'arm'
elif re.match('aarch64.*', a):
return 'arm64'
elif re.match('mips64el.*', a):
return 'mips64le'
elif re.match('mips64.*', a):
return 'mips64'
elif a == 'mips':
return 'mips'
elif a == 'mipsel':
return 'mipsle'
elif re.match('p(pc|owerpc)(64le)', a):
return 'ppc64le'
elif re.match('p(pc|owerpc)(64)', a):
return 'ppc64'
elif a == 'riscv64':
return 'riscv64'
elif a == 'loongarch64':
return 'loong64'
raise KeyError(f"Cannot map architecture {a}")