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

pull/13643/head
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 module builder
import os import os
import v.pref
import v.cflag import v.cflag
// get flags for current os // get flags for current os
@ -14,17 +15,18 @@ fn (mut v Builder) get_os_cflags() []cflag.CFlag {
if flag.value.ends_with('.o') { if flag.value.ends_with('.o') {
flag.cached = v.pref.cache_manager.postfix_with_key2cpath('.o', os.real_path(flag.value)) 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) if flag.os == '' || flag.os in ctimedefines {
|| (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) {
flags << flag 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 flags << flag
continue
}
if v.pref.os == .windows && flag.os == 'mingw' && v.pref.ccompiler != 'msvc' {
flags << flag
continue
} }
} }
return flags return flags

View File

@ -35,6 +35,7 @@ pub fn os_from_string(os_str string) ?OS {
'windows' { return .windows } 'windows' { return .windows }
'ios' { return .ios } 'ios' { return .ios }
'macos' { return .macos } 'macos' { return .macos }
'darwin' { return .macos }
'freebsd' { return .freebsd } 'freebsd' { return .freebsd }
'openbsd' { return .openbsd } 'openbsd' { return .openbsd }
'netbsd' { return .netbsd } 'netbsd' { return .netbsd }
@ -50,8 +51,10 @@ pub fn os_from_string(os_str string) ?OS {
'raw' { return .raw } 'raw' { return .raw }
'nix' { return .linux } 'nix' { return .linux }
'wasm32' { return .wasm32 } '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-emscripten' { return .wasm32_emscripten }
'wasm32_wasi' { return .wasm32_wasi }
'wasm32_emscripten' { return .wasm32_emscripten }
'' { return ._auto } '' { return ._auto }
else { return error('bad OS $os_str') } else { return error('bad OS $os_str') }
} }
@ -85,6 +88,9 @@ pub fn (o OS) str() string {
} }
pub fn get_host_os() OS { pub fn get_host_os() OS {
$if android {
return .android
}
$if linux { $if linux {
return .linux return .linux
} }