aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/meson/meson
diff options
context:
space:
mode:
authorMartin Kelly <mkelly@xevo.com>2018-06-04 16:06:02 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-06-07 08:52:13 +0100
commitaabb846b165fec218024a7a57f3c9fdaa2514179 (patch)
tree4eddcd18c508b71ef7ae803409e9b7a1278339ca /meta/recipes-devtools/meson/meson
parentf80567874c8c30e43d39599dd73dd4a67eff8103 (diff)
downloadopenembedded-core-contrib-aabb846b165fec218024a7a57f3c9fdaa2514179.tar.gz
meson: enable nativesdk
Currently, we can't build meson into SDKs because we don't autogenerate the required meson.cross file. Enable this by using the post-relocate hooks and generating a meson.cross file based on the SDK environment passed into the post-relocate hook. Signed-off-by: Martin Kelly <mkelly@xevo.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/meson/meson')
-rwxr-xr-xmeta/recipes-devtools/meson/meson/meson-setup.py62
-rwxr-xr-xmeta/recipes-devtools/meson/meson/meson-wrapper14
2 files changed, 76 insertions, 0 deletions
diff --git a/meta/recipes-devtools/meson/meson/meson-setup.py b/meta/recipes-devtools/meson/meson/meson-setup.py
new file mode 100755
index 0000000000..a9749eae9d
--- /dev/null
+++ b/meta/recipes-devtools/meson/meson/meson-setup.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+
+def bail(msg):
+ print(msg, file=sys.stderr)
+ sys.exit(1)
+
+_MARKER = '@@'
+def transform_line(line):
+ # Substitute any special markers of this form:
+ # @@ENV@@
+ # with the value of ENV, split into meson array syntax.
+ start = line.find(_MARKER)
+ if start == -1:
+ 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:
+ sysroot = os.environ['OECORE_NATIVE_SYSROOT']
+except KeyError:
+ bail('OECORE_NATIVE_SYSROOT env var must be set')
+
+cross_file = os.path.join(sysroot, 'usr/share/meson/meson.cross')
+tmp_cross_file = '%s.tmp' % cross_file
+
+# Read through and transform the current meson.cross.
+lines = []
+with open(cross_file, 'r') as f:
+ for line in f:
+ lines.append(transform_line(line))
+
+# 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)
diff --git a/meta/recipes-devtools/meson/meson/meson-wrapper b/meta/recipes-devtools/meson/meson/meson-wrapper
new file mode 100755
index 0000000000..b2e00da513
--- /dev/null
+++ b/meta/recipes-devtools/meson/meson/meson-wrapper
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+if [ -z "$OECORE_NATIVE_SYSROOT" ]; then
+ echo "OECORE_NATIVE_SYSROOT not set; are you in a Yocto SDK environment?" >&2
+fi
+
+# If these are set to a cross-compile path, meson will get confused and try to
+# use them as native tools. Unset them to prevent this, as all the cross-compile
+# config is already in meson.cross.
+unset CC CXX CPP LD AR NM STRIP
+
+exec "$OECORE_NATIVE_SYSROOT/usr/bin/meson.real" \
+ --cross-file "$OECORE_NATIVE_SYSROOT/usr/share/meson/meson.cross" \
+ "$@"