Skip to content

Commit

Permalink
Make sure machine_info_can_run() isn't called on incomplete MachineInfo
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lazka authored and h-vetinari committed Aug 6, 2024
1 parent 8c0de5a commit b92996d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ def get_executable_serialisation(
else:
extra_paths = []

if self.environment.need_exe_wrapper(exe_for_machine):
is_cross_built = not self.environment.machines.matches_build_machine(exe_for_machine)
if is_cross_built and self.environment.need_exe_wrapper():
if not self.environment.has_exe_wrapper():
msg = 'An exe_wrapper is needed but was not found. Please define one ' \
'in cross file and check the command and/or add it to PATH.'
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def sanity_check(self, work_dir: str, env: 'Environment') -> None:
flags += self.get_ccbin_args(env.coredata.options)

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

# Run sanity check (if possible)
if env.need_exe_wrapper(self.for_machine):
if self.is_cross:
if not env.has_exe_wrapper():
return
else:
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,15 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
compile_cmdlist = self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name]

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

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

if environment.need_exe_wrapper(self.for_machine):
if self.is_cross:
if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do
return
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _sanity_check_impl(self, work_dir: str, environment: 'Environment',
mode = CompileCheckMode.LINK
if self.is_cross:
binname += '_cross'
if environment.need_exe_wrapper(self.for_machine) and not environment.has_exe_wrapper():
if not environment.has_exe_wrapper():
# Linking cross built C/C++ apps is painful. You can't really
# tell if you should use -nostdlib or not and for example
# on OSX the compiler binary is the same but you need
Expand Down Expand Up @@ -308,7 +308,7 @@ def _sanity_check_impl(self, work_dir: str, environment: 'Environment',
if pc.returncode != 0:
raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
# Run sanity check
if environment.need_exe_wrapper(self.for_machine):
if self.is_cross:
if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do
return
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
if pc.returncode != 0:
raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.')
self._native_static_libs(work_dir, source_name)
if environment.need_exe_wrapper(self.for_machine):
if self.is_cross:
if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do
return
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ def machine_info_can_run(machine_info: MachineInfo):
if machine_info.system != detect_system():
return False
true_build_cpu_family = detect_cpu_family({})
assert machine_info.cpu_family is not None, 'called on incomplete machine_info'
return \
(machine_info.cpu_family == true_build_cpu_family) or \
((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86')) or \
Expand Down

0 comments on commit b92996d

Please sign in to comment.