1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v doc: skip _x.c.v when not on x, i.e. filter files like v itself

This commit is contained in:
Delyan Angelov 2020-05-05 08:00:52 +03:00
parent 74c2a3c6e6
commit f9fe5b60a7
5 changed files with 90 additions and 87 deletions

View File

@ -93,7 +93,7 @@ fn main() {
exit(1)
}
table := table.new_table()
println(doc.doc(args[1], table))
println(doc.doc(args[1], table, prefs))
return
}
else {}

View File

@ -144,7 +144,6 @@ pub fn (b &Builder) import_graph() &depgraph.DepGraph {
}
pub fn (b Builder) v_files_from_dir(dir string) []string {
mut res := []string{}
if !os.exists(dir) {
if dir == 'compiler' && os.is_dir('vlib') {
println('looks like you are trying to build V with an old command')
@ -160,75 +159,7 @@ pub fn (b Builder) v_files_from_dir(dir string) []string {
if b.pref.is_verbose {
println('v_files_from_dir ("$dir")')
}
files.sort()
for file in files {
if !file.ends_with('.v') && !file.ends_with('.vh') {
continue
}
if file.ends_with('_test.v') {
continue
}
if b.pref.backend == .c && !b.should_compile_c(file) {
continue
}
if b.pref.backend == .js && !b.should_compile_js(file) {
continue
}
if b.pref.compile_defines_all.len > 0 && file.contains('_d_') {
mut allowed := false
for cdefine in b.pref.compile_defines {
file_postfix := '_d_${cdefine}.v'
if file.ends_with(file_postfix) {
allowed = true
break
}
}
if !allowed {
continue
}
}
res << os.join_path(dir, file)
}
return res
}
[inline]
fn (b Builder) should_compile_c(file string) bool {
if !file.ends_with('.c.v') && file.split('.').len > 2 {
// Probably something like `a.js.v`.
return false
}
if file.ends_with('_windows.c.v') && b.pref.os != .windows {
return false
}
if file.ends_with('_linux.c.v') && b.pref.os != .linux {
return false
}
if file.ends_with('_darwin.c.v') && b.pref.os != .mac {
return false
}
if file.ends_with('_nix.c.v') && b.pref.os == .windows {
return false
}
if file.ends_with('_android.c.v') && b.pref.os != .android {
return false
}
if file.ends_with('_freebsd.c.v') && b.pref.os != .freebsd {
return false
}
if file.ends_with('_solaris.c.v') && b.pref.os != .solaris {
return false
}
return true
}
[inline]
fn (b Builder) should_compile_js(file string) bool {
if !file.ends_with('.js.v') && file.split('.').len > 2 {
// Probably something like `a.c.v`.
return false
}
return true
return b.pref.should_compile_filtered_files(dir, files)
}
pub fn (b Builder) log(s string) {

View File

@ -17,7 +17,7 @@ mut:
type FilterFn = fn (node ast.FnDecl) bool
pub fn doc(mod string, table &table.Table) string {
pub fn doc(mod string, table &table.Table, prefs &pref.Preferences) string {
mut d := Doc{
out: strings.new_builder(1000)
table: table
@ -35,17 +35,12 @@ pub fn doc(mod string, table &table.Table) string {
files := os.ls(path) or {
panic(err)
}
for file in files {
if !file.ends_with('.v') {
continue
}
if file.ends_with('_test.v') || file.ends_with('_windows.c.v') || file.ends_with('_macos.c.v') {
continue
}
file_ast := parser.parse_file(os.join_path(path, file), table, .skip_comments, &pref.Preferences{},
&ast.Scope{
filtered_files := prefs.should_compile_filtered_files(path, files)
for file in filtered_files {
fscope := &ast.Scope{
parent: 0
})
}
file_ast := parser.parse_file(file, table, .skip_comments, prefs, fscope)
d.stmts << file_ast.stmts
}
if d.stmts.len == 0 {

View File

@ -1,7 +1,10 @@
import v.table
import v.doc
import v.pref
fn test_vdoc() {
mut prefs := &pref.Preferences{}
prefs.fill_with_defaults()
table := table.new_table()
println(doc.doc('net', table))
println(doc.doc('net', table, prefs))
}

View File

@ -0,0 +1,74 @@
module pref
import os
pub fn (prefs &Preferences) should_compile_filtered_files(dir string, files []string) []string {
mut res := []string{}
files.sort()
for file in files {
if !file.ends_with('.v') && !file.ends_with('.vh') {
continue
}
if file.ends_with('_test.v') {
continue
}
if prefs.backend == .c && !prefs.should_compile_c(file) {
continue
}
if prefs.backend == .js && !prefs.should_compile_js(file) {
continue
}
if prefs.compile_defines_all.len > 0 && file.contains('_d_') {
mut allowed := false
for cdefine in prefs.compile_defines {
file_postfix := '_d_${cdefine}.v'
if file.ends_with(file_postfix) {
allowed = true
break
}
}
if !allowed {
continue
}
}
res << os.join_path(dir, file)
}
return res
}
pub fn (prefs &Preferences) should_compile_c(file string) bool {
if !file.ends_with('.c.v') && file.split('.').len > 2 {
// Probably something like `a.js.v`.
return false
}
if file.ends_with('_windows.c.v') && prefs.os != .windows {
return false
}
if file.ends_with('_linux.c.v') && prefs.os != .linux {
return false
}
if file.ends_with('_darwin.c.v') && prefs.os != .mac {
return false
}
if file.ends_with('_nix.c.v') && prefs.os == .windows {
return false
}
if file.ends_with('_android.c.v') && prefs.os != .android {
return false
}
if file.ends_with('_freebsd.c.v') && prefs.os != .freebsd {
return false
}
if file.ends_with('_solaris.c.v') && prefs.os != .solaris {
return false
}
return true
}
pub fn (prefs &Preferences) should_compile_js(file string) bool {
if !file.ends_with('.js.v') && file.split('.').len > 2 {
// Probably something like `a.c.v`.
return false
}
return true
}