vdoc: filter testdata and tests folders by default, reduce filesystem stats calls

This commit is contained in:
Delyan Angelov 2023-12-20 13:54:08 +02:00
parent 23ed1e9ae8
commit 818744e381
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED

View file

@ -39,22 +39,34 @@ fn is_included(path string, ignore_paths []string) bool {
return true return true
} }
fn get_modules_list(path string, ignore_paths2 []string) []string { fn get_modules_list(opath string, ignore_paths2 []string) []string {
files := os.ls(path) or { return []string{} } path := opath.trim_right('/\\')
names := os.ls(path) or { return [] }
mut ignore_paths := get_ignore_paths(path) or { []string{} } mut ignore_paths := get_ignore_paths(path) or { []string{} }
ignore_paths << ignore_paths2 ignore_paths << ignore_paths2
mut dirs := []string{} mut dirs := map[string]int{}
for file in files { for name in names {
fpath := os.join_path(path, file) if name == 'testdata' {
if os.is_dir(fpath) && is_included(fpath, ignore_paths) && !os.is_link(path) { continue
dirs << get_modules_list(fpath, ignore_paths.filter(it.starts_with(fpath))) }
} else if fpath.ends_with('.v') && !fpath.ends_with('_test.v') { if name == 'tests' {
if path in dirs { continue
continue }
fpath := os.join_path(path, name)
fmeta := os.inode(fpath)
if fmeta.typ == .directory && is_included(fpath, ignore_paths) {
current_ignore_paths := ignore_paths.filter(it.starts_with(fpath))
for k in get_modules_list(fpath, current_ignore_paths) {
dirs[k]++
} }
dirs << path continue
}
if fpath.ends_with('.v') && !fpath.ends_with('_test.v') {
dirs[path]++
continue
} }
} }
dirs.sort() mut res := dirs.keys()
return dirs res.sort()
return res
} }