diff options
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/envconfig.py | 8 | ||||
-rw-r--r-- | mesonbuild/environment.py | 28 | ||||
-rw-r--r-- | mesonbuild/interpreter/interpreterobjects.py | 17 | ||||
-rwxr-xr-x | mesonbuild/scripts/env2mfile.py | 17 |
4 files changed, 66 insertions, 4 deletions
diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index 50c974b..1bf6ab9 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -260,6 +260,8 @@ class MachineInfo(HoldableObject): cpu_family: str cpu: str endian: str + kernel: T.Optional[str] + subsystem: T.Optional[str] def __post_init__(self) -> None: self.is_64_bit: bool = self.cpu_family in CPU_FAMILIES_64_BIT @@ -283,7 +285,11 @@ class MachineInfo(HoldableObject): if endian not in ('little', 'big'): mlog.warning(f'Unknown endian {endian}') - return cls(literal['system'], cpu_family, literal['cpu'], endian) + system = literal['system'] + kernel = literal.get('kernel', None) + subsystem = literal.get('subsystem', None) + + return cls(system, cpu_family, literal['cpu'], endian, kernel, subsystem) def is_windows(self) -> bool: """ diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 74bae32..688070f 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -395,6 +395,27 @@ def detect_cpu(compilers: CompilersDict) -> str: # detect_cpu_family() above. return trial +KERNEL_MAPPINGS: T.Mapping[str, str] = {'freebsd': 'freebsd', + 'openbsd': 'openbsd', + 'netbsd': 'netbsd', + 'windows': 'nt', + 'android': 'linux', + 'linux': 'linux', + 'cygwin': 'nt', + 'darwin': 'xnu', + 'sunos': 'sunos', + 'dragonfly': 'dragonfly', + 'haiku': 'haiku', + } + +def detect_kernel(system: str) -> T.Optional[str]: + return KERNEL_MAPPINGS.get(system, None) + +def detect_subsystem(system: str) -> T.Optional[str]: + if system == 'darwin': + return 'macos' + return system + def detect_system() -> str: if sys.platform == 'cygwin': return 'cygwin' @@ -411,11 +432,14 @@ def detect_machine_info(compilers: T.Optional[CompilersDict] = None) -> MachineI underlying ''detect_*'' method can be called to explicitly use the partial information. """ + system = detect_system() return MachineInfo( - detect_system(), + system, detect_cpu_family(compilers) if compilers is not None else None, detect_cpu(compilers) if compilers is not None else None, - sys.byteorder) + sys.byteorder, + detect_kernel(system), + detect_subsystem(system)) # TODO make this compare two `MachineInfo`s purely. How important is the # `detect_cpu_family({})` distinction? It is the one impediment to that. diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index 4ca7f52..fac3b0e 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -639,6 +639,8 @@ class MachineHolder(ObjectHolder['MachineInfo']): 'cpu': self.cpu_method, 'cpu_family': self.cpu_family_method, 'endian': self.endian_method, + 'kernel': self.kernel_method, + 'subsystem': self.subsystem_method, }) @noPosargs @@ -661,6 +663,21 @@ class MachineHolder(ObjectHolder['MachineInfo']): def endian_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str: return self.held_object.endian + @noPosargs + @noKwargs + def kernel_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str: + if self.held_object.kernel is not None: + return self.held_object.kernel + raise InterpreterException('Kernel not defined or could not be autodetected.') + + @noPosargs + @noKwargs + def subsystem_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str: + if self.held_object.subsystem is not None: + return self.held_object.subsystem + raise InterpreterException('Subsystem not defined or could not be autodetected.') + + class IncludeDirsHolder(ObjectHolder[build.IncludeDirs]): pass diff --git a/mesonbuild/scripts/env2mfile.py b/mesonbuild/scripts/env2mfile.py index 6eda79a..27a7dd9 100755 --- a/mesonbuild/scripts/env2mfile.py +++ b/mesonbuild/scripts/env2mfile.py @@ -44,6 +44,10 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None: help='Generate a native compilation file.') parser.add_argument('--system', default=None, help='Define system for cross compilation.') + parser.add_argument('--subsystem', default=None, + help='Define subsystem for cross compilation.') + parser.add_argument('--kernel', default=None, + help='Define kernel for cross compilation.') parser.add_argument('--cpu', default=None, help='Define cpu for cross compilation.') parser.add_argument('--cpu-family', default=None, @@ -61,6 +65,8 @@ class MachineInfo: self.cmake: T.Dict[str, T.Union[str, T.List[str]]] = {} self.system: T.Optional[str] = None + self.subsystem: T.Optional[str] = None + self.kernel: T.Optional[str] = None self.cpu: T.Optional[str] = None self.cpu_family: T.Optional[str] = None self.endian: T.Optional[str] = None @@ -181,6 +187,8 @@ def detect_cross_debianlike(options: T.Any) -> MachineInfo: data[k] = v host_arch = data['DEB_HOST_GNU_TYPE'] host_os = data['DEB_HOST_ARCH_OS'] + host_subsystem = host_os + host_kernel = 'linux' host_cpu_family = deb_cpu_family_map.get(data['DEB_HOST_GNU_CPU'], data['DEB_HOST_GNU_CPU']) host_cpu = deb_cpu_map.get(data['DEB_HOST_ARCH'], @@ -213,6 +221,8 @@ def detect_cross_debianlike(options: T.Any) -> MachineInfo: except ValueError: pass infos.system = host_os + infos.subsystem = host_subsystem + infos.kernel = host_kernel infos.cpu_family = host_cpu_family infos.cpu = host_cpu infos.endian = host_endian @@ -260,6 +270,11 @@ def write_machine_file(infos: MachineInfo, ofilename: str, write_system_info: bo ofile.write(f"cpu_family = '{infos.cpu_family}'\n") ofile.write(f"endian = '{infos.endian}'\n") ofile.write(f"system = '{infos.system}'\n") + if infos.subsystem: + ofile.write(f"subsystem = '{infos.subsystem}'\n") + if infos.kernel: + ofile.write(f"kernel = '{infos.kernel}'\n") + os.replace(tmpfilename, ofilename) def detect_language_args_from_envvars(langname: str, envvar_suffix: str = '') -> T.Tuple[T.List[str], T.List[str]]: @@ -306,7 +321,7 @@ def detect_properties_from_envvars(infos: MachineInfo, envvar_suffix: str = '') infos.properties['sys_root'] = var def detect_cross_system(infos: MachineInfo, options: T.Any) -> None: - for optname in ('system', 'cpu', 'cpu_family', 'endian'): + for optname in ('system', 'subsystem', 'kernel', 'cpu', 'cpu_family', 'endian'): v = getattr(options, optname) if not v: mlog.error(f'Cross property "{optname}" missing, set it with --{optname.replace("_", "-")}.') |