1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.builder: streamline get_os_cflags/0, use pref.os_from_string to centralise string -> v.pref.OS conversion

This commit is contained in:
Delyan Angelov 2022-03-03 10:43:50 +02:00
parent 6a3d34ae11
commit 4e7db5bab0
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 17 additions and 9 deletions

View File

@ -1,6 +1,7 @@
module builder
import os
import v.pref
import v.cflag
// get flags for current os
@ -14,17 +15,18 @@ fn (mut v Builder) get_os_cflags() []cflag.CFlag {
if flag.value.ends_with('.o') {
flag.cached = v.pref.cache_manager.postfix_with_key2cpath('.o', os.real_path(flag.value))
}
if flag.os == '' || (flag.os == 'linux' && v.pref.os == .linux)
|| (flag.os == 'macos' && v.pref.os == .macos)
|| (flag.os == 'darwin' && v.pref.os == .macos)
|| (flag.os == 'freebsd' && v.pref.os == .freebsd)
|| (flag.os == 'windows' && v.pref.os == .windows)
|| (flag.os == 'mingw' && v.pref.os == .windows && v.pref.ccompiler != 'msvc')
|| (flag.os == 'solaris' && v.pref.os == .solaris) {
if flag.os == '' || flag.os in ctimedefines {
flags << flag
continue
}
if flag.os in ctimedefines {
fos := pref.os_from_string(flag.os) or { pref.OS.all }
if fos != .all && fos == v.pref.os {
flags << flag
continue
}
if v.pref.os == .windows && flag.os == 'mingw' && v.pref.ccompiler != 'msvc' {
flags << flag
continue
}
}
return flags

View File

@ -35,6 +35,7 @@ pub fn os_from_string(os_str string) ?OS {
'windows' { return .windows }
'ios' { return .ios }
'macos' { return .macos }
'darwin' { return .macos }
'freebsd' { return .freebsd }
'openbsd' { return .openbsd }
'netbsd' { return .netbsd }
@ -50,8 +51,10 @@ pub fn os_from_string(os_str string) ?OS {
'raw' { return .raw }
'nix' { return .linux }
'wasm32' { return .wasm32 }
'wasm32-wasi' { return .wasm32_wasi }
'wasm32-wasi' { return .wasm32_wasi } // TODO: remove these *or* the _ ones
'wasm32-emscripten' { return .wasm32_emscripten }
'wasm32_wasi' { return .wasm32_wasi }
'wasm32_emscripten' { return .wasm32_emscripten }
'' { return ._auto }
else { return error('bad OS $os_str') }
}
@ -85,6 +88,9 @@ pub fn (o OS) str() string {
}
pub fn get_host_os() OS {
$if android {
return .android
}
$if linux {
return .linux
}