Skip to content

Commit b92996d

Browse files
lazkah-vetinari
authored andcommitted
Make sure machine_info_can_run() isn't called on incomplete MachineInfo
If need_exe_wrapper() is called while figuring out the language compiler, the MachineInfo isn't complete yet, so machine_info_can_run() would return False despite not cross compiling. Make sure this fails loudly. Squash of the following cherry-picked commits: - mesonbuild@df833b0 - mesonbuild@c108d5b - mesonbuild@eba9e7e
1 parent 8c0de5a commit b92996d

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

mesonbuild/backend/backends.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ def get_executable_serialisation(
568568
else:
569569
extra_paths = []
570570

571-
if self.environment.need_exe_wrapper(exe_for_machine):
571+
is_cross_built = not self.environment.machines.matches_build_machine(exe_for_machine)
572+
if is_cross_built and self.environment.need_exe_wrapper():
572573
if not self.environment.has_exe_wrapper():
573574
msg = 'An exe_wrapper is needed but was not found. Please define one ' \
574575
'in cross file and check the command and/or add it to PATH.'

mesonbuild/compilers/cuda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def sanity_check(self, work_dir: str, env: 'Environment') -> None:
551551
flags += self.get_ccbin_args(env.coredata.options)
552552

553553
# If cross-compiling, we can't run the sanity check, only compile it.
554-
if env.need_exe_wrapper(self.for_machine) and not env.has_exe_wrapper():
554+
if self.is_cross and not env.has_exe_wrapper():
555555
# Linking cross built apps is painful. You can't really
556556
# tell if you should use -nostdlib or not and for example
557557
# on OSX the compiler binary is the same but you need
@@ -573,7 +573,7 @@ def sanity_check(self, work_dir: str, env: 'Environment') -> None:
573573
raise EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
574574

575575
# Run sanity check (if possible)
576-
if env.need_exe_wrapper(self.for_machine):
576+
if self.is_cross:
577577
if not env.has_exe_wrapper():
578578
return
579579
else:

mesonbuild/compilers/d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,15 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
447447
compile_cmdlist = self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name]
448448

449449
# If cross-compiling, we can't run the sanity check, only compile it.
450-
if environment.need_exe_wrapper(self.for_machine) and not environment.has_exe_wrapper():
450+
if self.is_cross and not environment.has_exe_wrapper():
451451
compile_cmdlist += self.get_compile_only_args()
452452

453453
pc = subprocess.Popen(compile_cmdlist, cwd=work_dir)
454454
pc.wait()
455455
if pc.returncode != 0:
456456
raise EnvironmentException('D compiler %s cannot compile programs.' % self.name_string())
457457

458-
if environment.need_exe_wrapper(self.for_machine):
458+
if self.is_cross:
459459
if not environment.has_exe_wrapper():
460460
# Can't check if the binaries run so we have to assume they do
461461
return

mesonbuild/compilers/mixins/clike.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def _sanity_check_impl(self, work_dir: str, environment: 'Environment',
278278
mode = CompileCheckMode.LINK
279279
if self.is_cross:
280280
binname += '_cross'
281-
if environment.need_exe_wrapper(self.for_machine) and not environment.has_exe_wrapper():
281+
if not environment.has_exe_wrapper():
282282
# Linking cross built C/C++ apps is painful. You can't really
283283
# tell if you should use -nostdlib or not and for example
284284
# on OSX the compiler binary is the same but you need
@@ -308,7 +308,7 @@ def _sanity_check_impl(self, work_dir: str, environment: 'Environment',
308308
if pc.returncode != 0:
309309
raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
310310
# Run sanity check
311-
if environment.need_exe_wrapper(self.for_machine):
311+
if self.is_cross:
312312
if not environment.has_exe_wrapper():
313313
# Can't check if the binaries run so we have to assume they do
314314
return

mesonbuild/compilers/rust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
8686
if pc.returncode != 0:
8787
raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.')
8888
self._native_static_libs(work_dir, source_name)
89-
if environment.need_exe_wrapper(self.for_machine):
89+
if self.is_cross:
9090
if not environment.has_exe_wrapper():
9191
# Can't check if the binaries run so we have to assume they do
9292
return

mesonbuild/environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ def machine_info_can_run(machine_info: MachineInfo):
505505
if machine_info.system != detect_system():
506506
return False
507507
true_build_cpu_family = detect_cpu_family({})
508+
assert machine_info.cpu_family is not None, 'called on incomplete machine_info'
508509
return \
509510
(machine_info.cpu_family == true_build_cpu_family) or \
510511
((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86')) or \

0 commit comments

Comments
 (0)