|
| 1 | +From d83327354463953adabbca4c68d316142f82f9c7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Christoph Reiter <reiter.christoph@gmail.com> |
| 3 | +Date: Fri, 12 Jul 2024 07:17:12 +0200 |
| 4 | +Subject: [PATCH 2/2] Make sure machine_info_can_run() isn't called on |
| 5 | + incomplete MachineInfo |
| 6 | + |
| 7 | +If need_exe_wrapper() is called while figuring out the language compiler, |
| 8 | +the MachineInfo isn't complete yet, so machine_info_can_run() would return |
| 9 | +False despite not cross compiling. |
| 10 | + |
| 11 | +Make sure this fails loudly. |
| 12 | +--- |
| 13 | + mesonbuild/backend/backends.py | 3 ++- |
| 14 | + mesonbuild/compilers/cuda.py | 4 ++-- |
| 15 | + mesonbuild/compilers/d.py | 4 ++-- |
| 16 | + mesonbuild/compilers/mixins/clike.py | 4 ++-- |
| 17 | + mesonbuild/compilers/rust.py | 2 +- |
| 18 | + mesonbuild/environment.py | 1 + |
| 19 | + 6 files changed, 10 insertions(+), 8 deletions(-) |
| 20 | + |
| 21 | +diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py |
| 22 | +index 740f349e4..bea8c7e85 100644 |
| 23 | +--- a/mesonbuild/backend/backends.py |
| 24 | ++++ b/mesonbuild/backend/backends.py |
| 25 | +@@ -568,7 +568,8 @@ class Backend: |
| 26 | + else: |
| 27 | + extra_paths = [] |
| 28 | + |
| 29 | +- if self.environment.need_exe_wrapper(exe_for_machine): |
| 30 | ++ is_cross_built = not self.environment.machines.matches_build_machine(exe_for_machine) |
| 31 | ++ if is_cross_built and self.environment.need_exe_wrapper(): |
| 32 | + if not self.environment.has_exe_wrapper(): |
| 33 | + msg = 'An exe_wrapper is needed but was not found. Please define one ' \ |
| 34 | + 'in cross file and check the command and/or add it to PATH.' |
| 35 | +diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py |
| 36 | +index 3761019b9..eaea5c846 100644 |
| 37 | +--- a/mesonbuild/compilers/cuda.py |
| 38 | ++++ b/mesonbuild/compilers/cuda.py |
| 39 | +@@ -551,7 +551,7 @@ class CudaCompiler(Compiler): |
| 40 | + flags += self.get_ccbin_args(env.coredata.options) |
| 41 | + |
| 42 | + # If cross-compiling, we can't run the sanity check, only compile it. |
| 43 | +- if env.need_exe_wrapper(self.for_machine) and not env.has_exe_wrapper(): |
| 44 | ++ if self.is_cross and not env.has_exe_wrapper(): |
| 45 | + # Linking cross built apps is painful. You can't really |
| 46 | + # tell if you should use -nostdlib or not and for example |
| 47 | + # on OSX the compiler binary is the same but you need |
| 48 | +@@ -573,7 +573,7 @@ class CudaCompiler(Compiler): |
| 49 | + raise EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.') |
| 50 | + |
| 51 | + # Run sanity check (if possible) |
| 52 | +- if env.need_exe_wrapper(self.for_machine): |
| 53 | ++ if self.is_cross: |
| 54 | + if not env.has_exe_wrapper(): |
| 55 | + return |
| 56 | + else: |
| 57 | +diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py |
| 58 | +index 46cffdd0f..c478c040b 100644 |
| 59 | +--- a/mesonbuild/compilers/d.py |
| 60 | ++++ b/mesonbuild/compilers/d.py |
| 61 | +@@ -447,7 +447,7 @@ class DCompiler(Compiler): |
| 62 | + compile_cmdlist = self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name] |
| 63 | + |
| 64 | + # If cross-compiling, we can't run the sanity check, only compile it. |
| 65 | +- if environment.need_exe_wrapper(self.for_machine) and not environment.has_exe_wrapper(): |
| 66 | ++ if self.is_cross and not environment.has_exe_wrapper(): |
| 67 | + compile_cmdlist += self.get_compile_only_args() |
| 68 | + |
| 69 | + pc = subprocess.Popen(compile_cmdlist, cwd=work_dir) |
| 70 | +@@ -455,7 +455,7 @@ class DCompiler(Compiler): |
| 71 | + if pc.returncode != 0: |
| 72 | + raise EnvironmentException('D compiler %s cannot compile programs.' % self.name_string()) |
| 73 | + |
| 74 | +- if environment.need_exe_wrapper(self.for_machine): |
| 75 | ++ if self.is_cross: |
| 76 | + if not environment.has_exe_wrapper(): |
| 77 | + # Can't check if the binaries run so we have to assume they do |
| 78 | + return |
| 79 | +diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py |
| 80 | +index d273015bc..434ec9fe7 100644 |
| 81 | +--- a/mesonbuild/compilers/mixins/clike.py |
| 82 | ++++ b/mesonbuild/compilers/mixins/clike.py |
| 83 | +@@ -278,7 +278,7 @@ class CLikeCompiler(Compiler): |
| 84 | + mode = CompileCheckMode.LINK |
| 85 | + if self.is_cross: |
| 86 | + binname += '_cross' |
| 87 | +- if environment.need_exe_wrapper(self.for_machine) and not environment.has_exe_wrapper(): |
| 88 | ++ if not environment.has_exe_wrapper(): |
| 89 | + # Linking cross built C/C++ apps is painful. You can't really |
| 90 | + # tell if you should use -nostdlib or not and for example |
| 91 | + # on OSX the compiler binary is the same but you need |
| 92 | +@@ -308,7 +308,7 @@ class CLikeCompiler(Compiler): |
| 93 | + if pc.returncode != 0: |
| 94 | + raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.') |
| 95 | + # Run sanity check |
| 96 | +- if environment.need_exe_wrapper(self.for_machine): |
| 97 | ++ if self.is_cross: |
| 98 | + if not environment.has_exe_wrapper(): |
| 99 | + # Can't check if the binaries run so we have to assume they do |
| 100 | + return |
| 101 | +diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py |
| 102 | +index ce1079190..f89d83fd9 100644 |
| 103 | +--- a/mesonbuild/compilers/rust.py |
| 104 | ++++ b/mesonbuild/compilers/rust.py |
| 105 | +@@ -86,7 +86,7 @@ class RustCompiler(Compiler): |
| 106 | + if pc.returncode != 0: |
| 107 | + raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.') |
| 108 | + self._native_static_libs(work_dir, source_name) |
| 109 | +- if environment.need_exe_wrapper(self.for_machine): |
| 110 | ++ if self.is_cross: |
| 111 | + if not environment.has_exe_wrapper(): |
| 112 | + # Can't check if the binaries run so we have to assume they do |
| 113 | + return |
| 114 | +diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py |
| 115 | +index 19b9e81b5..a86f47b7e 100644 |
| 116 | +--- a/mesonbuild/environment.py |
| 117 | ++++ b/mesonbuild/environment.py |
| 118 | +@@ -505,6 +505,7 @@ def machine_info_can_run(machine_info: MachineInfo): |
| 119 | + if machine_info.system != detect_system(): |
| 120 | + return False |
| 121 | + true_build_cpu_family = detect_cpu_family({}) |
| 122 | ++ assert machine_info.cpu_family is not None, 'called on incomplete machine_info' |
| 123 | + return \ |
| 124 | + (machine_info.cpu_family == true_build_cpu_family) or \ |
| 125 | + ((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86')) or \ |
0 commit comments