Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: refine check_os_api_parity.v #21371

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions cmd/tools/check_os_api_parity.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import v.ast
import rand
import term

const base_os = 'linux'
const os_names = ['linux', 'macos', 'windows', 'freebsd', 'openbsd', 'solaris', 'termux']
const base_os = pref.get_host_os()
const os_list = [pref.OS.linux, .macos, .windows, .freebsd, .openbsd, .solaris, .termux]
const skip_modules = [
'builtin.bare',
'builtin.linux_bare.old',
Expand All @@ -37,21 +37,19 @@ fn main() {
os.chdir(vroot)!
modules := if os.args.len > 1 { os.args[1..] } else { all_vlib_modules() }
mut diff_modules := map[string]bool{}
other_os_list := os_list.filter(it != base_os)
for m in modules {
if !is_verbose {
eprintln('Checking module: ${m} ...')
}
api_base := gen_api_for_module_in_os(m, base_os)
for oname in os_names {
if oname == base_os {
continue
}
api_os := gen_api_for_module_in_os(m, oname)
for other_os in other_os_list {
api_os := gen_api_for_module_in_os(m, other_os)
if api_base == api_os {
continue
}
diff_modules[m] = true
summary := 'Different APIs found for module: `${m}`, between OS base: `${base_os}` and OS: `${api_os}`'
summary := 'Different APIs found for module: `${m}`, between OS base: `${base_os}` and OS: `${other_os}`'
eprintln(term.header(summary, '-'))
if diff_cmd == '' {
continue
Expand Down Expand Up @@ -89,10 +87,11 @@ fn all_vlib_modules() []string {
return modules
}

fn gen_api_for_module_in_os(mod_name string, os_name string) string {
fn gen_api_for_module_in_os(mod_name string, os_ pref.OS) string {
if is_verbose {
eprintln('Checking module: ${mod_name:-30} for OS: ${os_name:-10} ...')
eprintln('Checking module: ${mod_name:-30} for OS: ${os_:-10} ...')
}
os_name := os_.str().to_lower()
mpath := os.join_path('vlib', mod_name.replace('.', '/'))
tmpname := '/tmp/${mod_name}_${os_name}.c'
prefs, _ := pref.parse_args([], ['-os', os_name, '-o', tmpname, '-shared', mpath])
Expand Down