Skip to content

Commit

Permalink
fix: make paths a positional argument (#8158)
Browse files Browse the repository at this point in the history
* fix: move paths to BuildArgs

* tests

* dirs -> paths
  • Loading branch information
klkvr committed Jun 17, 2024
1 parent 55ac4e4 commit 35356b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 0 additions & 5 deletions crates/cli/src/opts/build/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ pub struct CoreBuildArgs {
#[serde(skip)]
pub skip: Option<Vec<SkipBuildFilter>>,

/// Build source files from specified paths.
#[arg(long, short, num_args(0..))]
#[serde(skip)]
pub paths: Option<Vec<PathBuf>>,

#[command(flatten)]
#[serde(flatten)]
pub compiler: CompilerArgs,
Expand Down
11 changes: 8 additions & 3 deletions crates/forge/bin/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use foundry_config::{
Config,
};
use serde::Serialize;
use std::path::PathBuf;
use watchexec::config::{InitConfig, RuntimeConfig};

foundry_config::merge_impl_figment_convert!(BuildArgs, args);
Expand Down Expand Up @@ -46,6 +47,10 @@ foundry_config::merge_impl_figment_convert!(BuildArgs, args);
#[derive(Clone, Debug, Default, Serialize, Parser)]
#[command(next_help_heading = "Build options", about = None, long_about = None)] // override doc
pub struct BuildArgs {
/// Build source files from specified paths.
#[serde(skip)]
pub paths: Option<Vec<PathBuf>>,

/// Print compiled contract names.
#[arg(long)]
#[serde(skip)]
Expand Down Expand Up @@ -86,9 +91,9 @@ impl BuildArgs {

// Collect sources to compile if build subdirectories specified.
let mut files = vec![];
if let Some(dirs) = self.args.paths {
for dir in dirs {
files.extend(source_files_iter(dir, MultiCompilerLanguage::FILE_EXTENSIONS));
if let Some(paths) = self.paths {
for path in paths {
files.extend(source_files_iter(path, MultiCompilerLanguage::FILE_EXTENSIONS));
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ function test_bar() external {}

// Build 2 files within test dir
prj.clear();
cmd.args(["build", "--paths", "test", "--force"]);
cmd.args(["build", "test", "--force"]);
cmd.unchecked_output().stdout_matches_path(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/can_build_path_with_two_files.stdout"),
Expand All @@ -1705,7 +1705,7 @@ function test_bar() external {}
// Build one file within src dir
prj.clear();
cmd.forge_fuse();
cmd.args(["build", "--paths", "src", "--force"]);
cmd.args(["build", "src", "--force"]);
cmd.unchecked_output().stdout_matches_path(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/can_build_path_with_one_file.stdout"),
Expand All @@ -1714,7 +1714,7 @@ function test_bar() external {}
// Build 3 files from test and src dirs
prj.clear();
cmd.forge_fuse();
cmd.args(["build", "--paths", "src", "test", "--force"]);
cmd.args(["build", "src", "test", "--force"]);
cmd.unchecked_output().stdout_matches_path(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/can_build_path_with_three_files.stdout"),
Expand All @@ -1723,7 +1723,7 @@ function test_bar() external {}
// Build single test file
prj.clear();
cmd.forge_fuse();
cmd.args(["build", "--paths", "test/Bar.sol", "--force"]);
cmd.args(["build", "test/Bar.sol", "--force"]);
cmd.unchecked_output().stdout_matches_path(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/can_build_path_with_one_file.stdout"),
Expand Down

0 comments on commit 35356b0

Please sign in to comment.