2020-06-11 20:02:27 +02:00
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
|
|
|
import v.util
|
2021-06-22 17:52:34 +02:00
|
|
|
import v.util.diff
|
2020-06-11 20:02:27 +02:00
|
|
|
import v.pref
|
|
|
|
import v.builder
|
2021-12-12 20:10:43 +01:00
|
|
|
import v.builder.cbuilder
|
2020-06-11 20:02:27 +02:00
|
|
|
import v.ast
|
2021-04-05 21:57:53 +02:00
|
|
|
import rand
|
2020-06-11 20:02:27 +02:00
|
|
|
import term
|
|
|
|
|
|
|
|
const (
|
|
|
|
base_os = 'linux'
|
|
|
|
os_names = ['linux', 'macos', 'windows']
|
|
|
|
skip_modules = [
|
2020-10-15 15:17:52 +02:00
|
|
|
'builtin.bare',
|
2021-06-22 17:52:34 +02:00
|
|
|
'builtin.linux_bare.old',
|
2020-10-15 15:17:52 +02:00
|
|
|
'builtin.js',
|
|
|
|
'strconv',
|
|
|
|
'strconv.ftoa',
|
|
|
|
'hash',
|
|
|
|
'strings',
|
2020-06-11 20:02:27 +02:00
|
|
|
'crypto.rand',
|
2020-10-15 15:17:52 +02:00
|
|
|
'os.bare',
|
|
|
|
'os2',
|
|
|
|
'picohttpparser',
|
|
|
|
'picoev',
|
2020-06-11 20:02:27 +02:00
|
|
|
'szip',
|
2020-10-15 15:17:52 +02:00
|
|
|
'v.eval',
|
2020-06-11 20:02:27 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
struct App {
|
2021-01-17 15:04:08 +01:00
|
|
|
diff_cmd string
|
|
|
|
is_verbose bool
|
|
|
|
modules []string
|
2020-06-11 20:02:27 +02:00
|
|
|
mut:
|
|
|
|
api_differences map[string]int
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
vexe := pref.vexe_path()
|
|
|
|
vroot := os.dir(vexe)
|
|
|
|
util.set_vroot_folder(vroot)
|
2021-08-28 11:44:03 +02:00
|
|
|
os.chdir(vroot) ?
|
2021-06-22 17:52:34 +02:00
|
|
|
cmd := diff.find_working_diff_command() or { '' }
|
2020-06-11 20:02:27 +02:00
|
|
|
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 {
|
2020-10-15 15:17:52 +02:00
|
|
|
eprintln('Checking module: $mname ...')
|
2020-06-11 20:02:27 +02:00
|
|
|
}
|
|
|
|
api_base := app.gen_api_for_module_in_os(mname, 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)
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 16:51:02 +02:00
|
|
|
howmany := app.api_differences.len
|
2020-06-11 20:02:27 +02:00
|
|
|
if howmany > 0 {
|
|
|
|
eprintln(term.header('Found $howmany modules with different APIs', '='))
|
|
|
|
for m in app.api_differences.keys() {
|
|
|
|
eprintln('Module: $m')
|
|
|
|
}
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn all_vlib_modules() []string {
|
|
|
|
mut vlib_v_files := os.walk_ext('vlib', '.v')
|
|
|
|
mut vmodulesmap := map[string]int{}
|
|
|
|
for f in vlib_v_files {
|
|
|
|
if f.contains('/tests/') || f.ends_with('_test.v') {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
vmodulename := os.dir(f).replace('/', '.').replace('vlib.', '')
|
|
|
|
if vmodulename in skip_modules {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
vmodulesmap[vmodulename] = vmodulesmap[vmodulename] + 1
|
|
|
|
}
|
|
|
|
mut modules := vmodulesmap.keys()
|
|
|
|
modules.sort()
|
|
|
|
return modules
|
|
|
|
}
|
|
|
|
|
2020-10-15 15:17:52 +02:00
|
|
|
fn (app App) gen_api_for_module_in_os(mod_name string, os_name string) string {
|
2020-06-11 20:02:27 +02:00
|
|
|
if app.is_verbose {
|
|
|
|
eprintln('Checking module: ${mod_name:-30} for OS: ${os_name:-10} ...')
|
|
|
|
}
|
|
|
|
mpath := os.join_path('vlib', mod_name.replace('.', '/'))
|
|
|
|
tmpname := '/tmp/${mod_name}_${os_name}.c'
|
2021-02-18 11:08:14 +01:00
|
|
|
prefs, _ := pref.parse_args([], ['-os', os_name, '-o', tmpname, '-shared', mpath])
|
2020-06-11 20:02:27 +02:00
|
|
|
mut b := builder.new_builder(prefs)
|
2021-12-12 20:10:43 +01:00
|
|
|
cbuilder.compile_c(mut b)
|
2020-06-11 20:02:27 +02:00
|
|
|
mut res := []string{}
|
|
|
|
for f in b.parsed_files {
|
|
|
|
for s in f.stmts {
|
|
|
|
if s is ast.FnDecl {
|
2020-07-09 17:14:14 +02:00
|
|
|
if s.is_pub {
|
2021-01-17 15:04:08 +01:00
|
|
|
fn_signature := s.stringify(b.table, mod_name, map[string]string{})
|
2020-07-09 17:14:14 +02:00
|
|
|
fn_mod := s.modname()
|
2020-06-11 20:02:27 +02:00
|
|
|
if fn_mod == mod_name {
|
2020-10-15 15:17:52 +02:00
|
|
|
fline := '$fn_mod: $fn_signature'
|
2020-06-11 20:02:27 +02:00
|
|
|
res << fline
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.sort()
|
|
|
|
return res.join('\n')
|
|
|
|
}
|
|
|
|
|
2020-10-15 15:17:52 +02:00
|
|
|
fn (mut app App) compare_api(api_base string, api_os string, mod_name string, os_base string, os_target string) {
|
2021-06-22 17:52:34 +02:00
|
|
|
res := diff.color_compare_strings(app.diff_cmd, rand.ulid(), api_base, api_os)
|
2020-06-11 20:02:27 +02:00
|
|
|
if res.len > 0 {
|
2020-10-15 15:17:52 +02:00
|
|
|
summary := 'Different APIs found for module: `$mod_name`, between OS base: `$os_base` and OS: `$os_target`'
|
2020-06-11 20:02:27 +02:00
|
|
|
eprintln(term.header(summary, '-'))
|
|
|
|
eprintln(res)
|
|
|
|
eprintln(term.h_divider('-'))
|
|
|
|
app.api_differences[mod_name] = 1
|
|
|
|
}
|
|
|
|
}
|