-
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: remapping contexts #5397
feat: remapping contexts #5397
Conversation
Ethers 2.0.8 is out with the fix. |
Some comments/questions: |
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.
So this seems to work well, and considering this will fix master i'm leaning to merging soon—some comments:
} | ||
impl_figment_convert_basic!(RemappingArgs); | ||
|
||
impl Cmd for RemappingArgs { | ||
type Output = (); | ||
|
||
// TODO: Do people use `forge remappings >> file`? |
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.
How are we planning to test this? Wasn't this what you tweeted the other day?
@@ -83,11 +90,13 @@ impl<'a> RemappingsProvider<'a> { | |||
new_remappings.extend(remappings); | |||
|
|||
// scan all library dirs and autodetect remappings | |||
// todo: if a lib specifies contexts for remappings manually, we need to figure out how to |
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.
do we plan to do this now or later?
.into_iter() | ||
.map(Remapping::from) | ||
.map(|mut r| { | ||
// todo: windows/mac/linux |
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.
😄
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.
cool, this looks less invasive than I expected, and since context is optional, this should work as before
smol nit re deps, otherwise lgtm
Cargo.toml
Outdated
ethers = { version = "2.0.8", default-features = false } | ||
ethers-addressbook = { version = "2.0.8", default-features = false } | ||
ethers-core = { version = "2.0.8", default-features = false } | ||
ethers-contract = { version = "2.0.8", default-features = false } | ||
ethers-contract-abigen = { version = "2.0.8", default-features = false } | ||
ethers-providers = { version = "2.0.8", default-features = false } | ||
ethers-signers = { version = "2.0.8", default-features = false } | ||
ethers-middleware = { version = "2.0.8", default-features = false } | ||
ethers-etherscan = { version = "2.0.8", default-features = false } | ||
ethers-solc = { version = "2.0.8", default-features = false } |
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.
now this is on ethers master, we should continue using git deps
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.
fixed in d92bd23 — we can switch to master deps whenever we plan on publishing crates 😄
} | ||
impl_figment_convert_basic!(RemappingArgs); | ||
|
||
impl Cmd for RemappingArgs { | ||
type Output = (); | ||
|
||
// TODO: Do people use `forge remappings >> file`? |
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.
they definitely do,
I also used this a few times at least
match mappings.entry(key) { | ||
/// grouped by remapping context | ||
fn insert_closest( | ||
mappings: &mut HashMap<Option<String>, HashMap<String, 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.
I think this should work,
so the previous hashmap is now just the None
key
and this also supports remappings with context extracted from nested deps
Motivation
Dependencies in projects using Foundry can mess with how imports are resolved through the project because remappings from dependencies are just merged with remappings defined in the root folder.
To solve this, we make use of solc's remapping contexts.
Solution
This PR adds support for specifying remapping contexts if necessary, but ideally it should never be. Instead, this PR also automatically scopes each remapping defined in dependencies to files in the dependency itself.
Global remappings (
context: None
) are still automatically generated for each installed dependency, making it possible to import them as usual.This PR in other words just makes the following user-facing change: remappings defined in dependencies/libraries can no longer override remappings defined in
foundry.toml
/remappings.txt
, and it should no longer be necessary to copy over remappings from dependencies tofoundry.toml
/remappings.txt
for dependencies with weird remappings.This PR also adds a
--pretty
flag toforge remappings
that groups remappings by context. Global remappings apply to every file (including dependencies), and remappings with a context only apply to the paths defined by the context. The default is to not pretty print since a common use case offorge remappings
is to pipe the output to a file or other command.Todo
Closes #3440, closes #1855
Depends on gakonst/ethers-rs#2509