diff options
author | Martin Kelly <mkelly@xevo.com> | 2018-06-04 16:06:01 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-06-07 08:52:55 +0100 |
commit | 2a73be1b0e5adecd29e3dfb3f987d6bc761bc8f3 (patch) | |
tree | 2e952256eca1ce1dc89a1f08e723df1bcf61db55 | |
parent | aa497e057b27e580a1d280a4d99311f6309c3d55 (diff) | |
download | poky-2a73be1b0e5adecd29e3dfb3f987d6bc761bc8f3.tar.gz |
meson: handle exe wrappers
Add patches to enable meson to handle being wrapped with a shell script. This
will enable us to do so for supporting the SDK, which requires us to setup env
vars and point to a meson.cross file inside the SDK.
These patches are all merged upstream, so we can drop them soon.
(From OE-Core rev: f80567874c8c30e43d39599dd73dd4a67eff8103)
Signed-off-by: Martin Kelly <mkelly@xevo.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
3 files changed, 1041 insertions, 0 deletions
diff --git a/meta/recipes-devtools/meson/meson/0004-Prettifying-some-output-with-pathlib.patch b/meta/recipes-devtools/meson/meson/0004-Prettifying-some-output-with-pathlib.patch new file mode 100644 index 0000000000..e75633beb9 --- /dev/null +++ b/meta/recipes-devtools/meson/meson/0004-Prettifying-some-output-with-pathlib.patch | |||
@@ -0,0 +1,188 @@ | |||
1 | From 253ab5bf6d6d925abcf625b72f5fcacf99be13bd Mon Sep 17 00:00:00 2001 | ||
2 | From: Niklas Claesson <nicke.claesson@gmail.com> | ||
3 | Date: Wed, 18 Apr 2018 15:25:03 +0200 | ||
4 | Subject: [PATCH] Prettifying some output with pathlib | ||
5 | |||
6 | This is a backport required in order to make | ||
7 | 0005-Set-the-meson-command-to-use-when-we-know-what-it-is.patch apply. | ||
8 | |||
9 | Upstream-Status: Accepted [https://github.com/mesonbuild/meson/pull/3423] | ||
10 | Should be in the 0.47.0 release. | ||
11 | |||
12 | Signed-off-by: Martin Kelly <mkelly@xevo.com> | ||
13 | --- | ||
14 | run_cross_test.py | 6 ++++-- | ||
15 | run_project_tests.py | 51 +++++++++++++++++++++++++++++---------------------- | ||
16 | 2 files changed, 33 insertions(+), 24 deletions(-) | ||
17 | |||
18 | diff --git a/run_cross_test.py b/run_cross_test.py | ||
19 | index e285e218..71914028 100755 | ||
20 | --- a/run_cross_test.py | ||
21 | +++ b/run_cross_test.py | ||
22 | @@ -22,13 +22,15 @@ Not part of the main test suite because of two reasons: | ||
23 | |||
24 | Eventually migrate to something fancier.''' | ||
25 | |||
26 | -import sys, os | ||
27 | +import sys | ||
28 | +import os | ||
29 | +from pathlib import Path | ||
30 | |||
31 | from run_project_tests import gather_tests, run_tests, StopException, setup_commands | ||
32 | from run_project_tests import failing_logs | ||
33 | |||
34 | def runtests(cross_file): | ||
35 | - commontests = [('common', gather_tests('test cases/common'), False)] | ||
36 | + commontests = [('common', gather_tests(Path('test cases', 'common')), False)] | ||
37 | try: | ||
38 | (passing_tests, failing_tests, skipped_tests) = run_tests(commontests, 'meson-cross-test-run', ['--cross', cross_file]) | ||
39 | except StopException: | ||
40 | diff --git a/run_project_tests.py b/run_project_tests.py | ||
41 | index 8c02a9ee..3c516240 100755 | ||
42 | --- a/run_project_tests.py | ||
43 | +++ b/run_project_tests.py | ||
44 | @@ -14,14 +14,22 @@ | ||
45 | # See the License for the specific language governing permissions and | ||
46 | # limitations under the License. | ||
47 | |||
48 | -from glob import glob | ||
49 | import itertools | ||
50 | -import os, subprocess, shutil, sys, signal | ||
51 | +import os | ||
52 | +import subprocess | ||
53 | +import shutil | ||
54 | +import sys | ||
55 | +import signal | ||
56 | from io import StringIO | ||
57 | from ast import literal_eval | ||
58 | from enum import Enum | ||
59 | import tempfile | ||
60 | -from mesonbuild import build, environment, mesonlib, mlog, mtest | ||
61 | +from pathlib import Path, PurePath | ||
62 | +from mesonbuild import build | ||
63 | +from mesonbuild import environment | ||
64 | +from mesonbuild import mesonlib | ||
65 | +from mesonbuild import mlog | ||
66 | +from mesonbuild import mtest | ||
67 | from mesonbuild.mesonlib import stringlistify, Popen_safe | ||
68 | from mesonbuild.coredata import backendlist | ||
69 | import argparse | ||
70 | @@ -198,7 +206,7 @@ def validate_install(srcdir, installdir, compiler, env): | ||
71 | |||
72 | def log_text_file(logfile, testdir, stdo, stde): | ||
73 | global stop, executor, futures | ||
74 | - logfile.write('%s\nstdout\n\n---\n' % testdir) | ||
75 | + logfile.write('%s\nstdout\n\n---\n' % testdir.as_posix()) | ||
76 | logfile.write(stdo) | ||
77 | logfile.write('\n\n---\n\nstderr\n\n---\n') | ||
78 | logfile.write(stde) | ||
79 | @@ -245,11 +253,11 @@ def run_test_inprocess(testdir): | ||
80 | sys.stderr = mystderr = StringIO() | ||
81 | old_cwd = os.getcwd() | ||
82 | os.chdir(testdir) | ||
83 | - test_log_fname = 'meson-logs/testlog.txt' | ||
84 | + test_log_fname = Path('meson-logs', 'testlog.txt') | ||
85 | try: | ||
86 | returncode_test = mtest.run(['--no-rebuild']) | ||
87 | - if os.path.exists(test_log_fname): | ||
88 | - test_log = open(test_log_fname, errors='ignore').read() | ||
89 | + if test_log_fname.exists(): | ||
90 | + test_log = test_log_fname.open(errors='ignore').read() | ||
91 | else: | ||
92 | test_log = '' | ||
93 | returncode_benchmark = mtest.run(['--no-rebuild', '--benchmark', '--logbase', 'benchmarklog']) | ||
94 | @@ -318,9 +326,8 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen | ||
95 | gen_args += [testdir, test_build_dir] + flags + test_args + extra_args | ||
96 | (returncode, stdo, stde) = run_configure(meson_command, gen_args) | ||
97 | try: | ||
98 | - logfile = os.path.join(test_build_dir, 'meson-logs/meson-log.txt') | ||
99 | - with open(logfile, encoding='utf-8', errors='ignore') as f: | ||
100 | - mesonlog = f.read() | ||
101 | + logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt') | ||
102 | + mesonlog = logfile.open(errors='ignore', encoding='utf-8').read() | ||
103 | except Exception: | ||
104 | mesonlog = no_meson_log_msg | ||
105 | gen_time = time.time() - gen_start | ||
106 | @@ -390,11 +397,11 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen | ||
107 | return TestResult(validate_install(testdir, install_dir, compiler, builddata.environment), | ||
108 | BuildStep.validate, stdo, stde, mesonlog, gen_time, build_time, test_time) | ||
109 | |||
110 | -def gather_tests(testdir): | ||
111 | - tests = [t.replace('\\', '/').split('/', 2)[2] for t in glob(testdir + '/*')] | ||
112 | +def gather_tests(testdir: Path): | ||
113 | + tests = [t.name for t in testdir.glob('*')] | ||
114 | testlist = [(int(t.split()[0]), t) for t in tests] | ||
115 | testlist.sort() | ||
116 | - tests = [os.path.join(testdir, t[1]) for t in testlist] | ||
117 | + tests = [testdir / t[1] for t in testlist] | ||
118 | return tests | ||
119 | |||
120 | def have_d_compiler(): | ||
121 | @@ -517,7 +524,7 @@ def detect_tests_to_run(): | ||
122 | ('fpga', 'fpga', shutil.which('yosys') is None), | ||
123 | ('frameworks', 'frameworks', False), | ||
124 | ] | ||
125 | - gathered_tests = [(name, gather_tests('test cases/' + subdir), skip) for name, subdir, skip in all_tests] | ||
126 | + gathered_tests = [(name, gather_tests(Path('test cases', subdir)), skip) for name, subdir, skip in all_tests] | ||
127 | return gathered_tests | ||
128 | |||
129 | def run_tests(all_tests, log_name_base, extra_args): | ||
130 | @@ -566,18 +573,18 @@ def _run_tests(all_tests, log_name_base, extra_args): | ||
131 | for t in test_cases: | ||
132 | # Jenkins screws us over by automatically sorting test cases by name | ||
133 | # and getting it wrong by not doing logical number sorting. | ||
134 | - (testnum, testbase) = os.path.split(t)[-1].split(' ', 1) | ||
135 | + (testnum, testbase) = t.name.split(' ', 1) | ||
136 | testname = '%.3d %s' % (int(testnum), testbase) | ||
137 | should_fail = False | ||
138 | if name.startswith('failing'): | ||
139 | should_fail = name.split('failing-')[1] | ||
140 | - result = executor.submit(run_test, skipped, t, extra_args, system_compiler, backend, backend_flags, commands, should_fail) | ||
141 | + result = executor.submit(run_test, skipped, t.as_posix(), extra_args, system_compiler, backend, backend_flags, commands, should_fail) | ||
142 | futures.append((testname, t, result)) | ||
143 | for (testname, t, result) in futures: | ||
144 | sys.stdout.flush() | ||
145 | result = result.result() | ||
146 | - if (result is None) or (('MESON_SKIP_TEST' in result.stdo) and (skippable(name, t))): | ||
147 | - print(yellow('Skipping:'), t) | ||
148 | + if (result is None) or (('MESON_SKIP_TEST' in result.stdo) and (skippable(name, t.as_posix()))): | ||
149 | + print(yellow('Skipping:'), t.as_posix()) | ||
150 | current_test = ET.SubElement(current_suite, 'testcase', {'name': testname, | ||
151 | 'classname': name}) | ||
152 | ET.SubElement(current_test, 'skipped', {}) | ||
153 | @@ -585,7 +592,7 @@ def _run_tests(all_tests, log_name_base, extra_args): | ||
154 | else: | ||
155 | without_install = "" if len(install_commands) > 0 else " (without install)" | ||
156 | if result.msg != '': | ||
157 | - print(red('Failed test{} during {}: {!r}'.format(without_install, result.step.name, t))) | ||
158 | + print(red('Failed test{} during {}: {!r}'.format(without_install, result.step.name, t.as_posix()))) | ||
159 | print('Reason:', result.msg) | ||
160 | failing_tests += 1 | ||
161 | if result.step == BuildStep.configure and result.mlog != no_meson_log_msg: | ||
162 | @@ -597,7 +604,7 @@ def _run_tests(all_tests, log_name_base, extra_args): | ||
163 | failing_logs.append(result.stdo) | ||
164 | failing_logs.append(result.stde) | ||
165 | else: | ||
166 | - print('Succeeded test%s: %s' % (without_install, t)) | ||
167 | + print('Succeeded test%s: %s' % (without_install, t.as_posix())) | ||
168 | passing_tests += 1 | ||
169 | conf_time += result.conftime | ||
170 | build_time += result.buildtime | ||
171 | @@ -641,7 +648,7 @@ def check_format(): | ||
172 | |||
173 | def check_meson_commands_work(): | ||
174 | global backend, meson_command, compile_commands, test_commands, install_commands | ||
175 | - testdir = 'test cases/common/1 trivial' | ||
176 | + testdir = PurePath('test cases', 'common', '1 trivial').as_posix() | ||
177 | with AutoDeletedDir(tempfile.mkdtemp(prefix='b ', dir='.')) as build_dir: | ||
178 | print('Checking that configuring works...') | ||
179 | gen_cmd = mesonlib.meson_command + [testdir, build_dir] + backend_flags | ||
180 | @@ -706,7 +713,7 @@ if __name__ == '__main__': | ||
181 | except UnicodeError: | ||
182 | print(l.encode('ascii', errors='replace').decode(), '\n') | ||
183 | for name, dirs, skip in all_tests: | ||
184 | - dirs = (os.path.basename(x) for x in dirs) | ||
185 | + dirs = (x.name for x in dirs) | ||
186 | for k, g in itertools.groupby(dirs, key=lambda x: x.split()[0]): | ||
187 | tests = list(g) | ||
188 | if len(tests) != 1: | ||
diff --git a/meta/recipes-devtools/meson/meson/0005-Set-the-meson-command-to-use-when-we-know-what-it-is.patch b/meta/recipes-devtools/meson/meson/0005-Set-the-meson-command-to-use-when-we-know-what-it-is.patch new file mode 100644 index 0000000000..8fb277a150 --- /dev/null +++ b/meta/recipes-devtools/meson/meson/0005-Set-the-meson-command-to-use-when-we-know-what-it-is.patch | |||
@@ -0,0 +1,851 @@ | |||
1 | From 717480549bea68ed2da1420141f64c1c15cda11d Mon Sep 17 00:00:00 2001 | ||
2 | From: Nirbheek Chauhan <nirbheek@centricular.com> | ||
3 | Date: Fri, 1 Jun 2018 13:00:17 +0530 | ||
4 | Subject: [PATCH] Set the meson command to use when we know what it is | ||
5 | |||
6 | Instead of using fragile guessing to figure out how to invoke meson, | ||
7 | set the value when meson is run. Also rework how we pass of | ||
8 | meson_script_launcher to regenchecker.py -- it wasn't even being used | ||
9 | |||
10 | With this change, we only need to guess the meson path when running | ||
11 | the tests, and in that case: | ||
12 | |||
13 | 1. If MESON_EXE is set in the env, we know how to run meson | ||
14 | for project tests. | ||
15 | 2. MESON_EXE is not set, which means we run the configure in-process | ||
16 | for project tests and need to guess what meson to run, so either | ||
17 | - meson.py is found next to run_tests.py, or | ||
18 | - meson, meson.py, or meson.exe is in PATH | ||
19 | |||
20 | Otherwise, you can invoke meson in the following ways: | ||
21 | |||
22 | 1. meson is installed, and mesonbuild is available in PYTHONPATH: | ||
23 | - meson, meson.py, meson.exe from PATH | ||
24 | - python3 -m mesonbuild.mesonmain | ||
25 | - python3 /path/to/meson.py | ||
26 | - meson is a shell wrapper to meson.real | ||
27 | 2. meson is not installed, and is run from git: | ||
28 | - Absolute path to meson.py | ||
29 | - Relative path to meson.py | ||
30 | - Symlink to meson.py | ||
31 | |||
32 | All these are tested in test_meson_commands.py, except meson.exe since | ||
33 | that involves building the meson msi and installing it. | ||
34 | |||
35 | Upstream-Status: Accepted [https://github.com/mesonbuild/meson/pull/3654] | ||
36 | Should be in the 0.47.0 release. | ||
37 | |||
38 | Signed-off-by: Martin Kelly <mkelly@xevo.com> | ||
39 | --- | ||
40 | meson.py | 17 ++-- | ||
41 | mesonbuild/environment.py | 6 +- | ||
42 | mesonbuild/mesonlib.py | 48 +--------- | ||
43 | mesonbuild/mesonmain.py | 34 +++++-- | ||
44 | mesonbuild/scripts/regen_checker.py | 6 +- | ||
45 | run_meson_command_tests.py | 186 ++++++++++++++++++++++++++++++++++++ | ||
46 | run_project_tests.py | 20 ++-- | ||
47 | run_tests.py | 43 +++++++-- | ||
48 | run_unittests.py | 64 +++++-------- | ||
49 | 9 files changed, 297 insertions(+), 127 deletions(-) | ||
50 | create mode 100755 run_meson_command_tests.py | ||
51 | |||
52 | diff --git a/meson.py b/meson.py | ||
53 | index abbac6f4..dc84b513 100755 | ||
54 | --- a/meson.py | ||
55 | +++ b/meson.py | ||
56 | @@ -14,13 +14,16 @@ | ||
57 | # See the License for the specific language governing permissions and | ||
58 | # limitations under the License. | ||
59 | |||
60 | -from mesonbuild import mesonmain | ||
61 | -import sys, os | ||
62 | +import sys | ||
63 | +from pathlib import Path | ||
64 | + | ||
65 | +# If we're run uninstalled, add the script directory to sys.path to ensure that | ||
66 | +# we always import the correct mesonbuild modules even if PYTHONPATH is mangled | ||
67 | +meson_exe = Path(sys.argv[0]).resolve() | ||
68 | +if (meson_exe.parent / 'mesonbuild').is_dir(): | ||
69 | + sys.path.insert(0, meson_exe.parent) | ||
70 | |||
71 | -def main(): | ||
72 | - # Always resolve the command path so Ninja can find it for regen, tests, etc. | ||
73 | - launcher = os.path.realpath(sys.argv[0]) | ||
74 | - return mesonmain.run(sys.argv[1:], launcher) | ||
75 | +from mesonbuild import mesonmain | ||
76 | |||
77 | if __name__ == '__main__': | ||
78 | - sys.exit(main()) | ||
79 | + sys.exit(mesonmain.main()) | ||
80 | diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py | ||
81 | index 15b37378..d02a8370 100644 | ||
82 | --- a/mesonbuild/environment.py | ||
83 | +++ b/mesonbuild/environment.py | ||
84 | @@ -263,10 +263,9 @@ class Environment: | ||
85 | log_dir = 'meson-logs' | ||
86 | coredata_file = os.path.join(private_dir, 'coredata.dat') | ||
87 | |||
88 | - def __init__(self, source_dir, build_dir, main_script_launcher, options, original_cmd_line_args): | ||
89 | + def __init__(self, source_dir, build_dir, options, original_cmd_line_args): | ||
90 | self.source_dir = source_dir | ||
91 | self.build_dir = build_dir | ||
92 | - self.meson_script_launcher = main_script_launcher | ||
93 | self.scratch_dir = os.path.join(build_dir, Environment.private_dir) | ||
94 | self.log_dir = os.path.join(build_dir, Environment.log_dir) | ||
95 | os.makedirs(self.scratch_dir, exist_ok=True) | ||
96 | @@ -279,7 +278,8 @@ class Environment: | ||
97 | # re-initialized with project options by the interpreter during | ||
98 | # build file parsing. | ||
99 | self.coredata = coredata.CoreData(options) | ||
100 | - self.coredata.meson_script_launcher = self.meson_script_launcher | ||
101 | + # Used by the regenchecker script, which runs meson | ||
102 | + self.coredata.meson_command = mesonlib.meson_command | ||
103 | self.first_invocation = True | ||
104 | if self.coredata.cross_file: | ||
105 | self.cross_info = CrossBuildInfo(self.coredata.cross_file) | ||
106 | diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py | ||
107 | index 2a3b920b..01561658 100644 | ||
108 | --- a/mesonbuild/mesonlib.py | ||
109 | +++ b/mesonbuild/mesonlib.py | ||
110 | @@ -38,58 +38,12 @@ except Exception: | ||
111 | |||
112 | from glob import glob | ||
113 | |||
114 | -def detect_meson_py_location(): | ||
115 | - c = sys.argv[0] | ||
116 | - c_dir, c_fname = os.path.split(c) | ||
117 | - | ||
118 | - # get the absolute path to the <mesontool> folder | ||
119 | - m_dir = None | ||
120 | - if os.path.isabs(c): | ||
121 | - # $ /foo/<mesontool>.py <args> | ||
122 | - m_dir = c_dir | ||
123 | - elif c_dir == '': | ||
124 | - # $ <mesontool> <args> (gets run from /usr/bin/<mesontool>) | ||
125 | - in_path_exe = shutil.which(c_fname) | ||
126 | - if in_path_exe: | ||
127 | - if not os.path.isabs(in_path_exe): | ||
128 | - m_dir = os.getcwd() | ||
129 | - c_fname = in_path_exe | ||
130 | - else: | ||
131 | - m_dir, c_fname = os.path.split(in_path_exe) | ||
132 | - else: | ||
133 | - m_dir = os.path.abspath(c_dir) | ||
134 | - | ||
135 | - # find meson in m_dir | ||
136 | - if m_dir is not None: | ||
137 | - for fname in ['meson', 'meson.py']: | ||
138 | - m_path = os.path.join(m_dir, fname) | ||
139 | - if os.path.exists(m_path): | ||
140 | - return m_path | ||
141 | - | ||
142 | - # No meson found, which means that either: | ||
143 | - # a) meson is not installed | ||
144 | - # b) meson is installed to a non-standard location | ||
145 | - # c) the script that invoked mesonlib is not the one of meson tools (e.g. run_unittests.py) | ||
146 | - fname = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'meson.py')) | ||
147 | - if os.path.exists(fname): | ||
148 | - return fname | ||
149 | - # If meson is still not found, we might be imported by out-of-source tests | ||
150 | - # https://github.com/mesonbuild/meson/issues/3015 | ||
151 | - exe = shutil.which('meson') | ||
152 | - if exe is None: | ||
153 | - exe = shutil.which('meson.py') | ||
154 | - if exe is not None: | ||
155 | - return exe | ||
156 | - # Give up. | ||
157 | - raise RuntimeError('Could not determine how to run Meson. Please file a bug with details.') | ||
158 | - | ||
159 | if os.path.basename(sys.executable) == 'meson.exe': | ||
160 | # In Windows and using the MSI installed executable. | ||
161 | - meson_command = [sys.executable] | ||
162 | python_command = [sys.executable, 'runpython'] | ||
163 | else: | ||
164 | python_command = [sys.executable] | ||
165 | - meson_command = python_command + [detect_meson_py_location()] | ||
166 | +meson_command = None | ||
167 | |||
168 | def is_ascii_string(astring): | ||
169 | try: | ||
170 | diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py | ||
171 | index 2b6281d7..67f99439 100644 | ||
172 | --- a/mesonbuild/mesonmain.py | ||
173 | +++ b/mesonbuild/mesonmain.py | ||
174 | @@ -73,9 +73,8 @@ def filter_builtin_options(args, original_args): | ||
175 | |||
176 | class MesonApp: | ||
177 | |||
178 | - def __init__(self, dir1, dir2, script_launcher, handshake, options, original_cmd_line_args): | ||
179 | + def __init__(self, dir1, dir2, handshake, options, original_cmd_line_args): | ||
180 | (self.source_dir, self.build_dir) = self.validate_dirs(dir1, dir2, handshake) | ||
181 | - self.meson_script_launcher = script_launcher | ||
182 | self.options = options | ||
183 | self.original_cmd_line_args = original_cmd_line_args | ||
184 | |||
185 | @@ -129,7 +128,7 @@ class MesonApp: | ||
186 | env.coredata.pkgconf_envvar = curvar | ||
187 | |||
188 | def generate(self): | ||
189 | - env = environment.Environment(self.source_dir, self.build_dir, self.meson_script_launcher, self.options, self.original_cmd_line_args) | ||
190 | + env = environment.Environment(self.source_dir, self.build_dir, self.options, self.original_cmd_line_args) | ||
191 | mlog.initialize(env.get_log_dir()) | ||
192 | with mesonlib.BuildDirLock(self.build_dir): | ||
193 | self._generate(env) | ||
194 | @@ -268,12 +267,27 @@ def run_script_command(args): | ||
195 | raise MesonException('Unknown internal command {}.'.format(cmdname)) | ||
196 | return cmdfunc(cmdargs) | ||
197 | |||
198 | -def run(original_args, mainfile=None): | ||
199 | +def set_meson_command(mainfile): | ||
200 | + if mainfile.endswith('.exe'): | ||
201 | + mesonlib.meson_command = [mainfile] | ||
202 | + elif os.path.isabs(mainfile) and mainfile.endswith('mesonmain.py'): | ||
203 | + # Can't actually run meson with an absolute path to mesonmain.py, it must be run as -m mesonbuild.mesonmain | ||
204 | + mesonlib.meson_command = mesonlib.python_command + ['-m', 'mesonbuild.mesonmain'] | ||
205 | + else: | ||
206 | + mesonlib.meson_command = mesonlib.python_command + [mainfile] | ||
207 | + # This won't go into the log file because it's not initialized yet, and we | ||
208 | + # need this value for unit tests. | ||
209 | + if 'MESON_COMMAND_TESTS' in os.environ: | ||
210 | + mlog.log('meson_command is {!r}'.format(mesonlib.meson_command)) | ||
211 | + | ||
212 | +def run(original_args, mainfile): | ||
213 | if sys.version_info < (3, 5): | ||
214 | print('Meson works correctly only with python 3.5+.') | ||
215 | print('You have python %s.' % sys.version) | ||
216 | print('Please update your environment') | ||
217 | return 1 | ||
218 | + # Set the meson command that will be used to run scripts and so on | ||
219 | + set_meson_command(mainfile) | ||
220 | args = original_args[:] | ||
221 | if len(args) > 0: | ||
222 | # First check if we want to run a subcommand. | ||
223 | @@ -351,9 +365,7 @@ def run(original_args, mainfile=None): | ||
224 | else: | ||
225 | dir2 = '.' | ||
226 | try: | ||
227 | - if mainfile is None: | ||
228 | - raise AssertionError('I iz broken. Sorry.') | ||
229 | - app = MesonApp(dir1, dir2, mainfile, handshake, options, original_args) | ||
230 | + app = MesonApp(dir1, dir2, handshake, options, original_args) | ||
231 | except Exception as e: | ||
232 | # Log directory does not exist, so just print | ||
233 | # to stdout. | ||
234 | @@ -381,3 +393,11 @@ def run(original_args, mainfile=None): | ||
235 | mlog.shutdown() | ||
236 | |||
237 | return 0 | ||
238 | + | ||
239 | +def main(): | ||
240 | + # Always resolve the command path so Ninja can find it for regen, tests, etc. | ||
241 | + launcher = os.path.realpath(sys.argv[0]) | ||
242 | + return run(sys.argv[1:], launcher) | ||
243 | + | ||
244 | +if __name__ == '__main__': | ||
245 | + sys.exit(main()) | ||
246 | diff --git a/mesonbuild/scripts/regen_checker.py b/mesonbuild/scripts/regen_checker.py | ||
247 | index a9b00c7b..80d9242b 100644 | ||
248 | --- a/mesonbuild/scripts/regen_checker.py | ||
249 | +++ b/mesonbuild/scripts/regen_checker.py | ||
250 | @@ -14,7 +14,6 @@ | ||
251 | |||
252 | import sys, os | ||
253 | import pickle, subprocess | ||
254 | -from mesonbuild.mesonlib import meson_command | ||
255 | |||
256 | # This could also be used for XCode. | ||
257 | |||
258 | @@ -32,7 +31,7 @@ def need_regen(regeninfo, regen_timestamp): | ||
259 | Vs2010Backend.touch_regen_timestamp(regeninfo.build_dir) | ||
260 | return False | ||
261 | |||
262 | -def regen(regeninfo, mesonscript, backend): | ||
263 | +def regen(regeninfo, meson_command, backend): | ||
264 | cmd = meson_command + ['--internal', | ||
265 | 'regenerate', | ||
266 | regeninfo.build_dir, | ||
267 | @@ -48,11 +47,10 @@ def run(args): | ||
268 | regeninfo = pickle.load(f) | ||
269 | with open(coredata, 'rb') as f: | ||
270 | coredata = pickle.load(f) | ||
271 | - mesonscript = coredata.meson_script_launcher | ||
272 | backend = coredata.get_builtin_option('backend') | ||
273 | regen_timestamp = os.stat(dumpfile).st_mtime | ||
274 | if need_regen(regeninfo, regen_timestamp): | ||
275 | - regen(regeninfo, mesonscript, backend) | ||
276 | + regen(regeninfo, coredata.meson_command, backend) | ||
277 | sys.exit(0) | ||
278 | |||
279 | if __name__ == '__main__': | ||
280 | diff --git a/run_meson_command_tests.py b/run_meson_command_tests.py | ||
281 | new file mode 100755 | ||
282 | index 00000000..6efd911b | ||
283 | --- /dev/null | ||
284 | +++ b/run_meson_command_tests.py | ||
285 | @@ -0,0 +1,186 @@ | ||
286 | +#!/usr/bin/env python3 | ||
287 | + | ||
288 | +# Copyright 2018 The Meson development team | ||
289 | +# | ||
290 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
291 | +# you may not use this file except in compliance with the License. | ||
292 | +# You may obtain a copy of the License at | ||
293 | +# | ||
294 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
295 | +# | ||
296 | +# Unless required by applicable law or agreed to in writing, software | ||
297 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
298 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
299 | +# See the License for the specific language governing permissions and | ||
300 | +# limitations under the License. | ||
301 | + | ||
302 | +import os | ||
303 | +import tempfile | ||
304 | +import unittest | ||
305 | +import subprocess | ||
306 | +from pathlib import Path | ||
307 | + | ||
308 | +from mesonbuild.mesonlib import windows_proof_rmtree, python_command, is_windows | ||
309 | + | ||
310 | +# Find the meson.py adjacent to us | ||
311 | +meson_py = Path(__file__).resolve().parent / 'meson.py' | ||
312 | +if not meson_py.is_file(): | ||
313 | + raise RuntimeError("meson.py not found: test must only run from git") | ||
314 | + | ||
315 | +def get_pypath(): | ||
316 | + import sysconfig | ||
317 | + pypath = sysconfig.get_path('purelib', vars={'base': ''}) | ||
318 | + # Ensure that / is the path separator and not \, then strip / | ||
319 | + return Path(pypath).as_posix().strip('/') | ||
320 | + | ||
321 | +def get_pybindir(): | ||
322 | + import sysconfig | ||
323 | + # 'Scripts' on Windows and 'bin' on other platforms including MSYS | ||
324 | + return sysconfig.get_path('scripts', vars={'base': ''}).strip('\\/') | ||
325 | + | ||
326 | +class CommandTests(unittest.TestCase): | ||
327 | + ''' | ||
328 | + Test that running meson in various ways works as expected by checking the | ||
329 | + value of mesonlib.meson_command that was set during configuration. | ||
330 | + ''' | ||
331 | + | ||
332 | + def setUp(self): | ||
333 | + super().setUp() | ||
334 | + self.orig_env = os.environ.copy() | ||
335 | + self.orig_dir = os.getcwd() | ||
336 | + os.environ['MESON_COMMAND_TESTS'] = '1' | ||
337 | + self.tmpdir = Path(tempfile.mkdtemp()).resolve() | ||
338 | + self.src_root = Path(__file__).resolve().parent | ||
339 | + self.testdir = str(self.src_root / 'test cases/common/1 trivial') | ||
340 | + self.meson_args = ['--backend=ninja'] | ||
341 | + | ||
342 | + def tearDown(self): | ||
343 | + try: | ||
344 | + windows_proof_rmtree(str(self.tmpdir)) | ||
345 | + except FileNotFoundError: | ||
346 | + pass | ||
347 | + os.environ.clear() | ||
348 | + os.environ.update(self.orig_env) | ||
349 | + os.chdir(str(self.orig_dir)) | ||
350 | + super().tearDown() | ||
351 | + | ||
352 | + def _run(self, command, workdir=None): | ||
353 | + ''' | ||
354 | + Run a command while printing the stdout and stderr to stdout, | ||
355 | + and also return a copy of it | ||
356 | + ''' | ||
357 | + # If this call hangs CI will just abort. It is very hard to distinguish | ||
358 | + # between CI issue and test bug in that case. Set timeout and fail loud | ||
359 | + # instead. | ||
360 | + p = subprocess.run(command, stdout=subprocess.PIPE, | ||
361 | + stderr=subprocess.STDOUT, env=os.environ.copy(), | ||
362 | + universal_newlines=True, cwd=workdir, timeout=60 * 5) | ||
363 | + print(p.stdout) | ||
364 | + if p.returncode != 0: | ||
365 | + raise subprocess.CalledProcessError(p.returncode, command) | ||
366 | + return p.stdout | ||
367 | + | ||
368 | + def assertMesonCommandIs(self, line, cmd): | ||
369 | + self.assertTrue(line.startswith('meson_command '), msg=line) | ||
370 | + self.assertEqual(line, 'meson_command is {!r}'.format(cmd)) | ||
371 | + | ||
372 | + def test_meson_uninstalled(self): | ||
373 | + # This is what the meson command must be for all these cases | ||
374 | + resolved_meson_command = python_command + [str(self.src_root / 'meson.py')] | ||
375 | + # Absolute path to meson.py | ||
376 | + os.chdir('/') | ||
377 | + builddir = str(self.tmpdir / 'build1') | ||
378 | + meson_py = str(self.src_root / 'meson.py') | ||
379 | + meson_setup = [meson_py, 'setup'] | ||
380 | + meson_command = python_command + meson_setup + self.meson_args | ||
381 | + stdo = self._run(meson_command + [self.testdir, builddir]) | ||
382 | + self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) | ||
383 | + # ./meson.py | ||
384 | + os.chdir(str(self.src_root)) | ||
385 | + builddir = str(self.tmpdir / 'build2') | ||
386 | + meson_py = './meson.py' | ||
387 | + meson_setup = [meson_py, 'setup'] | ||
388 | + meson_command = python_command + meson_setup + self.meson_args | ||
389 | + stdo = self._run(meson_command + [self.testdir, builddir]) | ||
390 | + self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) | ||
391 | + # Symlink to meson.py | ||
392 | + if is_windows(): | ||
393 | + # Symlinks require admin perms | ||
394 | + return | ||
395 | + os.chdir(str(self.src_root)) | ||
396 | + builddir = str(self.tmpdir / 'build3') | ||
397 | + # Create a symlink to meson.py in bindir, and add it to PATH | ||
398 | + bindir = (self.tmpdir / 'bin') | ||
399 | + bindir.mkdir() | ||
400 | + (bindir / 'meson').symlink_to(self.src_root / 'meson.py') | ||
401 | + os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH'] | ||
402 | + # See if it works! | ||
403 | + meson_py = 'meson' | ||
404 | + meson_setup = [meson_py, 'setup'] | ||
405 | + meson_command = meson_setup + self.meson_args | ||
406 | + stdo = self._run(meson_command + [self.testdir, builddir]) | ||
407 | + self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) | ||
408 | + | ||
409 | + def test_meson_installed(self): | ||
410 | + # Install meson | ||
411 | + prefix = self.tmpdir / 'prefix' | ||
412 | + pylibdir = prefix / get_pypath() | ||
413 | + bindir = prefix / get_pybindir() | ||
414 | + pylibdir.mkdir(parents=True) | ||
415 | + os.environ['PYTHONPATH'] = str(pylibdir) | ||
416 | + os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH'] | ||
417 | + self._run(python_command + ['setup.py', 'install', '--prefix', str(prefix)]) | ||
418 | + self.assertTrue(pylibdir.is_dir()) | ||
419 | + self.assertTrue(bindir.is_dir()) | ||
420 | + # Run `meson` | ||
421 | + os.chdir('/') | ||
422 | + if is_windows(): | ||
423 | + resolved_meson_command = python_command + [str(bindir / 'meson.py')] | ||
424 | + else: | ||
425 | + resolved_meson_command = python_command + [str(bindir / 'meson')] | ||
426 | + # The python configuration on appveyor does not register .py as | ||
427 | + # a valid extension, so we cannot run `meson` on Windows. | ||
428 | + builddir = str(self.tmpdir / 'build1') | ||
429 | + meson_setup = ['meson', 'setup'] | ||
430 | + meson_command = meson_setup + self.meson_args | ||
431 | + stdo = self._run(meson_command + [self.testdir, builddir]) | ||
432 | + self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) | ||
433 | + # Run `/path/to/meson` | ||
434 | + builddir = str(self.tmpdir / 'build2') | ||
435 | + if is_windows(): | ||
436 | + # Cannot run .py directly because of the appveyor configuration, | ||
437 | + # and the script is named meson.py, not meson | ||
438 | + meson_setup = python_command + [str(bindir / 'meson.py'), 'setup'] | ||
439 | + else: | ||
440 | + meson_setup = [str(bindir / 'meson'), 'setup'] | ||
441 | + meson_command = meson_setup + self.meson_args | ||
442 | + stdo = self._run(meson_command + [self.testdir, builddir]) | ||
443 | + self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) | ||
444 | + # Run `python3 -m mesonbuild.mesonmain` | ||
445 | + resolved_meson_command = python_command + ['-m', 'mesonbuild.mesonmain'] | ||
446 | + builddir = str(self.tmpdir / 'build3') | ||
447 | + meson_setup = ['-m', 'mesonbuild.mesonmain', 'setup'] | ||
448 | + meson_command = python_command + meson_setup + self.meson_args | ||
449 | + stdo = self._run(meson_command + [self.testdir, builddir]) | ||
450 | + self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) | ||
451 | + if is_windows(): | ||
452 | + # Next part requires a shell | ||
453 | + return | ||
454 | + # `meson` is a wrapper to `meson.real` | ||
455 | + resolved_meson_command = python_command + [str(bindir / 'meson.real')] | ||
456 | + builddir = str(self.tmpdir / 'build4') | ||
457 | + (bindir / 'meson').rename(bindir / 'meson.real') | ||
458 | + wrapper = (bindir / 'meson') | ||
459 | + with open(wrapper, 'w') as f: | ||
460 | + f.write('#!/bin/sh\n\nmeson.real "$@"') | ||
461 | + wrapper.chmod(0o755) | ||
462 | + meson_setup = [str(wrapper), 'setup'] | ||
463 | + meson_command = meson_setup + self.meson_args | ||
464 | + stdo = self._run(meson_command + [self.testdir, builddir]) | ||
465 | + self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) | ||
466 | + | ||
467 | + def test_meson_exe_windows(self): | ||
468 | + raise unittest.SkipTest('NOT IMPLEMENTED') | ||
469 | + | ||
470 | +if __name__ == '__main__': | ||
471 | + unittest.main(buffer=True) | ||
472 | diff --git a/run_project_tests.py b/run_project_tests.py | ||
473 | index 3c516240..3d22b152 100755 | ||
474 | --- a/run_project_tests.py | ||
475 | +++ b/run_project_tests.py | ||
476 | @@ -38,8 +38,7 @@ import time | ||
477 | import multiprocessing | ||
478 | from concurrent.futures import ProcessPoolExecutor | ||
479 | import re | ||
480 | -from run_unittests import get_fake_options, run_configure | ||
481 | - | ||
482 | +from run_tests import get_fake_options, run_configure, get_meson_script | ||
483 | from run_tests import get_backend_commands, get_backend_args_for_dir, Backend | ||
484 | from run_tests import ensure_backend_detects_changes | ||
485 | |||
486 | @@ -88,12 +87,6 @@ no_meson_log_msg = 'No meson-log.txt found.' | ||
487 | |||
488 | system_compiler = None | ||
489 | |||
490 | -meson_command = os.path.join(os.getcwd(), 'meson') | ||
491 | -if not os.path.exists(meson_command): | ||
492 | - meson_command += '.py' | ||
493 | - if not os.path.exists(meson_command): | ||
494 | - raise RuntimeError('Could not find main Meson script to run.') | ||
495 | - | ||
496 | class StopException(Exception): | ||
497 | def __init__(self): | ||
498 | super().__init__('Stopped by user') | ||
499 | @@ -324,7 +317,7 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen | ||
500 | if pass_libdir_to_test(testdir): | ||
501 | gen_args += ['--libdir', 'lib'] | ||
502 | gen_args += [testdir, test_build_dir] + flags + test_args + extra_args | ||
503 | - (returncode, stdo, stde) = run_configure(meson_command, gen_args) | ||
504 | + (returncode, stdo, stde) = run_configure(gen_args) | ||
505 | try: | ||
506 | logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt') | ||
507 | mesonlog = logfile.open(errors='ignore', encoding='utf-8').read() | ||
508 | @@ -417,7 +410,7 @@ def have_d_compiler(): | ||
509 | |||
510 | def have_objc_compiler(): | ||
511 | with AutoDeletedDir(tempfile.mkdtemp(prefix='b ', dir='.')) as build_dir: | ||
512 | - env = environment.Environment(None, build_dir, None, get_fake_options('/'), []) | ||
513 | + env = environment.Environment(None, build_dir, get_fake_options('/'), []) | ||
514 | try: | ||
515 | objc_comp = env.detect_objc_compiler(False) | ||
516 | except mesonlib.MesonException: | ||
517 | @@ -432,7 +425,7 @@ def have_objc_compiler(): | ||
518 | |||
519 | def have_objcpp_compiler(): | ||
520 | with AutoDeletedDir(tempfile.mkdtemp(prefix='b ', dir='.')) as build_dir: | ||
521 | - env = environment.Environment(None, build_dir, None, get_fake_options('/'), []) | ||
522 | + env = environment.Environment(None, build_dir, get_fake_options('/'), []) | ||
523 | try: | ||
524 | objcpp_comp = env.detect_objcpp_compiler(False) | ||
525 | except mesonlib.MesonException: | ||
526 | @@ -647,11 +640,12 @@ def check_format(): | ||
527 | check_file(fullname) | ||
528 | |||
529 | def check_meson_commands_work(): | ||
530 | - global backend, meson_command, compile_commands, test_commands, install_commands | ||
531 | + global backend, compile_commands, test_commands, install_commands | ||
532 | testdir = PurePath('test cases', 'common', '1 trivial').as_posix() | ||
533 | + meson_commands = mesonlib.python_command + [get_meson_script()] | ||
534 | with AutoDeletedDir(tempfile.mkdtemp(prefix='b ', dir='.')) as build_dir: | ||
535 | print('Checking that configuring works...') | ||
536 | - gen_cmd = mesonlib.meson_command + [testdir, build_dir] + backend_flags | ||
537 | + gen_cmd = meson_commands + [testdir, build_dir] + backend_flags | ||
538 | pc, o, e = Popen_safe(gen_cmd) | ||
539 | if pc.returncode != 0: | ||
540 | raise RuntimeError('Failed to configure {!r}:\n{}\n{}'.format(testdir, e, o)) | ||
541 | diff --git a/run_tests.py b/run_tests.py | ||
542 | index 648e6ce1..736cdc07 100755 | ||
543 | --- a/run_tests.py | ||
544 | +++ b/run_tests.py | ||
545 | @@ -21,13 +21,16 @@ import shutil | ||
546 | import subprocess | ||
547 | import tempfile | ||
548 | import platform | ||
549 | +from io import StringIO | ||
550 | +from enum import Enum | ||
551 | +from glob import glob | ||
552 | +from pathlib import Path | ||
553 | + | ||
554 | +import mesonbuild | ||
555 | from mesonbuild import mesonlib | ||
556 | from mesonbuild import mesonmain | ||
557 | from mesonbuild import mlog | ||
558 | from mesonbuild.environment import detect_ninja | ||
559 | -from io import StringIO | ||
560 | -from enum import Enum | ||
561 | -from glob import glob | ||
562 | |||
563 | Backend = Enum('Backend', 'ninja vs xcode') | ||
564 | |||
565 | @@ -42,6 +45,28 @@ if mesonlib.is_windows() or mesonlib.is_cygwin(): | ||
566 | else: | ||
567 | exe_suffix = '' | ||
568 | |||
569 | +def get_meson_script(): | ||
570 | + ''' | ||
571 | + Guess the meson that corresponds to the `mesonbuild` that has been imported | ||
572 | + so we can run configure and other commands in-process, since mesonmain.run | ||
573 | + needs to know the meson_command to use. | ||
574 | + | ||
575 | + Also used by run_unittests.py to determine what meson to run when not | ||
576 | + running in-process (which is the default). | ||
577 | + ''' | ||
578 | + # Is there a meson.py next to the mesonbuild currently in use? | ||
579 | + mesonbuild_dir = Path(mesonbuild.__file__).resolve().parent.parent | ||
580 | + meson_script = mesonbuild_dir / 'meson.py' | ||
581 | + if meson_script.is_file(): | ||
582 | + return str(meson_script) | ||
583 | + # Then if mesonbuild is in PYTHONPATH, meson must be in PATH | ||
584 | + mlog.warning('Could not find meson.py next to the mesonbuild module. ' | ||
585 | + 'Trying system meson...') | ||
586 | + meson_cmd = shutil.which('meson') | ||
587 | + if meson_cmd: | ||
588 | + return meson_cmd | ||
589 | + raise RuntimeError('Could not find {!r} or a meson in PATH'.format(meson_script)) | ||
590 | + | ||
591 | def get_backend_args_for_dir(backend, builddir): | ||
592 | ''' | ||
593 | Visual Studio backend needs to be given the solution to build | ||
594 | @@ -133,13 +158,13 @@ def get_fake_options(prefix): | ||
595 | def should_run_linux_cross_tests(): | ||
596 | return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm') | ||
597 | |||
598 | -def run_configure_inprocess(meson_command, commandlist): | ||
599 | +def run_configure_inprocess(commandlist): | ||
600 | old_stdout = sys.stdout | ||
601 | sys.stdout = mystdout = StringIO() | ||
602 | old_stderr = sys.stderr | ||
603 | sys.stderr = mystderr = StringIO() | ||
604 | try: | ||
605 | - returncode = mesonmain.run(commandlist, meson_command) | ||
606 | + returncode = mesonmain.run(commandlist, get_meson_script()) | ||
607 | finally: | ||
608 | sys.stdout = old_stdout | ||
609 | sys.stderr = old_stderr | ||
610 | @@ -149,11 +174,11 @@ def run_configure_external(full_command): | ||
611 | pc, o, e = mesonlib.Popen_safe(full_command) | ||
612 | return pc.returncode, o, e | ||
613 | |||
614 | -def run_configure(meson_command, commandlist): | ||
615 | +def run_configure(commandlist): | ||
616 | global meson_exe | ||
617 | if meson_exe: | ||
618 | return run_configure_external(meson_exe + commandlist) | ||
619 | - return run_configure_inprocess(meson_command, commandlist) | ||
620 | + return run_configure_inprocess(commandlist) | ||
621 | |||
622 | def print_system_info(): | ||
623 | print(mlog.bold('System information.').get_text(mlog.colorize_console)) | ||
624 | @@ -214,6 +239,9 @@ if __name__ == '__main__': | ||
625 | 'coverage.process_startup()\n') | ||
626 | env['COVERAGE_PROCESS_START'] = '.coveragerc' | ||
627 | env['PYTHONPATH'] = os.pathsep.join([td] + env.get('PYTHONPATH', [])) | ||
628 | + # Meson command tests | ||
629 | + returncode += subprocess.call(mesonlib.python_command + ['run_meson_command_tests.py', '-v'], env=env) | ||
630 | + # Unit tests | ||
631 | returncode += subprocess.call(mesonlib.python_command + ['run_unittests.py', '-v'], env=env) | ||
632 | # Ubuntu packages do not have a binary without -6 suffix. | ||
633 | if should_run_linux_cross_tests(): | ||
634 | @@ -221,5 +249,6 @@ if __name__ == '__main__': | ||
635 | print() | ||
636 | returncode += subprocess.call(mesonlib.python_command + ['run_cross_test.py', 'cross/ubuntu-armhf.txt'], | ||
637 | env=env) | ||
638 | + # Project tests | ||
639 | returncode += subprocess.call(mesonlib.python_command + ['run_project_tests.py'] + sys.argv[1:], env=env) | ||
640 | sys.exit(returncode) | ||
641 | diff --git a/run_unittests.py b/run_unittests.py | ||
642 | index 6d4e0339..3c215db4 100755 | ||
643 | --- a/run_unittests.py | ||
644 | +++ b/run_unittests.py | ||
645 | @@ -36,7 +36,7 @@ import mesonbuild.modules.gnome | ||
646 | from mesonbuild.interpreter import ObjectHolder | ||
647 | from mesonbuild.mesonlib import ( | ||
648 | is_windows, is_osx, is_cygwin, is_dragonflybsd, | ||
649 | - windows_proof_rmtree, python_command, meson_command, version_compare, | ||
650 | + windows_proof_rmtree, python_command, version_compare, | ||
651 | BuildDirLock | ||
652 | ) | ||
653 | from mesonbuild.environment import Environment, detect_ninja | ||
654 | @@ -44,9 +44,9 @@ from mesonbuild.mesonlib import MesonException, EnvironmentException | ||
655 | from mesonbuild.dependencies import PkgConfigDependency, ExternalProgram | ||
656 | import mesonbuild.modules.pkgconfig | ||
657 | |||
658 | -from run_tests import exe_suffix, get_fake_options | ||
659 | +from run_tests import exe_suffix, get_fake_options, get_meson_script | ||
660 | from run_tests import get_builddir_target_args, get_backend_commands, Backend | ||
661 | -from run_tests import ensure_backend_detects_changes, run_configure, meson_exe | ||
662 | +from run_tests import ensure_backend_detects_changes, run_configure_inprocess | ||
663 | from run_tests import should_run_linux_cross_tests | ||
664 | |||
665 | |||
666 | @@ -488,13 +488,13 @@ class BasePlatformTests(unittest.TestCase): | ||
667 | # Get the backend | ||
668 | # FIXME: Extract this from argv? | ||
669 | self.backend = getattr(Backend, os.environ.get('MESON_UNIT_TEST_BACKEND', 'ninja')) | ||
670 | - self.meson_mainfile = os.path.join(src_root, 'meson.py') | ||
671 | self.meson_args = ['--backend=' + self.backend.name] | ||
672 | self.meson_cross_file = None | ||
673 | - self.meson_command = meson_command + self.meson_args | ||
674 | - self.mconf_command = meson_command + ['configure'] | ||
675 | - self.mintro_command = meson_command + ['introspect'] | ||
676 | - self.wrap_command = meson_command + ['wrap'] | ||
677 | + self.meson_command = python_command + [get_meson_script()] | ||
678 | + self.setup_command = self.meson_command + self.meson_args | ||
679 | + self.mconf_command = self.meson_command + ['configure'] | ||
680 | + self.mintro_command = self.meson_command + ['introspect'] | ||
681 | + self.wrap_command = self.meson_command + ['wrap'] | ||
682 | # Backend-specific build commands | ||
683 | self.build_command, self.clean_command, self.test_command, self.install_command, \ | ||
684 | self.uninstall_command = get_backend_commands(self.backend) | ||
685 | @@ -521,7 +521,7 @@ class BasePlatformTests(unittest.TestCase): | ||
686 | self.logdir = os.path.join(self.builddir, 'meson-logs') | ||
687 | self.installdir = os.path.join(self.builddir, 'install') | ||
688 | self.distdir = os.path.join(self.builddir, 'meson-dist') | ||
689 | - self.mtest_command = meson_command + ['test', '-C', self.builddir] | ||
690 | + self.mtest_command = self.meson_command + ['test', '-C', self.builddir] | ||
691 | self.builddirs.append(self.builddir) | ||
692 | |||
693 | def new_builddir(self): | ||
694 | @@ -581,7 +581,7 @@ class BasePlatformTests(unittest.TestCase): | ||
695 | self.privatedir = os.path.join(self.builddir, 'meson-private') | ||
696 | if inprocess: | ||
697 | try: | ||
698 | - (returncode, out, err) = run_configure(self.meson_mainfile, self.meson_args + args + extra_args) | ||
699 | + (returncode, out, err) = run_configure_inprocess(self.meson_args + args + extra_args) | ||
700 | if 'MESON_SKIP_TEST' in out: | ||
701 | raise unittest.SkipTest('Project requested skipping.') | ||
702 | if returncode != 0: | ||
703 | @@ -601,7 +601,7 @@ class BasePlatformTests(unittest.TestCase): | ||
704 | mesonbuild.mlog.log_file = None | ||
705 | else: | ||
706 | try: | ||
707 | - out = self._run(self.meson_command + args + extra_args) | ||
708 | + out = self._run(self.setup_command + args + extra_args) | ||
709 | except unittest.SkipTest: | ||
710 | raise unittest.SkipTest('Project requested skipping: ' + srcdir) | ||
711 | except: | ||
712 | @@ -900,8 +900,7 @@ class AllPlatformTests(BasePlatformTests): | ||
713 | https://github.com/mesonbuild/meson/issues/1355 | ||
714 | ''' | ||
715 | testdir = os.path.join(self.common_test_dir, '3 static') | ||
716 | - env = Environment(testdir, self.builddir, self.meson_command, | ||
717 | - get_fake_options(self.prefix), []) | ||
718 | + env = Environment(testdir, self.builddir, get_fake_options(self.prefix), []) | ||
719 | cc = env.detect_c_compiler(False) | ||
720 | static_linker = env.detect_static_linker(cc) | ||
721 | if is_windows(): | ||
722 | @@ -1182,8 +1181,7 @@ class AllPlatformTests(BasePlatformTests): | ||
723 | if not is_windows(): | ||
724 | langs += [('objc', 'OBJC'), ('objcpp', 'OBJCXX')] | ||
725 | testdir = os.path.join(self.unit_test_dir, '5 compiler detection') | ||
726 | - env = Environment(testdir, self.builddir, self.meson_command, | ||
727 | - get_fake_options(self.prefix), []) | ||
728 | + env = Environment(testdir, self.builddir, get_fake_options(self.prefix), []) | ||
729 | for lang, evar in langs: | ||
730 | # Detect with evar and do sanity checks on that | ||
731 | if evar in os.environ: | ||
732 | @@ -1285,8 +1283,7 @@ class AllPlatformTests(BasePlatformTests): | ||
733 | def test_always_prefer_c_compiler_for_asm(self): | ||
734 | testdir = os.path.join(self.common_test_dir, '141 c cpp and asm') | ||
735 | # Skip if building with MSVC | ||
736 | - env = Environment(testdir, self.builddir, self.meson_command, | ||
737 | - get_fake_options(self.prefix), []) | ||
738 | + env = Environment(testdir, self.builddir, get_fake_options(self.prefix), []) | ||
739 | if env.detect_c_compiler(False).get_id() == 'msvc': | ||
740 | raise unittest.SkipTest('MSVC can\'t compile assembly') | ||
741 | self.init(testdir) | ||
742 | @@ -1544,8 +1541,7 @@ int main(int argc, char **argv) { | ||
743 | self.assertPathExists(os.path.join(testdir, i)) | ||
744 | |||
745 | def detect_prebuild_env(self): | ||
746 | - env = Environment('', self.builddir, self.meson_command, | ||
747 | - get_fake_options(self.prefix), []) | ||
748 | + env = Environment('', self.builddir, get_fake_options(self.prefix), []) | ||
749 | cc = env.detect_c_compiler(False) | ||
750 | stlinker = env.detect_static_linker(cc) | ||
751 | if mesonbuild.mesonlib.is_windows(): | ||
752 | @@ -1713,8 +1709,7 @@ int main(int argc, char **argv) { | ||
753 | '--libdir=' + libdir]) | ||
754 | # Find foo dependency | ||
755 | os.environ['PKG_CONFIG_LIBDIR'] = self.privatedir | ||
756 | - env = Environment(testdir, self.builddir, self.meson_command, | ||
757 | - get_fake_options(self.prefix), []) | ||
758 | + env = Environment(testdir, self.builddir, get_fake_options(self.prefix), []) | ||
759 | kwargs = {'required': True, 'silent': True} | ||
760 | foo_dep = PkgConfigDependency('libfoo', env, kwargs) | ||
761 | # Ensure link_args are properly quoted | ||
762 | @@ -1847,16 +1842,16 @@ int main(int argc, char **argv) { | ||
763 | for lang in ('c', 'cpp'): | ||
764 | for type in ('executable', 'library'): | ||
765 | with tempfile.TemporaryDirectory() as tmpdir: | ||
766 | - self._run(meson_command + ['init', '--language', lang, '--type', type], | ||
767 | + self._run(self.meson_command + ['init', '--language', lang, '--type', type], | ||
768 | workdir=tmpdir) | ||
769 | - self._run(self.meson_command + ['--backend=ninja', 'builddir'], | ||
770 | + self._run(self.setup_command + ['--backend=ninja', 'builddir'], | ||
771 | workdir=tmpdir) | ||
772 | self._run(ninja, | ||
773 | workdir=os.path.join(tmpdir, 'builddir')) | ||
774 | with tempfile.TemporaryDirectory() as tmpdir: | ||
775 | with open(os.path.join(tmpdir, 'foo.' + lang), 'w') as f: | ||
776 | f.write('int main() {}') | ||
777 | - self._run(meson_command + ['init', '-b'], workdir=tmpdir) | ||
778 | + self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) | ||
779 | |||
780 | # The test uses mocking and thus requires that | ||
781 | # the current process is the one to run the Meson steps. | ||
782 | @@ -1981,8 +1976,7 @@ recommended as it can lead to undefined behaviour on some platforms''') | ||
783 | testdirbase = os.path.join(self.unit_test_dir, '26 guessed linker dependencies') | ||
784 | testdirlib = os.path.join(testdirbase, 'lib') | ||
785 | extra_args = None | ||
786 | - env = Environment(testdirlib, self.builddir, self.meson_command, | ||
787 | - get_fake_options(self.prefix), []) | ||
788 | + env = Environment(testdirlib, self.builddir, get_fake_options(self.prefix), []) | ||
789 | if env.detect_c_compiler(False).get_id() != 'msvc': | ||
790 | # static libraries are not linkable with -l with msvc because meson installs them | ||
791 | # as .a files which unix_args_to_native will not know as it expects libraries to use | ||
792 | @@ -2095,9 +2089,6 @@ class FailureTests(BasePlatformTests): | ||
793 | Assert that running meson configure on the specified @contents raises | ||
794 | a error message matching regex @match. | ||
795 | ''' | ||
796 | - if meson_exe is not None: | ||
797 | - # Because the exception happens in a different process. | ||
798 | - raise unittest.SkipTest('Can not test assert raise tests with an external Meson command.') | ||
799 | if langs is None: | ||
800 | langs = [] | ||
801 | with open(self.mbuild, 'w') as f: | ||
802 | @@ -2232,8 +2223,7 @@ class FailureTests(BasePlatformTests): | ||
803 | ''' | ||
804 | Test that when we can't detect objc or objcpp, we fail gracefully. | ||
805 | ''' | ||
806 | - env = Environment('', self.builddir, self.meson_command, | ||
807 | - get_fake_options(self.prefix), []) | ||
808 | + env = Environment('', self.builddir, get_fake_options(self.prefix), []) | ||
809 | try: | ||
810 | env.detect_objc_compiler(False) | ||
811 | env.detect_objcpp_compiler(False) | ||
812 | @@ -2328,8 +2318,7 @@ class WindowsTests(BasePlatformTests): | ||
813 | ExternalLibraryHolder from build files. | ||
814 | ''' | ||
815 | testdir = os.path.join(self.platform_test_dir, '1 basic') | ||
816 | - env = Environment(testdir, self.builddir, self.meson_command, | ||
817 | - get_fake_options(self.prefix), []) | ||
818 | + env = Environment(testdir, self.builddir, get_fake_options(self.prefix), []) | ||
819 | cc = env.detect_c_compiler(False) | ||
820 | if cc.id != 'msvc': | ||
821 | raise unittest.SkipTest('Not using MSVC') | ||
822 | @@ -2399,8 +2388,7 @@ class LinuxlikeTests(BasePlatformTests): | ||
823 | ''' | ||
824 | testdir = os.path.join(self.common_test_dir, '51 pkgconfig-gen') | ||
825 | self.init(testdir) | ||
826 | - env = Environment(testdir, self.builddir, self.meson_command, | ||
827 | - get_fake_options(self.prefix), []) | ||
828 | + env = Environment(testdir, self.builddir, get_fake_options(self.prefix), []) | ||
829 | kwargs = {'required': True, 'silent': True} | ||
830 | os.environ['PKG_CONFIG_LIBDIR'] = self.privatedir | ||
831 | foo_dep = PkgConfigDependency('libfoo', env, kwargs) | ||
832 | @@ -2650,8 +2638,7 @@ class LinuxlikeTests(BasePlatformTests): | ||
833 | an ordinary test because it requires passing options to meson. | ||
834 | ''' | ||
835 | testdir = os.path.join(self.common_test_dir, '1 trivial') | ||
836 | - env = Environment(testdir, self.builddir, self.meson_command, | ||
837 | - get_fake_options(self.prefix), []) | ||
838 | + env = Environment(testdir, self.builddir, get_fake_options(self.prefix), []) | ||
839 | cc = env.detect_c_compiler(False) | ||
840 | self._test_stds_impl(testdir, cc, 'c') | ||
841 | |||
842 | @@ -2661,8 +2648,7 @@ class LinuxlikeTests(BasePlatformTests): | ||
843 | be an ordinary test because it requires passing options to meson. | ||
844 | ''' | ||
845 | testdir = os.path.join(self.common_test_dir, '2 cpp') | ||
846 | - env = Environment(testdir, self.builddir, self.meson_command, | ||
847 | - get_fake_options(self.prefix), []) | ||
848 | + env = Environment(testdir, self.builddir, get_fake_options(self.prefix), []) | ||
849 | cpp = env.detect_cpp_compiler(False) | ||
850 | self._test_stds_impl(testdir, cpp, 'cpp') | ||
851 | |||
diff --git a/meta/recipes-devtools/meson/meson_0.46.1.bb b/meta/recipes-devtools/meson/meson_0.46.1.bb index a18cab81f4..77f6416cc2 100644 --- a/meta/recipes-devtools/meson/meson_0.46.1.bb +++ b/meta/recipes-devtools/meson/meson_0.46.1.bb | |||
@@ -9,6 +9,8 @@ SRC_URI = "https://github.com/mesonbuild/meson/releases/download/${PV}/${BP}.tar | |||
9 | file://0002-gobject-introspection-determine-g-ir-scanner-and-g-i.patch \ | 9 | file://0002-gobject-introspection-determine-g-ir-scanner-and-g-i.patch \ |
10 | file://0001-Linker-rules-move-cross_args-in-front-of-output_args.patch \ | 10 | file://0001-Linker-rules-move-cross_args-in-front-of-output_args.patch \ |
11 | file://0003-native_bindir.patch \ | 11 | file://0003-native_bindir.patch \ |
12 | file://0004-Prettifying-some-output-with-pathlib.patch \ | ||
13 | file://0005-Set-the-meson-command-to-use-when-we-know-what-it-is.patch \ | ||
12 | " | 14 | " |
13 | SRC_URI[md5sum] = "1698f6526574839de5dcdc45e3f7d582" | 15 | SRC_URI[md5sum] = "1698f6526574839de5dcdc45e3f7d582" |
14 | SRC_URI[sha256sum] = "19497a03e7e5b303d8d11f98789a79aba59b5ad4a81bd00f4d099be0212cee78" | 16 | SRC_URI[sha256sum] = "19497a03e7e5b303d8d11f98789a79aba59b5ad4a81bd00f4d099be0212cee78" |