Skip to content

Commit

Permalink
Rename scope and exclude args (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexroan committed May 29, 2024
1 parent 9d2e5d8 commit 3020207
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: run
args: -- -o reports/ccip-functions-report-workflow.md tests/ccip-contracts/contracts --src src/v0.8/functions/ --exclude "tests/,test/,mocks/" --skip-update-check --icf
args: -- -o reports/ccip-functions-report-workflow.md tests/ccip-contracts/contracts --src src/v0.8/functions/ -x "tests/,test/,mocks/" --skip-update-check --icf

- name: Check ccip-functions-report-workflow.md vs ccip-functions-report.md
run: |
Expand All @@ -202,7 +202,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: run
args: -- -o ./reports/report-workflow.json --scope src/ --exclude lib/ ./tests/contract-playground/ --skip-update-check --icf
args: -- -o ./reports/report-workflow.json -i src/ -x lib/ ./tests/contract-playground/ --skip-update-check --icf

- name: Check report.json vs report-workflow.json
run: |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ Usage: `aderyn [OPTIONS] <ROOT>`

Options:
- `-o`, `--output <OUTPUT>`: Desired file path for the final report (will overwrite the existing one) [default: report.md]
- `-s`, `--scope <SCOPE>`: List of path strings to include, delimited by comma (no spaces). Any solidity file path not containing these strings will be ignored
- `-e`, `--exclude <EXCLUDE>`: List of path strings to exclude, delimited by comma (no spaces). Any solidity file path containing these strings will be ignored
- `-i`, `--path-includes <PATH_INCLUDES>`: List of path strings to include, delimited by comma (no spaces). Any solidity file path not containing these strings will be ignored
- `-x`, `--path-excludes <PATH_EXCLUDES>`: List of path strings to exclude, delimited by comma (no spaces). Any solidity file path containing these strings will be ignored
- `-n`, `--no-snippets`: Do not include code snippets in the report (reduces report size in large repos)
- `-h`, `--help`: Print help
- `-V`, `--version`: Print version
Expand Down
4 changes: 2 additions & 2 deletions aderyn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ Usage: `aderyn [OPTIONS] <ROOT>`

Options:
- `-o`, `--output <OUTPUT>`: Desired file path for the final report (will overwrite the existing one) [default: report.md]
- `-s`, `--scope <SCOPE>`: List of path strings to include, delimited by comma (no spaces). Any solidity file path not containing these strings will be ignored
- `-e`, `--exclude <EXCLUDE>`: List of path strings to exclude, delimited by comma (no spaces). Any solidity file path containing these strings will be ignored
- `-i`, `--path-includes <PATH_INCLUDES>`: List of path strings to include, delimited by comma (no spaces). Any solidity file path not containing these strings will be ignored
- `-x`, `--path-excludes <PATH_EXCLUDES>`: List of path strings to exclude, delimited by comma (no spaces). Any solidity file path containing these strings will be ignored
- `-n`, `--no-snippets`: Do not include code snippets in the report (reduces report size in large repos)
- `-h`, `--help`: Print help
- `-V`, `--version`: Print version
Expand Down
24 changes: 16 additions & 8 deletions aderyn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub struct CommandLineArgs {

/// List of path strings to include, delimited by comma (no spaces).
/// Any solidity file path not containing these strings will be ignored
#[clap(short, long, use_value_delimiter = true)]
scope: Option<Vec<String>>,
#[clap(short = 'i', long, use_value_delimiter = true)]
path_includes: Option<Vec<String>>,

/// List of path strings to exclude, delimited by comma (no spaces).
/// Any solidity file path containing these strings will be ignored
#[clap(short, long, use_value_delimiter = true)]
exclude: Option<Vec<String>>,
#[clap(short = 'x', long, use_value_delimiter = true)]
path_excludes: Option<Vec<String>>,

/// Do not include code snippets in the report (reduces report size in large repos)
#[arg(short, long)]
Expand Down Expand Up @@ -65,8 +65,16 @@ pub struct CommandLineArgs {
#[arg(long, name = "icf")]
icf: bool,

/// Path relative to project root, inside which solidity contracts will be analyzed
#[clap(long, use_value_delimiter = true, group = "icf_dependent")]
/// Path to the source contracts. If not provided, the ROOT directory will be used.
///
/// For example, in a foundry repo:
///
/// --src=src/
///
/// In a hardhat repo:
///
/// --src=contracts/
#[clap(short, long, use_value_delimiter = true, group = "icf_dependent")]
src: Option<Vec<String>>,

/// Watch for file changes and continuously generate report
Expand Down Expand Up @@ -106,8 +114,8 @@ fn main() {
root: cmd_args.root,
output: cmd_args.output,
src: cmd_args.src,
scope: cmd_args.scope,
exclude: cmd_args.exclude,
path_includes: cmd_args.path_includes,
path_excludes: cmd_args.path_excludes,
no_snippets: cmd_args.no_snippets,
skip_build: cmd_args.skip_build,
skip_cloc: cmd_args.skip_cloc,
Expand Down
4 changes: 2 additions & 2 deletions aderyn_driver/benches/detectors_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn bench_aderyn_on_contract_playground(c: &mut Criterion) {
skip_build: true,
skip_cloc: true,
skip_update_check: true,
exclude: None,
scope: None,
path_excludes: None,
path_includes: None,
src: None,
stdout: false,
auditor_mode: false,
Expand Down
30 changes: 15 additions & 15 deletions aderyn_driver/src/config_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct AderynConfig {
pub src: Option<String>,
pub exclude: Option<Vec<String>>,
pub remappings: Option<Vec<String>>,
pub scope: Option<Vec<String>>,
pub include: Option<Vec<String>>,
}

/// Load the aderyn.toml file and deserialize it to AderynConfig
Expand All @@ -36,7 +36,7 @@ pub fn derive_from_aderyn_toml(
src: &Option<Vec<String>>,
exclude: &Option<Vec<String>>,
remappings: &Option<Vec<String>>,
scope: &Option<Vec<String>>,
include: &Option<Vec<String>>,
) -> (
PathBuf, // Root
Option<Vec<String>>, // Src
Expand All @@ -45,7 +45,7 @@ pub fn derive_from_aderyn_toml(
Option<Vec<String>>, // Scope
) {
let config = load_aderyn_config(root).unwrap();
interpret_aderyn_config(config, root, src, exclude, remappings, scope)
interpret_aderyn_config(config, root, src, exclude, remappings, include)
}

#[allow(clippy::type_complexity)]
Expand All @@ -55,7 +55,7 @@ fn interpret_aderyn_config(
src: &Option<Vec<String>>,
exclude: &Option<Vec<String>>,
remappings: &Option<Vec<String>>,
scope: &Option<Vec<String>>,
include: &Option<Vec<String>>,
) -> (
PathBuf, // Root
Option<Vec<String>>, // Src
Expand Down Expand Up @@ -109,17 +109,17 @@ fn interpret_aderyn_config(
}
}

// If config.scope is some, append each value to scope if it is not already present
let mut local_scope = scope.clone();
if let Some(config_scope) = &config.scope {
if let Some(local_scope) = &mut local_scope {
// If config.include is some, append each value to include if it is not already present
let mut local_include = include.clone();
if let Some(config_scope) = &config.include {
if let Some(local_include) = &mut local_include {
for item in config_scope {
if !local_scope.contains(item) {
local_scope.push(item.clone());
if !local_include.contains(item) {
local_include.push(item.clone());
}
}
} else {
local_scope = Some(config_scope.clone());
local_include = Some(config_scope.clone());
}
}

Expand All @@ -128,7 +128,7 @@ fn interpret_aderyn_config(
local_src,
local_exclude,
local_remappings,
local_scope,
local_include,
)
}

Expand Down Expand Up @@ -228,7 +228,7 @@ mod tests {
src: Some("CONFIG_SRC".to_string()),
exclude: Some(vec!["CONFIG_EXCLUDE".to_string()]),
remappings: Some(vec!["CONFIG_REMAPPINGS".to_string()]),
scope: Some(vec!["CONFIG_SCOPE".to_string()]),
include: Some(vec!["CONFIG_SCOPE".to_string()]),
};

let root = std::path::Path::new("ARG_ROOT");
Expand All @@ -241,9 +241,9 @@ mod tests {
"ARG_REMAPPINGS_1".to_string(),
"ARG_REMAPPINGS_2".to_string(),
]);
let scope = Some(vec!["ARG_SCOPE_1".to_string(), "ARG_SCOPE_2".to_string()]);
let include = Some(vec!["ARG_SCOPE_1".to_string(), "ARG_SCOPE_2".to_string()]);
let result =
super::interpret_aderyn_config(config, root, &src, &exclude, &remappings, &scope);
super::interpret_aderyn_config(config, root, &src, &exclude, &remappings, &include);
assert_eq!(result.0, std::path::Path::new("ARG_ROOT/CONFIG_ROOT"));
assert_eq!(
result.1,
Expand Down
24 changes: 12 additions & 12 deletions aderyn_driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct Args {
pub root: String,
pub output: String,
pub src: Option<Vec<String>>,
pub exclude: Option<Vec<String>>,
pub scope: Option<Vec<String>>,
pub path_excludes: Option<Vec<String>>,
pub path_includes: Option<Vec<String>>,
pub no_snippets: bool,
pub skip_build: bool,
pub skip_cloc: bool,
Expand Down Expand Up @@ -109,17 +109,17 @@ fn make_context(args: &Args) -> WorkspaceContextWrapper {
eprintln!("Warning: output file lacks the \".md\" or \".json\" extension in its filename.");
}

let (root_path, src, exclude, remappings, scope) = obtain_config_values(args).unwrap();
let (root_path, src, exclude, remappings, include) = obtain_config_values(args).unwrap();

let absolute_root_path = &ensure_valid_root_path(&root_path);
println!(
"Root: {:?}, Src: {:?}, Scope: {:?}, Exclude: {:?}",
absolute_root_path, src, scope, exclude
"Root: {:?}, Src: {:?}, Include: {:?}, Exclude: {:?}",
absolute_root_path, src, include, exclude
);

let mut contexts: Vec<WorkspaceContext> = {
if args.icf {
process_auto::with_project_root_at(&root_path, &src, &exclude, &remappings, &scope)
process_auto::with_project_root_at(&root_path, &src, &exclude, &remappings, &include)
} else {
if !is_foundry(&PathBuf::from(&args.root)) {
// Exit with a non-zero exit code
Expand All @@ -132,7 +132,7 @@ fn make_context(args: &Args) -> WorkspaceContextWrapper {

vec![process_foundry::with_project_root_at(
&root_path,
&scope,
&include,
&exclude,
args.skip_build,
)]
Expand Down Expand Up @@ -175,9 +175,9 @@ fn obtain_config_values(
let mut root_path = PathBuf::from(&args.root);

let mut local_src = args.src.clone();
let mut local_exclude = args.exclude.clone();
let mut local_exclude = args.path_excludes.clone();
let mut local_remappings = None;
let mut local_scope = args.scope.clone();
let mut local_include = args.path_includes.clone();

let aderyn_path = root_path.join("aderyn.toml");
// Process aderyn.toml if it exists
Expand All @@ -187,13 +187,13 @@ fn obtain_config_values(
local_src,
local_exclude,
local_remappings,
local_scope,
local_include,
) = derive_from_aderyn_toml(
&root_path,
&local_src,
&local_exclude,
&local_remappings,
&local_scope,
&local_include,
);
}

Expand All @@ -209,7 +209,7 @@ fn obtain_config_values(
local_src,
local_exclude,
local_remappings,
local_scope,
local_include,
))
}

Expand Down
4 changes: 2 additions & 2 deletions aderyn_py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fn main() {
no_snippets: false, // TODO support this later
skip_build: false, // TODO support this later
skip_cloc: false, // TODO support this later
scope: None, // TODO support this later
exclude: None, // TODO support this later
path_includes: None, // TODO support this later
path_excludes: None, // TODO support this later
stdout: false, // TODO support this later
skip_update_check: false, // TODO support this later
auditor_mode: false, // TODO support this later
Expand Down
8 changes: 4 additions & 4 deletions cli/icf_reportgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#### MARKDOWN REPORTS ######

# Basic report.md
cargo run -- --scope src/ --exclude lib/ ./tests/contract-playground -o ./reports/report.md --skip-update-check --icf &
cargo run -- -i src/ -x lib/ ./tests/contract-playground -o ./reports/report.md --skip-update-check --icf &

# Adhoc sol files report.md
cargo run -- ./tests/adhoc-sol-files -o ./reports/adhoc-sol-files-report.md --skip-update-check --icf &
Expand All @@ -13,10 +13,10 @@ cargo run -- ./tests/2024-05-Sablier -o ./reports/sablier-aderyn-toml-nested-roo

# nft-report.md (Handle remappings)
cd tests/foundry-nft-f23 && forge install && cd ../.. &&
cargo run -- ./tests/foundry-nft-f23 --scope src/ --exclude lib/ -o ./reports/nft-report.md --skip-update-check --icf &
cargo run -- ./tests/foundry-nft-f23 -i src/ -x lib/ -o ./reports/nft-report.md --skip-update-check --icf &

# ccip-functions-report.md (Handle remappings)
cargo run -- tests/ccip-contracts/contracts --src src/v0.8/functions/ --exclude "tests/,test/,mocks/" -o ./reports/ccip-functions-report.md --icf &
cargo run -- tests/ccip-contracts/contracts --src src/v0.8/functions/ -x "tests/,test/,mocks/" -o ./reports/ccip-functions-report.md --icf &

# Extract src, scope and exclude from foundry profile in case of foundry project
FOUNDRY_PROFILE=uniswap cargo run tests/contract-playground/ -o ./reports/uniswap_profile.md --icf &
Expand All @@ -25,7 +25,7 @@ FOUNDRY_PROFILE=uniswap cargo run tests/contract-playground/ -o ./reports/uniswa
##### JSON REPORTS ########

# Basic report.json
cargo run -- --scope src/ --exclude lib/ -o ./reports/report.json ./tests/contract-playground --skip-update-check --icf &
cargo run -- -i src/ -x lib/ -o ./reports/report.json ./tests/contract-playground --skip-update-check --icf &

##### SARIF REPORTS ########

Expand Down

0 comments on commit 3020207

Please sign in to comment.