Skip to content

Commit d3ed361

Browse files
authored
builder,pref: add -file-list support (implement feature #25707) (#25749)
1 parent c4e41c1 commit d3ed361

File tree

4 files changed

+71
-11
lines changed

4 files changed

+71
-11
lines changed

vlib/v/builder/builder_test.v

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,42 @@ fn test_conditional_executable_removal() {
4343
dump(after_second_run___)
4444
assert executable in after_second_run___
4545
}
46+
47+
fn test_file_list() {
48+
os.chdir(test_path)!
49+
os.mkdir_all('filelist')!
50+
os.write_file('filelist/main.v', 'module main
51+
fn main() {
52+
part_a := AS{}
53+
part_b := BS{}
54+
println("\${part_a}=>\${part_b}")
55+
}')!
56+
os.write_file('filelist/part_a.v', 'module main
57+
pub struct AS{}
58+
')!
59+
60+
os.write_file('filelist/part_b.v', 'module main
61+
pub struct BS{}
62+
')!
63+
64+
// `part_c.v` is not included in the compilation
65+
// or there will be a conflit definition of `struct BS`
66+
os.write_file('filelist/part_c.v', 'module main
67+
pub struct BS{}
68+
')!
69+
mut executable := 'filelist_check'
70+
$if windows {
71+
executable += '.exe'
72+
}
73+
74+
original_file_list_ := os.ls(test_path)!
75+
dump(original_file_list_)
76+
assert executable !in original_file_list_
77+
78+
cmd := '${os.quoted_path(vexe)} -o ${executable} filelist/main.v -file-list "filelist/part_a.v,filelist/part_b.v,"'
79+
os.execute(cmd)
80+
after_compile_file_list := os.ls(test_path)!.filter(os.exists(it))
81+
dump(after_compile_file_list)
82+
assert executable in after_compile_file_list
83+
assert os.execute('./${executable}').output.trim_space() == 'AS{}=>BS{}'
84+
}

vlib/v/builder/compile.v

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,24 @@ pub fn (v &Builder) get_user_files() []string {
369369
user_files << single_test_v_file
370370
dir = os.dir(single_test_v_file)
371371
}
372+
v.add_file_or_dir(mut user_files, dir)
373+
for f in v.pref.file_list {
374+
file := f.trim_space()
375+
if file.len > 0 {
376+
v.add_file_or_dir(mut user_files, file)
377+
}
378+
}
379+
if user_files.len == 0 {
380+
println('No input .v files')
381+
exit(1)
382+
}
383+
if v.pref.is_verbose {
384+
v.log('user_files: ${user_files}')
385+
}
386+
return user_files
387+
}
388+
389+
fn (v &Builder) add_file_or_dir(mut user_files []string, dir string) {
372390
does_exist := os.exists(dir)
373391
if !does_exist {
374392
verror("${dir} doesn't exist")
@@ -381,7 +399,7 @@ pub fn (v &Builder) get_user_files() []string {
381399
// Just compile one file and get parent dir
382400
user_files << single_v_file
383401
if v.pref.is_verbose {
384-
v.log('> just compile one file: "${single_v_file}"')
402+
v.log('> add one file: "${single_v_file}"')
385403
}
386404
} else if os.is_dir(dir) {
387405
if v.pref.is_verbose {
@@ -395,12 +413,4 @@ pub fn (v &Builder) get_user_files() []string {
395413
println('unknown file extension `${ext}`')
396414
exit(1)
397415
}
398-
if user_files.len == 0 {
399-
println('No input .v files')
400-
exit(1)
401-
}
402-
if v.pref.is_verbose {
403-
v.log('user_files: ${user_files}')
404-
}
405-
return user_files
406416
}

vlib/v/help/build/build.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ NB: the build flags are shared with the run command too:
9292
`./v -exclude @vlib/math/*.c.v vlib/math/math_test.v`
9393
^ run the math test file, using only pure .v files, excluding the .c.v overrides.
9494

95+
-file-list
96+
Specifies a comma-separated list of paths for compilation. Paths can be to individual .v files
97+
or directories; all .v files found recursively within directories are included.
98+
Example:
99+
`./v main.v -file-list "src/part_a.v,src/part_b.v,lib/moda"
100+
95101
-prod
96102
Compile the executable in production mode, where most optimizations are enabled.
97103
Note that most V warnings turn to errors, if you pass -prod, so you will have

vlib/v/pref/pref.v

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ pub mut:
203203
line_info string // `-line-info="file.v:28"`: for "mini VLS" (shows information about objects on provided line)
204204
linfo LineInfo
205205

206-
run_only []string // VTEST_ONLY_FN and -run-only accept comma separated glob patterns.
207-
exclude []string // glob patterns for excluding .v files from the list of .v files that otherwise would have been used for a compilation, example: `-exclude @vlib/math/*.c.v`
206+
run_only []string // VTEST_ONLY_FN and -run-only accept comma separated glob patterns.
207+
exclude []string // glob patterns for excluding .v files from the list of .v files that otherwise would have been used for a compilation, example: `-exclude @vlib/math/*.c.v`
208+
file_list []string // A list of .v files or directories. All .v files found recursively in directories will be included in the compilation.
208209
// Only test_ functions that match these patterns will be run. -run-only is valid only for _test.v files.
209210
// -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another ? { will NOT get here }`
210211
compile_defines []string // just ['vfmt']
@@ -740,6 +741,10 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
740741
res.exclude << patterns
741742
i++
742743
}
744+
'-file-list' {
745+
res.file_list = cmdline.option(args[i..], arg, '').split_any(',')
746+
i++
747+
}
743748
'-test-runner' {
744749
res.test_runner = cmdline.option(args[i..], arg, res.test_runner)
745750
i++

0 commit comments

Comments
 (0)