From 5add765812bb570a4daba463ba0b59273421d977 Mon Sep 17 00:00:00 2001 From: Dave McEwan Date: Sat, 11 Nov 2023 21:35:15 +0000 Subject: [PATCH 1/5] feature269 Tidy manual-introduction headings for easier navigation. --- md/manual-introduction.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/md/manual-introduction.md b/md/manual-introduction.md index 80e3e48c..9cda94d6 100644 --- a/md/manual-introduction.md +++ b/md/manual-introduction.md @@ -51,7 +51,7 @@ Another class of functional rules is those which check for datatypes and constructs that avoid compiler checks for legacy compatibility. -## Usage +## How Svlint Works Svlint works in a series of well-defined steps: @@ -73,7 +73,7 @@ Svlint works in a series of well-defined steps: failure, otherwise return a pass. -### Filelists +## Filelists Specification of the files to be processed can be given on the command line by *either* a list of files, e.g. `svlint foo.sv bar/*.sv`, or via filelists, @@ -103,7 +103,7 @@ $(FOO)/ddd.sv ``` -### Plugin Syntax Rules +## Plugin Syntax Rules Svlint supports plugin syntax rules, an example of which is available [here](https://github.com/dalance/svlint-plugin-sample). @@ -119,7 +119,7 @@ All loaded plugins, via the `--plugin` option, are enabled and have access to all values in the TOML configuration. -### Configuration +## Configuration Firstly, you need a TOML configuration file to specify which rules to enable. By default, svlint will search up the filesystem hierarchy from the current @@ -165,7 +165,7 @@ To generate an updated configuration, use the `--update` command line option which will load your existing configuration then emit the updated TOML to STDOUT. -#### `[option]` Section +### `[option]` Section - `exclude_paths` is a list of regular expressions. If a file path is matched with any regex in the list, the file is skipped. @@ -187,7 +187,7 @@ STDOUT. - Please see the explanations for individual rules for details of other options. -#### `[textrules]` and `[syntaxrules]` Sections +### `[textrules]` and `[syntaxrules]` Sections All rules are disabled unless explicitly enabled in their corresponding `[textrules]` or `[syntaxrules]` section. From 853d5a25f99d1d20246e7f70ab607f20a3f48279 Mon Sep 17 00:00:00 2001 From: Dave McEwan Date: Sat, 11 Nov 2023 21:36:03 +0000 Subject: [PATCH 2/5] feature269 Describe intended functionality of env vars in MANUAL. SVLINT_INCDIRS, SVLINT_PREFILES, SVLINT_POSTFILES --- md/manual-introduction.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/md/manual-introduction.md b/md/manual-introduction.md index 9cda94d6..d188e29a 100644 --- a/md/manual-introduction.md +++ b/md/manual-introduction.md @@ -119,6 +119,39 @@ All loaded plugins, via the `--plugin` option, are enabled and have access to all values in the TOML configuration. +## Environment Variables + +Svlint is sensitive to 4 environment variables: +- `SVLINT_CONFIG` - an exact absolute or relative path to a TOML configuration. + This is the only way to specify an *exact* configuration path, as the `-c` + command-line option is used to search hierarchically. +- `SVLINT_INCDIRS` - a colon-separated list of include paths, i.e. an + alternative to using the `-I` command-line option. +- `SVLINT_PREFILES` - a colon-separated list of files to process before those + given on the command-vline. +- `SVLINT_POSTFILES` - a colon-separated list of files to process after those + given on the command-line. + + +For example: +```sh +svlint -I/cad/tools/uvm -I/work/myTeam \ + uvm_macros.svh \ + /another/thing/first \ + foo.sv bar.sv \ + /another/thing/last \ + check_pp_final_state.svh +``` + +Is exactly equivalent to: +```sh +$ export SVLINT_INCDIRS="/cad/tools/uvm:/work/myTeam" +$ export SVLINT_PREFILES="uvm_macros.svh:/another/thing/first" +$ export SVLINT_POSTFILES="/another/thing/last:check_pp_final_state.svh" +$ svlint foo.sv bar.sv +``` + + ## Configuration Firstly, you need a TOML configuration file to specify which rules to enable. From 4a7a47297f3d491a8670a4afd65d57278f36c7d4 Mon Sep 17 00:00:00 2001 From: Dave McEwan Date: Sat, 11 Nov 2023 22:23:25 +0000 Subject: [PATCH 3/5] feature269 Implement [proposal 1](https://github.com/dalance/svlint/issues/269#issuecomment-1806918798) This command... ```sh $ SVLINT_PREFILES='preA:preB' \ SVLINT_POSTFILES='postA:postB' \ SVLINT_INCDIRS='incA:incB' \ cargo run -- --dump-filelist=yaml -IincX -IincY cliX.sv cliY.sv ``` ...gives the output: ``` ".": files: - "preA" - "preB" - "cliX.sv" - "cliY.sv" - "postA" - "postB" incdirs: - "incA" - "incB" - "incX" - "incY" defines: ``` --- src/main.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index fa73e26a..92bb3ad9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -243,9 +243,9 @@ pub fn run_opt_config(printer: &mut Printer, opt: &Opt, config: Config) -> Resul } } - (files, incdirs) + get_files_incdirs(files, incdirs) } else { - (opt.files.clone(), opt.incdirs.clone()) + get_files_incdirs(opt.files.clone(), opt.incdirs.clone()) }; if let Some(mode) = &opt.dump_filelist { @@ -369,6 +369,35 @@ fn print_parser_error( Ok(()) } +#[cfg_attr(tarpaulin, skip)] +fn get_files_incdirs( + cli_files: Vec, + cli_incdirs: Vec +) -> (Vec, Vec) { + let env_incdirs: Vec = if let Ok(e) = env::var("SVLINT_INCDIRS") { + e.split(':').map(|x| PathBuf::from(x)).collect() + } else { + vec![] + }; + + let env_prefiles: Vec = if let Ok(e) = env::var("SVLINT_PREFILES") { + e.split(':').map(|x| PathBuf::from(x)).collect() + } else { + vec![] + }; + + let env_postfiles: Vec = if let Ok(e) = env::var("SVLINT_POSTFILES") { + e.split(':').map(|x| PathBuf::from(x)).collect() + } else { + vec![] + }; + + let ret_files: Vec = [env_prefiles, cli_files, env_postfiles].concat(); + let ret_incdirs: Vec = [env_incdirs, cli_incdirs].concat(); + + (ret_files, ret_incdirs) +} + #[cfg_attr(tarpaulin, skip)] fn search_config(printer: &mut Printer, config: &Path) -> Option { if let Ok(c) = env::var("SVLINT_CONFIG") { From d4e925f255b431831bd0a32fb574e94412b57184 Mon Sep 17 00:00:00 2001 From: Dave McEwan Date: Sat, 11 Nov 2023 22:24:16 +0000 Subject: [PATCH 4/5] feature269 Rerun mdgen --- MANUAL.md | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/MANUAL.md b/MANUAL.md index 17e8d89b..eed753e2 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -51,7 +51,7 @@ Another class of functional rules is those which check for datatypes and constructs that avoid compiler checks for legacy compatibility. -## Usage +## How Svlint Works Svlint works in a series of well-defined steps: @@ -73,7 +73,7 @@ Svlint works in a series of well-defined steps: failure, otherwise return a pass. -### Filelists +## Filelists Specification of the files to be processed can be given on the command line by *either* a list of files, e.g. `svlint foo.sv bar/*.sv`, or via filelists, @@ -103,7 +103,7 @@ $(FOO)/ddd.sv ``` -### Plugin Syntax Rules +## Plugin Syntax Rules Svlint supports plugin syntax rules, an example of which is available [here](https://github.com/dalance/svlint-plugin-sample). @@ -119,7 +119,40 @@ All loaded plugins, via the `--plugin` option, are enabled and have access to all values in the TOML configuration. -### Configuration +## Environment Variables + +Svlint is sensitive to 4 environment variables: +- `SVLINT_CONFIG` - an exact absolute or relative path to a TOML configuration. + This is the only way to specify an *exact* configuration path, as the `-c` + command-line option is used to search hierarchically. +- `SVLINT_INCDIRS` - a colon-separated list of include paths, i.e. an + alternative to using the `-I` command-line option. +- `SVLINT_PREFILES` - a colon-separated list of files to process before those + given on the command-vline. +- `SVLINT_POSTFILES` - a colon-separated list of files to process after those + given on the command-line. + + +For example: +```sh +svlint -I/cad/tools/uvm -I/work/myTeam \ + uvm_macros.svh \ + /another/thing/first \ + foo.sv bar.sv \ + /another/thing/last \ + check_pp_final_state.svh +``` + +Is exactly equivalent to: +```sh +$ export SVLINT_INCDIRS="/cad/tools/uvm:/work/myTeam" +$ export SVLINT_PREFILES="uvm_macros.svh:/another/thing/first" +$ export SVLINT_POSTFILES="/another/thing/last:check_pp_final_state.svh" +$ svlint foo.sv bar.sv +``` + + +## Configuration Firstly, you need a TOML configuration file to specify which rules to enable. By default, svlint will search up the filesystem hierarchy from the current @@ -165,7 +198,7 @@ To generate an updated configuration, use the `--update` command line option which will load your existing configuration then emit the updated TOML to STDOUT. -#### `[option]` Section +### `[option]` Section - `exclude_paths` is a list of regular expressions. If a file path is matched with any regex in the list, the file is skipped. @@ -187,7 +220,7 @@ STDOUT. - Please see the explanations for individual rules for details of other options. -#### `[textrules]` and `[syntaxrules]` Sections +### `[textrules]` and `[syntaxrules]` Sections All rules are disabled unless explicitly enabled in their corresponding `[textrules]` or `[syntaxrules]` section. From 8cfb3ca098ca7dd8727cadd31db31b2bb34eb831 Mon Sep 17 00:00:00 2001 From: Dave McEwan Date: Tue, 14 Nov 2023 15:15:15 +0000 Subject: [PATCH 5/5] feature269 Use `env::split_paths` instead of `str::split(':')` hack. --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 92bb3ad9..70bda828 100644 --- a/src/main.rs +++ b/src/main.rs @@ -375,19 +375,19 @@ fn get_files_incdirs( cli_incdirs: Vec ) -> (Vec, Vec) { let env_incdirs: Vec = if let Ok(e) = env::var("SVLINT_INCDIRS") { - e.split(':').map(|x| PathBuf::from(x)).collect() + env::split_paths(&e).map(|x| PathBuf::from(x)).collect() } else { vec![] }; let env_prefiles: Vec = if let Ok(e) = env::var("SVLINT_PREFILES") { - e.split(':').map(|x| PathBuf::from(x)).collect() + env::split_paths(&e).map(|x| PathBuf::from(x)).collect() } else { vec![] }; let env_postfiles: Vec = if let Ok(e) = env::var("SVLINT_POSTFILES") { - e.split(':').map(|x| PathBuf::from(x)).collect() + env::split_paths(&e).map(|x| PathBuf::from(x)).collect() } else { vec![] };