Skip to content

Commit

Permalink
make src single
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy committed Mar 10, 2025
1 parent 9a67522 commit 5a6d055
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 43 deletions.
2 changes: 1 addition & 1 deletion aderyn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct CommandLineArgs {
///
/// --src=contracts/
#[clap(short, long, use_value_delimiter = true)]
src: Option<Vec<String>>,
src: Option<String>,

/// List of path strings to include, delimited by comma (no spaces).
///
Expand Down
38 changes: 17 additions & 21 deletions aderyn_driver/src/config_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ fn clear_empty_vectors<T>(vec: &mut Option<Vec<T>>) {
#[allow(clippy::type_complexity)]
pub fn derive_from_aderyn_toml(
root: &Path,
src: &Option<Vec<String>>,
src: &Option<String>,
exclude: &Option<Vec<String>>,
remappings: &Option<Vec<String>>,
include: &Option<Vec<String>>,
) -> (
PathBuf, // Root
Option<Vec<String>>, // Src
Option<String>, // Src
Option<Vec<String>>, // Exclude
Option<Vec<String>>, // Remappings
Option<Vec<String>>, // Scope
Expand All @@ -84,13 +84,13 @@ pub fn derive_from_aderyn_toml(
fn interpret_aderyn_config(
config: AderynConfig,
root: &Path,
src: &Option<Vec<String>>,
src: &Option<String>,
exclude: &Option<Vec<String>>,
remappings: &Option<Vec<String>>,
include: &Option<Vec<String>>,
) -> (
PathBuf, // Root
Option<Vec<String>>, // Src
Option<String>, // Src
Option<Vec<String>>, // Exclude
Option<Vec<String>>, // Remappings
Option<Vec<String>>, // Scope
Expand All @@ -101,15 +101,11 @@ fn interpret_aderyn_config(
local_root.push(config_root);
}

// If config.src is some, append src if it is not already present
let mut local_src: Option<Vec<String>> = src.clone();
// If config.src is some, command line arg src overrides config.src
let mut local_src: Option<String> = src.clone();
if let Some(config_src) = &config.src {
if let Some(local_src) = &mut local_src {
if !local_src.contains(config_src) {
local_src.push(config_src.clone());
}
} else {
local_src = Some(vec![config_src.clone()]);
if local_src.is_none() {
local_src = Some(config_src.clone());
}
}

Expand Down Expand Up @@ -164,11 +160,11 @@ fn interpret_aderyn_config(
#[allow(clippy::type_complexity)]
pub fn append_from_foundry_toml(
root: &Path,
src: &Option<Vec<String>>,
src: &Option<String>,
exclude: &Option<Vec<String>>,
remappings: &Option<Vec<String>>,
) -> (
Option<Vec<String>>, // Src
Option<String>, // Src
Option<Vec<String>>, // Exclude
Option<Vec<String>>, // Remappings
) {
Expand All @@ -179,11 +175,11 @@ pub fn append_from_foundry_toml(
#[allow(clippy::type_complexity)]
fn interpret_foundry_config(
config: Config,
src: &Option<Vec<String>>,
src: &Option<String>,
exclude: &Option<Vec<String>>,
remappings: &Option<Vec<String>>,
) -> (
Option<Vec<String>>, // Src
Option<String>, // Src
Option<Vec<String>>, // Exclude
Option<Vec<String>>, // Remappings
) {
Expand All @@ -193,7 +189,7 @@ fn interpret_foundry_config(
match local_src {
Some(_) => (),
None => {
local_src = Some(vec![config.src.to_string_lossy().to_string()]);
local_src = Some(config.src.to_string_lossy().to_string());
}
}

Expand Down Expand Up @@ -251,7 +247,7 @@ mod tests {
};

let root = std::path::Path::new("ARG_ROOT");
let src = Some(vec!["ARG_SRC".to_string()]);
let src = Some("ARG_SRC".to_string());
let exclude = Some(vec!["ARG_EXCLUDE_1".to_string(), "ARG_EXCLUDE_2".to_string()]);
let remappings = Some(vec!["ARG_REMAPPINGS_1".to_string(), "ARG_REMAPPINGS_2".to_string()]);
let include = Some(vec!["ARG_SCOPE_1".to_string(), "ARG_SCOPE_2".to_string()]);
Expand All @@ -260,7 +256,7 @@ mod tests {
let result =
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, Some(vec!["ARG_SRC".to_string(), "CONFIG_SRC".to_string()]));
assert_eq!(result.1, Some("ARG_SRC".to_string()));
assert_eq!(
result.2,
Some(vec![
Expand Down Expand Up @@ -305,14 +301,14 @@ mod tests {
};
config.remappings = vec![rel_remap];

let src = Some(vec!["ADERYN_SRC".to_string()]);
let src = Some("ADERYN_SRC".to_string());
let exclude: Option<Vec<String>> =
Some(vec!["ADERYN_EXCLUDE_1".to_string(), "ADERYN_EXCLUDE_2".to_string()]);
let remappings =
Some(vec!["ADERYN_REMAPPINGS_1".to_string(), "ADERYN_REMAPPINGS_2".to_string()]);

let result = super::interpret_foundry_config(config, &src, &exclude, &remappings);
assert_eq!(result.0, Some(vec!["ADERYN_SRC".to_string()]));
assert_eq!(result.0, Some("ADERYN_SRC".to_string()));
assert_eq!(
result.1,
Some(vec![
Expand Down
6 changes: 3 additions & 3 deletions aderyn_driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tokio::sync::Mutex;
pub struct Args {
pub root: String,
pub output: String,
pub src: Option<Vec<String>>,
pub src: Option<String>,
pub path_excludes: Option<Vec<String>>,
pub path_includes: Option<Vec<String>>,
pub no_snippets: bool,
Expand Down Expand Up @@ -218,7 +218,7 @@ fn make_context(args: &Args) -> WorkspaceContextWrapper {
fn obtain_config_values(
args: &Args,
) -> Result<
(PathBuf, Option<Vec<String>>, Option<Vec<String>>, Option<Vec<String>>, Option<Vec<String>>),
(PathBuf, Option<String>, Option<Vec<String>>, Option<Vec<String>>, Option<Vec<String>>),
Box<dyn Error>,
> {
let mut root_path = PathBuf::from(&args.root);
Expand Down Expand Up @@ -255,7 +255,7 @@ fn obtain_config_values(
if local_src.is_none()
&& (hardhat_config_js_path.exists() || hardhat_config_ts_path.exists())
{
local_src = Some(vec![String::from("contracts")])
local_src = Some(String::from("contracts"));
}

// Also if there is no `remappings.txt` or `remappings` in this case, print a warning!
Expand Down
4 changes: 2 additions & 2 deletions aderyn_driver/src/foundry_compiler_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn get_project(root: &Path, remappings: Vec<Remapping>) -> Project {
pub fn get_relevant_sources(
root: &Path,
solidity_files: CompilerInput,
src: &Option<Vec<PathBuf>>,
src: &Option<PathBuf>,
scope: &Option<Vec<String>>,
exclude: &Option<Vec<String>>,
) -> BTreeMap<PathBuf, Source> {
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn get_relevant_sources(
pub fn get_relevant_pathbufs(
root: &Path,
pathbufs: &[PathBuf],
src: &Option<Vec<PathBuf>>,
src: &Option<PathBuf>,
scope: &Option<Vec<String>>,
exclude: &Option<Vec<String>>,
) -> Vec<PathBuf> {
Expand Down
6 changes: 3 additions & 3 deletions aderyn_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ fn ensure_valid_root_path(root_path: &Path) -> PathBuf {
utils::canonicalize(root_path).unwrap()
}

fn passes_src(src: &Option<Vec<PathBuf>>, solidity_file: &Path) -> bool {
if let Some(sources) = src {
return sources.iter().any(|s| solidity_file.starts_with(s));
fn passes_src(src: &Option<PathBuf>, solidity_file: &Path) -> bool {
if let Some(source) = src {
return solidity_file.starts_with(source);
}
true
}
Expand Down
13 changes: 4 additions & 9 deletions aderyn_driver/src/process_auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@ use crate::ensure_valid_root_path;

pub fn with_project_root_at(
root_path: &Path,
src: &Option<Vec<String>>,
src: &Option<String>,
exclude: &Option<Vec<String>>,
remappings: &Option<Vec<String>>,
scope: &Option<Vec<String>>,
lsp_mode: bool,
) -> Vec<WorkspaceContext> {
let root = utils::canonicalize(root_path).unwrap();
let src = src.clone().map(|sources| {
sources
.into_iter()
.map(|source| utils::canonicalize(root.join(source)).unwrap())
.collect::<Vec<_>>()
});
let src = src.clone().map(|source| utils::canonicalize(root.join(source)).unwrap());

let solidity_files = get_compiler_input(&root);
let sources = get_relevant_sources(&root, solidity_files, &src, scope, exclude);
Expand Down Expand Up @@ -107,7 +102,7 @@ pub fn with_project_root_at(

fn create_workspace_context_from_stdout(
stdout: String,
src: &Option<Vec<PathBuf>>,
src: &Option<PathBuf>,
scope: &Option<Vec<String>>,
exclude: &Option<Vec<String>>,
root_path: &Path,
Expand Down Expand Up @@ -181,7 +176,7 @@ fn is_demarcation_line(
scope: &Option<Vec<String>>,
exclude: &Option<Vec<String>>,
root_path: &Path,
src: &Option<Vec<PathBuf>>,
src: &Option<PathBuf>,
absolute_root_path_str: &str,
) -> (bool, Option<String>) {
if line.starts_with("======= ") {
Expand Down
8 changes: 4 additions & 4 deletions aderyn_driver/src/project_compiler_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod project_compiler_grouping_tests {
#[test]
fn foundry_nft_f23() {
let project_root_str = "../tests/foundry-nft-f23";
let src = &Some(vec![PathBuf::from_str("src/").unwrap()]);
let src = &Some(PathBuf::from_str("src/").unwrap());
test_grouping_files_to_compile(project_root_str, src, &None, &None);
}

Expand All @@ -25,20 +25,20 @@ mod project_compiler_grouping_tests {
#[test]
fn contract_playground() {
let project_root_str = "../tests/contract-playground";
let src = &Some(vec![PathBuf::from_str("src/").unwrap()]);
let src = &Some(PathBuf::from_str("src/").unwrap());
test_grouping_files_to_compile(project_root_str, src, &None, &None);
}

#[test]
fn ccip_develop() {
let project_root_str = "../tests/ccip-contracts/contracts";
let src = &Some(vec![PathBuf::from_str("src/v0.8/").unwrap()]);
let src = &Some(PathBuf::from_str("src/v0.8/").unwrap());
test_grouping_files_to_compile(project_root_str, src, &None, &None);
}

fn test_grouping_files_to_compile(
project_root_str: &str,
src: &Option<Vec<PathBuf>>,
src: &Option<PathBuf>,
scope: &Option<Vec<String>>,
exclude: &Option<Vec<String>>,
) {
Expand Down

0 comments on commit 5a6d055

Please sign in to comment.