mirror of
https://git.yoctoproject.org/poky
synced 2026-06-02 13:29:49 +00:00
meson: fix nativesdk-meson for multilib SDKs
Multilib SDKs differ only in the environment variables set, so nativesdk-meson's setup script needs to write a cross file for each environment. Rename the shipped meson.cross to meson.cross.template, as it cannot be used directly. Now that post-relocate scripts are called once for each environment, the generated meson.cross can be prefixed with TARGET_PREFIX to ensure it is unique. Finally rewrite the setup script to use string.Template to perform the expansion instead of hand-coding the logic. (From OE-Core rev: 8596f871ef834a38e3375443f7eb08e43816347a) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
3bda6b8e0a
commit
c2556c44ec
@@ -1,62 +1,31 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def bail(msg):
|
class Template(string.Template):
|
||||||
print(msg, file=sys.stderr)
|
delimiter = "@"
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
_MARKER = '@@'
|
class Environ():
|
||||||
def transform_line(line):
|
def __getitem__(self, name):
|
||||||
# Substitute any special markers of this form:
|
val = os.environ[name]
|
||||||
# @@ENV@@
|
val = ["'%s'" % x for x in val.split()]
|
||||||
# with the value of ENV, split into meson array syntax.
|
val = ', '.join(val)
|
||||||
start = line.find(_MARKER)
|
val = '[%s]' % val
|
||||||
if start == -1:
|
return val
|
||||||
return line
|
|
||||||
|
|
||||||
end = line.rfind(_MARKER)
|
|
||||||
if end == start:
|
|
||||||
return line
|
|
||||||
|
|
||||||
# Lookup value of the env var.
|
|
||||||
var = line[start+len(_MARKER):end]
|
|
||||||
try:
|
|
||||||
val = os.environ[var]
|
|
||||||
except KeyError:
|
|
||||||
bail('cannot generate meson.cross; env var %s not set' % var)
|
|
||||||
|
|
||||||
# Transform into meson array.
|
|
||||||
val = ["'%s'" % x for x in val.split()]
|
|
||||||
val = ', '.join(val)
|
|
||||||
val = '[%s]' % val
|
|
||||||
|
|
||||||
before = line[:start]
|
|
||||||
after = line[end+len(_MARKER):]
|
|
||||||
|
|
||||||
return '%s%s%s' % (before, val, after)
|
|
||||||
|
|
||||||
# Make sure this is really an SDK extraction environment.
|
|
||||||
try:
|
try:
|
||||||
sysroot = os.environ['OECORE_NATIVE_SYSROOT']
|
sysroot = os.environ['OECORE_NATIVE_SYSROOT']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
bail('OECORE_NATIVE_SYSROOT env var must be set')
|
print("Not in environment setup, bailing")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
cross_file = os.path.join(sysroot, 'usr/share/meson/meson.cross')
|
template_file = os.path.join(sysroot, 'usr/share/meson/meson.cross.template')
|
||||||
tmp_cross_file = '%s.tmp' % cross_file
|
cross_file = os.path.join(sysroot, 'usr/share/meson/%smeson.cross' % os.environ["TARGET_PREFIX"])
|
||||||
|
|
||||||
# Read through and transform the current meson.cross.
|
with open(template_file) as in_file:
|
||||||
lines = []
|
template = in_file.read()
|
||||||
with open(cross_file, 'r') as f:
|
output = Template(template).substitute(Environ())
|
||||||
for line in f:
|
with open(cross_file, "w") as out_file:
|
||||||
lines.append(transform_line(line))
|
out_file.write(output)
|
||||||
|
|
||||||
# Write the transformed result to a tmp file and atomically rename it. In case
|
|
||||||
# we crash during the file write, we don't want an invalid meson.cross file.
|
|
||||||
with open(tmp_cross_file, 'w') as f:
|
|
||||||
for line in lines:
|
|
||||||
f.write(line)
|
|
||||||
f.flush()
|
|
||||||
os.fdatasync(f.fileno())
|
|
||||||
os.rename(tmp_cross_file, cross_file)
|
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ fi
|
|||||||
unset CC CXX CPP LD AR NM STRIP
|
unset CC CXX CPP LD AR NM STRIP
|
||||||
|
|
||||||
exec "$OECORE_NATIVE_SYSROOT/usr/bin/meson.real" \
|
exec "$OECORE_NATIVE_SYSROOT/usr/bin/meson.real" \
|
||||||
--cross-file "$OECORE_NATIVE_SYSROOT/usr/share/meson/meson.cross" \
|
--cross-file "${OECORE_NATIVE_SYSROOT}/usr/share/meson/${TARGET_PREFIX}meson.cross" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ inherit nativesdk
|
|||||||
SRC_URI += "file://meson-setup.py \
|
SRC_URI += "file://meson-setup.py \
|
||||||
file://meson-wrapper"
|
file://meson-wrapper"
|
||||||
|
|
||||||
def meson_array(var, d):
|
|
||||||
return "', '".join(d.getVar(var).split()).join(("'", "'"))
|
|
||||||
|
|
||||||
# both are required but not used by meson
|
# both are required but not used by meson
|
||||||
MESON_SDK_ENDIAN = "bogus-endian"
|
MESON_SDK_ENDIAN = "bogus-endian"
|
||||||
MESON_TARGET_ENDIAN = "bogus-endian"
|
MESON_TARGET_ENDIAN = "bogus-endian"
|
||||||
@@ -17,32 +14,31 @@ MESON_C_ARGS = "${MESON_TOOLCHAIN_ARGS} ${BUILDSDK_CFLAGS}"
|
|||||||
MESON_CPP_ARGS = "${MESON_TOOLCHAIN_ARGS} ${BUILDSDK_CXXFLAGS}"
|
MESON_CPP_ARGS = "${MESON_TOOLCHAIN_ARGS} ${BUILDSDK_CXXFLAGS}"
|
||||||
MESON_LINK_ARGS = "${MESON_TOOLCHAIN_ARGS} ${BUILDSDK_LDFLAGS}"
|
MESON_LINK_ARGS = "${MESON_TOOLCHAIN_ARGS} ${BUILDSDK_LDFLAGS}"
|
||||||
|
|
||||||
# This logic is similar but not identical to that in meson.bbclass, since it's
|
# The cross file logic is similar but not identical to that in meson.bbclass,
|
||||||
# generating for an SDK rather than a cross-compile. Important differences are:
|
# since it's generating for an SDK rather than a cross-compile. Important
|
||||||
|
# differences are:
|
||||||
# - We can't set vars like CC, CXX, etc. yet because they will be filled in with
|
# - We can't set vars like CC, CXX, etc. yet because they will be filled in with
|
||||||
# real paths by meson-setup.sh when the SDK is extracted.
|
# real paths by meson-setup.sh when the SDK is extracted.
|
||||||
# - Some overrides aren't needed, since the SDK injects paths that take care of
|
# - Some overrides aren't needed, since the SDK injects paths that take care of
|
||||||
# them.
|
# them.
|
||||||
addtask write_config before do_install
|
do_install_append() {
|
||||||
do_write_config[vardeps] += "MESON_C_ARGS MESON_CPP_ARGS MESON_LINK_ARGS CC CXX LD AR NM STRIP READELF"
|
install -d ${D}${datadir}/meson
|
||||||
do_write_config() {
|
cat >${D}${datadir}/meson/meson.cross.template <<EOF
|
||||||
# This needs to be Py to split the args into single-element lists
|
|
||||||
cat >${WORKDIR}/meson.cross <<EOF
|
|
||||||
[binaries]
|
[binaries]
|
||||||
c = @@CC@@
|
c = @CC
|
||||||
cpp = @@CXX@@
|
cpp = @CXX
|
||||||
ar = @@AR@@
|
ar = @AR
|
||||||
nm = @@NM@@
|
nm = @NM
|
||||||
ld = @@LD@@
|
ld = @LD
|
||||||
strip = @@STRIP@@
|
strip = @STRIP
|
||||||
pkgconfig = 'pkg-config'
|
pkgconfig = 'pkg-config'
|
||||||
|
|
||||||
[properties]
|
[properties]
|
||||||
needs_exe_wrapper = true
|
needs_exe_wrapper = true
|
||||||
c_args = @@CFLAGS@@
|
c_args = @CFLAGS
|
||||||
c_link_args = @@LDFLAGS@@
|
c_link_args = @LDFLAGS
|
||||||
cpp_args = @@CPPFLAGS@@
|
cpp_args = @CPPFLAGS
|
||||||
cpp_link_args = @@LDFLAGS@@
|
cpp_link_args = @LDFLAGS
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
system = '${SDK_OS}'
|
system = '${SDK_OS}'
|
||||||
@@ -50,11 +46,6 @@ cpu_family = '${SDK_ARCH}'
|
|||||||
cpu = '${SDK_ARCH}'
|
cpu = '${SDK_ARCH}'
|
||||||
endian = '${MESON_SDK_ENDIAN}'
|
endian = '${MESON_SDK_ENDIAN}'
|
||||||
EOF
|
EOF
|
||||||
}
|
|
||||||
|
|
||||||
do_install_append() {
|
|
||||||
install -d ${D}${datadir}/meson
|
|
||||||
install -m 0644 ${WORKDIR}/meson.cross ${D}${datadir}/meson/
|
|
||||||
|
|
||||||
install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d
|
install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d
|
||||||
install -m 0755 ${WORKDIR}/meson-setup.py ${D}${SDKPATHNATIVE}/post-relocate-setup.d/
|
install -m 0755 ${WORKDIR}/meson-setup.py ${D}${SDKPATHNATIVE}/post-relocate-setup.d/
|
||||||
|
|||||||
Reference in New Issue
Block a user