From 6f25e93b524ec827a55c13632c9ff23a20d8d3c2 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 14 Nov 2017 15:08:35 -0800 Subject: cross: Implement support for loading cross files from system paths One thing that makes cross compiling with meson a pain is the need for cross files. The problem is not with cross files themselves (they're actually rather brilliant in that they allow for a much greater deal of flexibility than autotools hardcoded paths approach) but that each user needs to reimplement them themselves, when for most people what they really want is a cross file that could be provided by their distro, all they really want is the correct toolchain. This patch is the first stop to making it easier for distros to ship their own cross files (and for users to put their's somewhere safe so they don't get `git clean`ed. It allows the cross files (on Linux and *BSD) to be stored in home and system paths (~/.config/meson/cross, /usr/share/meson/cross, and /usr/local/share/meson/cross), and to be loaded by simply by specificying --cross-file. With this patch meson will check the locations its always checked first, (is cross file absolute, or is it relative to $PWD), then will check ~/.config/meson/cross, /usr/local/share/meson/cross, /usr/share/meson/cross, (or $XDG_CONFIG_PATH and $XDG_DATA_DIRS) for the files, raising an exception if it cannot find the specified cross file. Fixes #2283 --- run_unittests.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index 8af872e..5b3b3e1 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -19,10 +19,12 @@ import shlex import subprocess import re, json import tempfile +import textwrap import os import shutil import sys import unittest +from unittest import mock from configparser import ConfigParser from glob import glob from pathlib import PurePath @@ -2223,6 +2225,50 @@ endian = 'little' self.init(testdir, ['-Db_lto=true'], default_args=False) self.build('reconfigure') + def test_cross_file_system_paths(self): + testdir = os.path.join(self.common_test_dir, '1 trivial') + cross_content = textwrap.dedent("""\ + [binaries] + c = '/usr/bin/cc' + ar = '/usr/bin/ar' + strip = '/usr/bin/ar' + + [properties] + + [host_machine] + system = 'linux' + cpu_family = 'x86' + cpu = 'i686' + endian = 'little' + """) + + with tempfile.TemporaryDirectory() as d: + dir_ = os.path.join(d, 'meson', 'cross') + os.makedirs(dir_) + with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f: + f.write(cross_content) + name = os.path.basename(f.name) + + with mock.patch.dict(os.environ, {'XDG_DATA_HOME': d}): + self.init(testdir, ['--cross-file=' + name], inprocess=True) + self.wipe() + + with mock.patch.dict(os.environ, {'XDG_DATA_DIRS': d}): + os.environ.pop('XDG_DATA_HOME', None) + self.init(testdir, ['--cross-file=' + name], inprocess=True) + self.wipe() + + with tempfile.TemporaryDirectory() as d: + dir_ = os.path.join(d, '.local', 'share', 'meson', 'cross') + os.makedirs(dir_) + with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f: + f.write(cross_content) + name = os.path.basename(f.name) + + with mock.patch('mesonbuild.coredata.os.path.expanduser', lambda x: x.replace('~', d)): + self.init(testdir, ['--cross-file=' + name], inprocess=True) + self.wipe() + class LinuxArmCrossCompileTests(BasePlatformTests): ''' -- cgit v1.1