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: update check_os_api_parity.v #21367

Merged
merged 1 commit into from
Apr 28, 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
77 changes: 33 additions & 44 deletions cmd/tools/check_os_api_parity.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const skip_modules = [
'builtin.bare',
'builtin.linux_bare.old',
'builtin.js',
'builtin.wasm',
'strconv',
'strconv.ftoa',
'hash',
Expand All @@ -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, '-'))
spytheman marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand All @@ -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('.', '/'))
Expand All @@ -99,29 +101,16 @@ 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
}
}
}
}
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
}
spytheman marked this conversation as resolved.
Show resolved Hide resolved
}