-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(build): add option to build specific dir #8149
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iirc a lot of folks are also requesting this, and this actually looks simple to add. because this is opt-in I belive this is fine
ptal @klkvr
crates/forge/bin/cmd/build.rs
Outdated
let mut files = vec![]; | ||
if let Some(dirs) = self.args.dirs { | ||
for dir in dirs { | ||
for entry in fs::read_dir(dir)? { | ||
let entry = entry?; | ||
let path = entry.path(); | ||
if path.is_file() { | ||
files.push(entry.path()); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there should be utils to find the sol/vy files in a dir @klkvr ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, similarly to this
foundry/crates/forge/bin/cmd/test/mod.rs
Lines 219 to 222 in b7dcf46
test_sources.extend(source_files_iter( | |
project.paths.sources, | |
MultiCompilerLanguage::FILE_EXTENSIONS, | |
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, changed it in 6da9a55
crates/cli/src/opts/build/core.rs
Outdated
/// Child directories are not accounted and should be explicitly added. | ||
#[arg(long, num_args(1..))] | ||
#[serde(skip)] | ||
pub dirs: Option<Vec<PathBuf>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also support individual files?
maybe we do files:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, since now it supports single files I renamed it to paths
Can't we just pass these as a list of 0.. positional arguments? |
perhaps we also want a config key for this? similar to |
- use source_files_iter helper, build single files and child dirs as well - rename arg to paths, use 0.. pos arg
hope I get this comment right, pls check 6da9a55#diff-f3c6bdb4ebdb62f63412254e4c9154aff947fc45daf6aaff880aaf6470182d8aR129-R132 |
I think that would be cool, a difference from skip is that the arg is named LE: on a 2nd thought, since this cannot be shared with other commands and kind of valid only in build context, do we want to move it as a config key? |
This wouldn't require a change in compilers, should be doable by only using sparse output filters
yeah I meant making it valid in all context if specified in config. Since #8061 we respect foundry/crates/config/src/lib.rs Lines 811 to 813 in b7dcf46
|
I think I got it now, but wouldn't this be an issue with the sparse output filter when we want to include files (instead excluding them? |
Right, the way sparse output works is that it only requests artifacts for matched sources, excluding everything else. Such approach reduces compile time but might be a bit unexpected if people are expecting artifacts for imported sources to also be produced. However another issue is if we approach this by just using sparse output filters then this wouldn't give users a way to compile files which are not under Let's keep the config option for a future follow-up |
crates/forge/bin/cmd/build.rs
Outdated
@@ -18,6 +18,9 @@ use watchexec::config::{InitConfig, RuntimeConfig}; | |||
|
|||
foundry_config::merge_impl_figment_convert!(BuildArgs, args); | |||
|
|||
// Extensions accepted by `forge build` | |||
const BUILD_EXTENSIONS: &[&str] = &["sol", "yul", "vy", "vyi"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use MultiCompilerLanguage::FILE_EXTENSIONS
here? It would require including Language
trait from compilers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, changed in 0e71ca5
@grandizzy sorry missed this, I think Dani meant changing it to positional args to allow |
Ah, I see, thank you for following up! |
Motivation
Closes #8071
Not too familiar with build but at a quick look seemed to be a low hanging fruit with big impact for other tools integration, so here it is, hope it makes sense 😄
--paths
switch toforge build
e.g.--skip
as wellSolution