Refactor getting the host system of a cross compiler

Use mesonlib.for_windows or mesonlib.for_cygwin instead of
reimplementing them.

Add CrossBuildInfo.get_host_system to shorten the repeated the code in
the mesonlib.for_<platform> methods.
pull/3771/merge
George Koehler 7 years ago committed by Nirbheek Chauhan
parent e4a83e47d4
commit e0ed1ceae2
  1. 12
      mesonbuild/environment.py
  2. 24
      mesonbuild/mesonlib.py

@ -345,13 +345,11 @@ class Environment:
# static libraries, and executables.
# Versioning is added to these names in the backends as-needed.
cross = self.is_cross_build()
if (not cross and mesonlib.is_windows()) \
or (cross and self.cross_info.has_host() and self.cross_info.config['host_machine']['system'] == 'windows'):
if mesonlib.for_windows(cross, self):
self.exe_suffix = 'exe'
self.object_suffix = 'obj'
self.win_libdir_layout = True
elif (not cross and mesonlib.is_cygwin()) \
or (cross and self.cross_info.has_host() and self.cross_info.config['host_machine']['system'] == 'cygwin'):
elif mesonlib.for_cygwin(cross, self):
self.exe_suffix = 'exe'
self.object_suffix = 'o'
self.win_libdir_layout = True
@ -1039,6 +1037,12 @@ class CrossBuildInfo:
def get_stdlib(self, language):
return self.config['properties'][language + '_stdlib']
def get_host_system(self):
"Name of host system like 'linux', or None"
if self.has_host():
return self.config['host_machine']['system']
return None
def get_properties(self):
return self.config['properties']

@ -299,9 +299,7 @@ def for_windows(is_cross, env):
"""
if not is_cross:
return is_windows()
elif env.cross_info.has_host():
return env.cross_info.config['host_machine']['system'] == 'windows'
return False
return env.cross_info.get_host_system() == 'windows'
def for_cygwin(is_cross, env):
"""
@ -311,9 +309,7 @@ def for_cygwin(is_cross, env):
"""
if not is_cross:
return is_cygwin()
elif env.cross_info.has_host():
return env.cross_info.config['host_machine']['system'] == 'cygwin'
return False
return env.cross_info.get_host_system() == 'cygwin'
def for_linux(is_cross, env):
"""
@ -323,9 +319,7 @@ def for_linux(is_cross, env):
"""
if not is_cross:
return is_linux()
elif env.cross_info.has_host():
return env.cross_info.config['host_machine']['system'] == 'linux'
return False
return env.cross_info.get_host_system() == 'linux'
def for_darwin(is_cross, env):
"""
@ -335,9 +329,7 @@ def for_darwin(is_cross, env):
"""
if not is_cross:
return is_osx()
elif env.cross_info.has_host():
return env.cross_info.config['host_machine']['system'] in ('darwin', 'ios')
return False
return env.cross_info.get_host_system() in ('darwin', 'ios')
def for_android(is_cross, env):
"""
@ -347,9 +339,7 @@ def for_android(is_cross, env):
"""
if not is_cross:
return is_android()
elif env.cross_info.has_host():
return env.cross_info.config['host_machine']['system'] == 'android'
return False
return env.cross_info.get_host_system() == 'android'
def for_haiku(is_cross, env):
"""
@ -359,9 +349,7 @@ def for_haiku(is_cross, env):
"""
if not is_cross:
return is_haiku()
elif env.cross_info.has_host():
return env.cross_info.config['host_machine']['system'] == 'haiku'
return False
return env.cross_info.get_host_system() == 'haiku'
def for_openbsd(is_cross, env):
"""

Loading…
Cancel
Save