From 21aa97206f8c9160b346bfc2a14b772e70e2f61d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 6 Sep 2023 22:02:14 +0300 Subject: [PATCH] all: support `./v -exclude @vlib/math/*.c.v vlib/math/math_test.v`, for using the pure V math module implementation, without the .c.v overrides there. (#19290) --- vlib/v/help/build/build.txt | 11 +++++++++++ vlib/v/pref/default.v | 30 ++++++++++++++++++++++++------ vlib/v/pref/pref.v | 10 +++++++++- vlib/v/pref/should_compile.v | 10 +++++++++- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/vlib/v/help/build/build.txt b/vlib/v/help/build/build.txt index bc91e44bcb..303e88ab10 100644 --- a/vlib/v/help/build/build.txt +++ b/vlib/v/help/build/build.txt @@ -77,6 +77,17 @@ NB: the build flags are shared with the run command too: -path "/v/my_project_private_modules|@vlib|@vmodules" By default, -path is just "@vlib|@vmodules" . + -exclude + Specify an exclude pattern that will be applied as a filter over the full paths of the .v + files, that otherwise would have been selected for compilation. + Note: + @vroot is expanded to the location, where the v executable is. + @vlib is expanded do the location where your vlib/ folder is (next to your v executable). + @vmodules is expanded with the location of your ~/.vmodules/ folder. + Example: + `./v -exclude @vlib/math/*.c.v vlib/math/math_test.v` + ^ run the math test file, using only pure .v files, excluding the .c.v overrides. + -prod Compile the executable in production mode, where most optimizations are enabled. Note that most V warnings turn to errors, if you pass -prod, so you will have diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index 47ed9be2f1..d4a5e8e340 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -6,9 +6,7 @@ module pref import os import v.vcache -pub const ( - default_module_path = os.vmodules_dir() -) +pub const default_module_path = os.vmodules_dir() pub fn new_preferences() &Preferences { mut p := &Preferences{} @@ -21,26 +19,46 @@ fn (mut p Preferences) expand_lookup_paths() { // Location of all vlib files p.vroot = os.dir(vexe_path()) } - vlib_path := os.join_path(p.vroot, 'vlib') + p.vlib = os.join_path(p.vroot, 'vlib') + p.vmodules_paths = os.vmodules_paths() + // if p.lookup_path.len == 0 { p.lookup_path = ['@vlib', '@vmodules'] } mut expanded_paths := []string{} for path in p.lookup_path { match path { - '@vlib' { expanded_paths << vlib_path } - '@vmodules' { expanded_paths << os.vmodules_paths() } + '@vlib' { expanded_paths << p.vlib } + '@vmodules' { expanded_paths << p.vmodules_paths } else { expanded_paths << path } } } p.lookup_path = expanded_paths } +fn (mut p Preferences) expand_exclude_paths() { + mut res := []string{} + static_replacement_list := ['@vroot', p.vroot, '@vlib', p.vlib] + for x in p.exclude { + y := x.replace_each(static_replacement_list) + if y.contains('@vmodules') { + // @vmodules is a list of paths, each of which should be expanded in the complete exclusion list: + for vmp in p.vmodules_paths { + res << y.replace('@vmodules', vmp) + } + continue + } + res << y + } + p.exclude = res +} + pub fn (mut p Preferences) fill_with_defaults() { if p.arch == ._auto { p.arch = get_host_arch() } p.expand_lookup_paths() + p.expand_exclude_paths() rpath := os.real_path(p.path) if p.out_name == '' { filename := os.file_name(rpath).trim_space() diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 6a1ecbd275..400073a673 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -184,12 +184,15 @@ pub mut: output_es5 bool prealloc bool vroot string - out_name_c string // full os.real_path to the generated .tmp.c file; set by builder. + vlib string // absolute path to the vlib/ folder + vmodules_paths []string // absolute paths to the vmodules folders, by default ['/home/user/.vmodules'], can be overriden by setting VMODULES + out_name_c string // full os.real_path to the generated .tmp.c file; set by builder. out_name string path string // Path to file/folder to compile line_info string // `-line-info="file.v:28"`: for "mini VLS" (shows information about objects on provided line) // run_only []string // VTEST_ONLY_FN and -run-only accept comma separated glob patterns. + 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` // Only test_ functions that match these patterns will be run. -run-only is valid only for _test.v files. // // -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another ? { will NOT get here }` @@ -620,6 +623,11 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin res.run_only = cmdline.option(current_args, arg, os.getenv('VTEST_ONLY_FN')).split_any(',') i++ } + '-exclude' { + patterns := cmdline.option(current_args, arg, '').split_any(',') + res.exclude << patterns + i++ + } '-test-runner' { res.test_runner = cmdline.option(current_args, arg, res.test_runner) i++ diff --git a/vlib/v/pref/should_compile.v b/vlib/v/pref/should_compile.v index 6f49f50bc6..45cf28220d 100644 --- a/vlib/v/pref/should_compile.v +++ b/vlib/v/pref/should_compile.v @@ -7,7 +7,7 @@ pub fn (prefs &Preferences) should_compile_filtered_files(dir string, files_ []s mut files := files_.clone() files.sort() mut all_v_files := []string{} - for file in files { + files_loop: for file in files { if !file.ends_with('.v') && !file.ends_with('.vh') { continue } @@ -75,6 +75,14 @@ pub fn (prefs &Preferences) should_compile_filtered_files(dir string, files_ []s continue } } + if prefs.exclude.len > 0 { + full_file_path := os.join_path(dir, file) + for epattern in prefs.exclude { + if full_file_path.match_glob(epattern) { + continue files_loop + } + } + } all_v_files << os.join_path(dir, file) } //