From 8596f871ef834a38e3375443f7eb08e43816347a Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Mon, 7 Jan 2019 15:07:43 +0000 Subject: 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. Signed-off-by: Ross Burton --- meta/recipes-devtools/meson/meson/meson-setup.py | 69 +++++++----------------- 1 file changed, 19 insertions(+), 50 deletions(-) (limited to 'meta/recipes-devtools/meson/meson/meson-setup.py') diff --git a/meta/recipes-devtools/meson/meson/meson-setup.py b/meta/recipes-devtools/meson/meson/meson-setup.py index a9749eae9d..808e2a062f 100755 --- a/meta/recipes-devtools/meson/meson/meson-setup.py +++ b/meta/recipes-devtools/meson/meson/meson-setup.py @@ -1,62 +1,31 @@ #!/usr/bin/env python3 import os +import string 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) +class Template(string.Template): + delimiter = "@" - # Transform into meson array. - val = ["'%s'" % x for x in val.split()] - val = ', '.join(val) - val = '[%s]' % val +class Environ(): + def __getitem__(self, name): + val = os.environ[name] + val = ["'%s'" % x for x in val.split()] + val = ', '.join(val) + val = '[%s]' % val + return 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 + print("Not in environment setup, bailing") + sys.exit(1) -# 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)) +template_file = os.path.join(sysroot, 'usr/share/meson/meson.cross.template') +cross_file = os.path.join(sysroot, 'usr/share/meson/%smeson.cross' % os.environ["TARGET_PREFIX"]) -# 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) +with open(template_file) as in_file: + template = in_file.read() + output = Template(template).substitute(Environ()) + with open(cross_file, "w") as out_file: + out_file.write(output) -- cgit 1.2.3-korg