From 31171263dfafab836116998ebf806a4ca725b321 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Sun, 28 Apr 2024 15:11:35 +0200 Subject: [PATCH] tools: update check_os_api_parity.v (#21367) --- cmd/tools/check_os_api_parity.v | 77 ++++++++++++++------------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/cmd/tools/check_os_api_parity.v b/cmd/tools/check_os_api_parity.v index 3945c5359f0921..52d7c33b567dd7 100644 --- a/cmd/tools/check_os_api_parity.v +++ b/cmd/tools/check_os_api_parity.v @@ -16,6 +16,7 @@ const skip_modules = [ 'builtin.bare', 'builtin.linux_bare.old', 'builtin.js', + 'builtin.wasm', 'strconv', 'strconv.ftoa', 'hash', @@ -26,43 +27,44 @@ const skip_modules = [ 'szip', 'v.eval', ] - -struct App { - diff_cmd string - is_verbose bool - modules []string -mut: - api_differences map[string]int -} +const is_verbose = os.getenv('VERBOSE') != '' +const diff_cmd = diff.find_working_diff_command() or { '' } fn main() { vexe := os.real_path(os.getenv_opt('VEXE') or { @VEXE }) vroot := os.dir(vexe) util.set_vroot_folder(vroot) os.chdir(vroot)! - cmd := diff.find_working_diff_command() or { '' } - mut app := App{ - diff_cmd: cmd - is_verbose: os.getenv('VERBOSE').len > 0 - modules: if os.args.len > 1 { os.args[1..] } else { all_vlib_modules() } - } - for mname in app.modules { - if !app.is_verbose { - eprintln('Checking module: ${mname} ...') + modules := if os.args.len > 1 { os.args[1..] } else { all_vlib_modules() } + mut diff_modules := map[string]bool{} + for m in modules { + if !is_verbose { + eprintln('Checking module: ${m} ...') } - api_base := app.gen_api_for_module_in_os(mname, base_os) + api_base := gen_api_for_module_in_os(m, base_os) for oname in os_names { if oname == base_os { continue } - api_os := app.gen_api_for_module_in_os(mname, oname) - app.compare_api(api_base, api_os, mname, base_os, oname) + api_os := gen_api_for_module_in_os(m, oname) + 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}`' + eprintln(term.header(summary, '-')) + if diff_cmd == '' { + continue + } + diff_ := diff.color_compare_strings(diff_cmd, rand.ulid(), api_base, api_os) + println(diff_) + eprintln(term.h_divider('-')) } } - howmany := app.api_differences.len - if howmany > 0 { - eprintln(term.header('Found ${howmany} modules with different APIs', '=')) - for m in app.api_differences.keys() { + if diff_modules.len > 0 { + eprintln(term.header('Found ${diff_modules.len} modules with different APIs', + '=')) + for m in diff_modules.keys() { eprintln('Module: ${m}') } exit(1) @@ -87,8 +89,8 @@ fn all_vlib_modules() []string { return modules } -fn (app App) gen_api_for_module_in_os(mod_name string, os_name string) string { - if app.is_verbose { +fn gen_api_for_module_in_os(mod_name string, os_name string) string { + if is_verbose { eprintln('Checking module: ${mod_name:-30} for OS: ${os_name:-10} ...') } mpath := os.join_path('vlib', mod_name.replace('.', '/')) @@ -99,14 +101,12 @@ fn (app App) gen_api_for_module_in_os(mod_name string, os_name string) string { mut res := []string{} for f in b.parsed_files { for s in f.stmts { - if s is ast.FnDecl { - if s.is_pub { + if s is ast.FnDecl && s.is_pub { + fn_mod := s.modname() + if fn_mod == mod_name { fn_signature := b.table.stringify_fn_decl(&s, mod_name, map[string]string{}) - fn_mod := s.modname() - if fn_mod == mod_name { - fline := '${fn_mod}: ${fn_signature}' - res << fline - } + fline := '${fn_mod}: ${fn_signature}' + res << fline } } } @@ -114,14 +114,3 @@ fn (app App) gen_api_for_module_in_os(mod_name string, os_name string) string { res.sort() return res.join('\n') } - -fn (mut app App) compare_api(api_base string, api_os string, mod_name string, os_base string, os_target string) { - res := diff.color_compare_strings(app.diff_cmd, rand.ulid(), api_base, api_os) - if res.len > 0 { - summary := 'Different APIs found for module: `${mod_name}`, between OS base: `${os_base}` and OS: `${os_target}`' - eprintln(term.header(summary, '-')) - eprintln(res) - eprintln(term.h_divider('-')) - app.api_differences[mod_name] = 1 - } -}