diff options
author | Martin Kelly <mkelly@xevo.com> | 2018-06-04 16:06:02 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-06-07 08:52:55 +0100 |
commit | e14171cc594e8c3dfee8119847c26e10b15bacf4 (patch) | |
tree | f29803be476eac841f621f140a63d3de5b5b8697 /meta/recipes-devtools/meson/meson | |
parent | 2a73be1b0e5adecd29e3dfb3f987d6bc761bc8f3 (diff) | |
download | poky-e14171cc594e8c3dfee8119847c26e10b15bacf4.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.
(From OE-Core rev: aabb846b165fec218024a7a57f3c9fdaa2514179)
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-x | meta/recipes-devtools/meson/meson/meson-setup.py | 62 | ||||
-rwxr-xr-x | meta/recipes-devtools/meson/meson/meson-wrapper | 14 |
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 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | import os | ||
4 | import sys | ||
5 | |||
6 | def bail(msg): | ||
7 | print(msg, file=sys.stderr) | ||
8 | sys.exit(1) | ||
9 | |||
10 | _MARKER = '@@' | ||
11 | def transform_line(line): | ||
12 | # Substitute any special markers of this form: | ||
13 | # @@ENV@@ | ||
14 | # with the value of ENV, split into meson array syntax. | ||
15 | start = line.find(_MARKER) | ||
16 | if start == -1: | ||
17 | return line | ||
18 | |||
19 | end = line.rfind(_MARKER) | ||
20 | if end == start: | ||
21 | return line | ||
22 | |||
23 | # Lookup value of the env var. | ||
24 | var = line[start+len(_MARKER):end] | ||
25 | try: | ||
26 | val = os.environ[var] | ||
27 | except KeyError: | ||
28 | bail('cannot generate meson.cross; env var %s not set' % var) | ||
29 | |||
30 | # Transform into meson array. | ||
31 | val = ["'%s'" % x for x in val.split()] | ||
32 | val = ', '.join(val) | ||
33 | val = '[%s]' % val | ||
34 | |||
35 | before = line[:start] | ||
36 | after = line[end+len(_MARKER):] | ||
37 | |||
38 | return '%s%s%s' % (before, val, after) | ||
39 | |||
40 | # Make sure this is really an SDK extraction environment. | ||
41 | try: | ||
42 | sysroot = os.environ['OECORE_NATIVE_SYSROOT'] | ||
43 | except KeyError: | ||
44 | bail('OECORE_NATIVE_SYSROOT env var must be set') | ||
45 | |||
46 | cross_file = os.path.join(sysroot, 'usr/share/meson/meson.cross') | ||
47 | tmp_cross_file = '%s.tmp' % cross_file | ||
48 | |||
49 | # Read through and transform the current meson.cross. | ||
50 | lines = [] | ||
51 | with open(cross_file, 'r') as f: | ||
52 | for line in f: | ||
53 | lines.append(transform_line(line)) | ||
54 | |||
55 | # Write the transformed result to a tmp file and atomically rename it. In case | ||
56 | # we crash during the file write, we don't want an invalid meson.cross file. | ||
57 | with open(tmp_cross_file, 'w') as f: | ||
58 | for line in lines: | ||
59 | f.write(line) | ||
60 | f.flush() | ||
61 | os.fdatasync(f.fileno()) | ||
62 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if [ -z "$OECORE_NATIVE_SYSROOT" ]; then | ||
4 | echo "OECORE_NATIVE_SYSROOT not set; are you in a Yocto SDK environment?" >&2 | ||
5 | fi | ||
6 | |||
7 | # If these are set to a cross-compile path, meson will get confused and try to | ||
8 | # use them as native tools. Unset them to prevent this, as all the cross-compile | ||
9 | # config is already in meson.cross. | ||
10 | unset CC CXX CPP LD AR NM STRIP | ||
11 | |||
12 | exec "$OECORE_NATIVE_SYSROOT/usr/bin/meson.real" \ | ||
13 | --cross-file "$OECORE_NATIVE_SYSROOT/usr/share/meson/meson.cross" \ | ||
14 | "$@" | ||