Skip to content

Commit

Permalink
Merge pull request #271 from DaveMcEwan/feature269
Browse files Browse the repository at this point in the history
Feature: Include files and incdirs from the environment.
  • Loading branch information
dalance authored Nov 20, 2023
2 parents 73ceb61 + 8cfb3ca commit 943c6c8
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 14 deletions.
45 changes: 39 additions & 6 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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,
Expand Down Expand Up @@ -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).
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
45 changes: 39 additions & 6 deletions md/manual-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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,
Expand Down Expand Up @@ -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).
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
33 changes: 31 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -369,6 +369,35 @@ fn print_parser_error(
Ok(())
}

#[cfg_attr(tarpaulin, skip)]
fn get_files_incdirs(
cli_files: Vec<PathBuf>,
cli_incdirs: Vec<PathBuf>
) -> (Vec<PathBuf>, Vec<PathBuf>) {
let env_incdirs: Vec<PathBuf> = if let Ok(e) = env::var("SVLINT_INCDIRS") {
env::split_paths(&e).map(|x| PathBuf::from(x)).collect()
} else {
vec![]
};

let env_prefiles: Vec<PathBuf> = if let Ok(e) = env::var("SVLINT_PREFILES") {
env::split_paths(&e).map(|x| PathBuf::from(x)).collect()
} else {
vec![]
};

let env_postfiles: Vec<PathBuf> = if let Ok(e) = env::var("SVLINT_POSTFILES") {
env::split_paths(&e).map(|x| PathBuf::from(x)).collect()
} else {
vec![]
};

let ret_files: Vec<PathBuf> = [env_prefiles, cli_files, env_postfiles].concat();
let ret_incdirs: Vec<PathBuf> = [env_incdirs, cli_incdirs].concat();

(ret_files, ret_incdirs)
}

#[cfg_attr(tarpaulin, skip)]
fn search_config(printer: &mut Printer, config: &Path) -> Option<PathBuf> {
if let Ok(c) = env::var("SVLINT_CONFIG") {
Expand Down

0 comments on commit 943c6c8

Please sign in to comment.