Skip to content
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(dependencies): support pinning of tags / revs when using .gitmodules with foundry.lock #9522

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3bcf1b9
parse submodule status output
yash-atreya Dec 6, 2024
a3a01ec
feat(`forge`): save submodules info on install
yash-atreya Dec 9, 2024
cd075f2
re-checkout to tag/rev after forge update
yash-atreya Dec 9, 2024
917cc13
clippy
yash-atreya Dec 9, 2024
e7fb768
fmt
yash-atreya Dec 9, 2024
8e4b543
fix
yash-atreya Dec 9, 2024
53b362d
fix
yash-atreya Dec 10, 2024
f666e8c
test
yash-atreya Dec 10, 2024
0ea584d
fix
yash-atreya Dec 10, 2024
cf88ef8
override using forge update
yash-atreya Dec 10, 2024
2a55c67
nit
yash-atreya Dec 10, 2024
19194c0
nit
yash-atreya Dec 10, 2024
7f6d026
fix: update only untagged deps
yash-atreya Dec 11, 2024
ed3ccfe
allow overrides
yash-atreya Dec 11, 2024
f893917
clippy
yash-atreya Dec 11, 2024
dd072fd
remove + rename to foundry.lock
yash-atreya Dec 11, 2024
ed14a48
nit
yash-atreya Dec 11, 2024
90d92bb
fix: sync foundry.lock on install
yash-atreya Dec 11, 2024
5640bab
sync foundry lock using forge install
yash-atreya Dec 11, 2024
7d9ce8d
fix: read_and_sync_foundry_lock
yash-atreya Dec 17, 2024
92454f8
fix
yash-atreya Dec 17, 2024
46ce492
fix test
yash-atreya Dec 17, 2024
9ae88d6
fix
yash-atreya Dec 17, 2024
fdb1b32
fix
yash-atreya Dec 17, 2024
00a887c
fix
yash-atreya Dec 17, 2024
ac922fa
Merge branch 'master' into yash/fix-forge-update
yash-atreya Jan 6, 2025
07ce536
Merge branch 'master' into yash/fix-forge-update
yash-atreya Jan 10, 2025
53eed1f
Merge branch 'master' into yash/fix-forge-update
grandizzy Jan 14, 2025
3a7e7eb
Do not run can_sync_foundry_lock test on win (fails on master branch …
grandizzy Jan 14, 2025
b7954c3
Merge branch 'master' into yash/fix-forge-update
yash-atreya Jan 29, 2025
8276b42
feat: introduce `LockFile` type, use it in forge install and forge re…
yash-atreya Jan 29, 2025
2f82d39
fix: account for clean lib/ dir while syncing lockfile
yash-atreya Jan 29, 2025
c4a13fd
fix: integrate lockfile into update
yash-atreya Jan 29, 2025
1859e4d
clippy
yash-atreya Jan 29, 2025
97fba00
fix
yash-atreya Jan 29, 2025
090da39
fix
yash-atreya Jan 29, 2025
7787895
feat(`forge`): introduces a `Lockfile` type (#9781)
yash-atreya Jan 29, 2025
ddf425d
clean up forge update
yash-atreya Jan 29, 2025
1cd019a
Merge branch 'yash/lockfile' into yash/fix-forge-update
yash-atreya Jan 29, 2025
5fb8861
nits
yash-atreya Jan 29, 2025
6fc5850
nit
yash-atreya Jan 30, 2025
a55709c
fix: update branch rev in lockfile and print updates
yash-atreya Jan 30, 2025
c42c915
fix
yash-atreya Jan 30, 2025
9b93c00
clippy
yash-atreya Jan 30, 2025
94b5238
nit
yash-atreya Jan 30, 2025
29d846a
fix
yash-atreya Jan 30, 2025
f25c0da
assert foundry lock in tests
yash-atreya Jan 30, 2025
883d048
nit
yash-atreya Jan 30, 2025
94edb91
refac ExtTester and test uni v4 foundry lock sync
yash-atreya Jan 30, 2025
cb7e434
oz sync test
yash-atreya Jan 30, 2025
8fc72e1
fix: run sync after submodule update on install
yash-atreya Jan 30, 2025
4f91ecc
fix: tag_for_commit should return earliest tag that contains commit +…
yash-atreya Jan 30, 2025
50e4a4a
Merge branch 'master' into yash/fix-forge-update
yash-atreya Jan 30, 2025
4c87a7a
fix: write lockfile after git succeeds
yash-atreya Feb 5, 2025
44e334f
Merge branch 'master' into yash/fix-forge-update
yash-atreya Feb 5, 2025
d8a1e53
feat: account for deps pinned to a branch in .gitmodules while syncing
yash-atreya Feb 10, 2025
311d4bc
fix: SUBMODULE_BRANCH_REGEX
yash-atreya Feb 10, 2025
dc22515
fix: properly parse paths from .gitmodules
yash-atreya Feb 11, 2025
068ae3c
nit
yash-atreya Feb 11, 2025
3ecfcfa
Merge branch 'master' into yash/fix-forge-update
yash-atreya Feb 24, 2025
69ffe4c
clippy
yash-atreya Feb 24, 2025
16604d9
fix tests
yash-atreya Feb 24, 2025
905c5a0
fix test
yash-atreya Feb 24, 2025
e1b1a05
Merge branch 'master' into yash/fix-forge-update
zerosnacks Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: account for clean lib/ dir while syncing lockfile
yash-atreya committed Jan 29, 2025
commit 2f82d39745aa09acc6e83aeb464ef9044d0c3219
14 changes: 11 additions & 3 deletions crates/forge/src/lockfile.rs
Original file line number Diff line number Diff line change
@@ -89,8 +89,17 @@ impl<'a> Lockfile<'a> {
}
Entry::Vacant(e) => {
// Find out if rev has a tag associated with it.
let tag = git.tag_for_commit(rev, &git.root.join(rel_path))?;
let dep_id = if let Some(tag) = tag {
let maybe_tag =
git.tag_for_commit(rev, &git.root.join(rel_path)).or_else(|err| {
// Ignore Err: No such file or directory as it is possible that lib/
// dir cleaned.
if err.to_string().contains("No such file or directory") {
return Ok(None)
}
return Err(err);
})?;

let dep_id = if let Some(tag) = maybe_tag {
DepIdentifier::Tag { name: tag, rev: rev.to_string() }
} else {
DepIdentifier::Rev(rev.to_string())
@@ -132,7 +141,6 @@ impl<'a> Lockfile<'a> {
/// Writes the lockfile to the project root.
pub fn write(&self) -> Result<()> {
foundry_common::fs::write_json_file(&self.lockfile_path, &self.deps)?;

trace!(at= ?self.lockfile_path, "wrote lockfile");

Ok(())
54 changes: 1 addition & 53 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use foundry_test_utils::{
foundry_compilers::PathStyle,
rpc::next_mainnet_etherscan_api_key,
snapbox::IntoData,
util::{pretty_err, read_string, OutputExt},
util::{read_string, OutputExt},
};
use std::{
fs,
@@ -2791,58 +2791,6 @@ Bindings have been generated to [..]
"#]]);
});

// checks missing dependencies are auto installed
forgetest_init!(can_install_missing_deps_test, |prj, cmd| {
prj.clear();

// wipe forge-std
let forge_std_dir = prj.root().join("lib/forge-std");
pretty_err(&forge_std_dir, fs::remove_dir_all(&forge_std_dir));

cmd.arg("test").assert_success().stdout_eq(str![[r#"
Missing dependencies found. Installing now...
[UPDATING_DEPENDENCIES]
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, [AVG_GAS])
[PASS] test_Increment() ([GAS])
Suite result: ok. 2 passed; 0 failed; 0 skipped; [ELAPSED]
Ran 1 test suite [ELAPSED]: 2 tests passed, 0 failed, 0 skipped (2 total tests)
"#]]);
});

// checks missing dependencies are auto installed
forgetest_init!(can_install_missing_deps_build, |prj, cmd| {
prj.clear();

// wipe forge-std
let forge_std_dir = prj.root().join("lib/forge-std");
pretty_err(&forge_std_dir, fs::remove_dir_all(&forge_std_dir));

// Build the project
cmd.arg("build").assert_success().stdout_eq(str![[r#"
Missing dependencies found. Installing now...
[UPDATING_DEPENDENCIES]
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!
"#]]);

// Expect compilation to be skipped as no files have changed
cmd.forge_fuse().arg("build").assert_success().stdout_eq(str![[r#"
No files changed, compilation skipped
"#]]);
});

// checks that extra output works
forgetest_init!(can_build_skip_contracts, |prj, cmd| {
prj.clear();
53 changes: 53 additions & 0 deletions crates/forge/tests/cli/install.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,59 @@ use foundry_config::Config;
use foundry_test_utils::util::{read_string, TestCommand};
use semver::Version;
use std::{fs, path::PathBuf, process::Command, str::FromStr};
use foundry_test_utils::util::pretty_err;

// checks missing dependencies are auto installed
forgetest_init!(can_install_missing_deps_build, |prj, cmd| {
prj.clear();

// wipe forge-std
let forge_std_dir = prj.root().join("lib/forge-std");
pretty_err(&forge_std_dir, fs::remove_dir_all(&forge_std_dir));

// Build the project
cmd.arg("build").assert_success().stdout_eq(str![[r#"
Missing dependencies found. Installing now...
[UPDATING_DEPENDENCIES]
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!
"#]]);

// Expect compilation to be skipped as no files have changed
cmd.forge_fuse().arg("build").assert_success().stdout_eq(str![[r#"
No files changed, compilation skipped
"#]]);
});

// checks missing dependencies are auto installed
forgetest_init!(can_install_missing_deps_test, |prj, cmd| {
prj.clear();

// wipe forge-std
let forge_std_dir = prj.root().join("lib/forge-std");
pretty_err(&forge_std_dir, fs::remove_dir_all(&forge_std_dir));

cmd.arg("test").assert_success().stdout_eq(str![[r#"
Missing dependencies found. Installing now...
[UPDATING_DEPENDENCIES]
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, [AVG_GAS])
[PASS] test_Increment() ([GAS])
Suite result: ok. 2 passed; 0 failed; 0 skipped; [ELAPSED]
Ran 1 test suite [ELAPSED]: 2 tests passed, 0 failed, 0 skipped (2 total tests)
"#]]);
});

// test to check that install/remove works properly
forgetest!(can_install_and_remove, |prj, cmd| {