Sitelet https://github.com/foundry-rs/compilers/pull/49
Skip to content
This repository was archived by the owner on Apr 20, 2026. It is now read-only.

Fix inconsistent trailing slash in remappings - #49

Merged
DaniPopes merged 5 commits into
foundry-rs:mainfrom
Troublor:issue47
Jul 6, 2024
Merged

DaniPopes merged 5 commits into
foundry-rs:mainfrom
Troublor:issue47

Conversation

@Troublor

@Troublor Troublor commented Jan 21, 2024 •

Copy link
Copy Markdown
Contributor

Fix #47. One corresponding test is added.

Fix strategy

  • Remove the code that blindly add trailing / when serializing Remapping and RelativeRemapping.
  • Preserve the trailing / in the strip_prefix method of Remapping.

Rationale

There are roughly two sources where Remapping comes from:

  • Generated in find_many function.
  • Loaded from configuration like foundry.toml.

When generating Remapping in find_many function, the algorithm makes sure that the name and path of every remapping are valid folders in the file system. Then, trailing /s are added to both name and path in the impl From<RelativeRemapping> for Remapping implementation.
https://github.com/Troublor/compilers/blob/93c5f46a7dd0c0d387dd94c8ea756812e2907d92/src/remappings.rs#L360-L365

When loading Remapping from user-provided configurations, the name and path of remappings should be set as it is, and do not add any trailing /s.

Either way, the field name and path of Remapping contains intended values and should not be changed in the serialization (the implementation for Display trait).

PS: About coding style, I tried to use TempProject to write the test case but it seems the project.compile() method does not respect the remapping I give it via project.with_settings(settings_with_remapping). The remapping just does not take effect in the compilation. Not sure whether it's I don't know how to use it or TempProject has some bugs.

@Troublor
Troublor marked this pull request as draft January 21, 2024 05:08
@BlazeWasHere

Copy link
Copy Markdown

gm @Troublor are you still working on this?

@Troublor

Copy link
Copy Markdown
Contributor Author

@BlazeWasHere Yeah you remind me. I will finish it this weekend.

@Troublor
Troublor marked this pull request as ready for review March 31, 2024 02:37
@DaniPopes
DaniPopes requested review from klkvr and mattsse April 2, 2024 15:20

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry forgot about this,

could you please open a foundry pr that patches the foundry-compilers crate to this branch to check if this causes any issues

@BlazeWasHere

BlazeWasHere commented Apr 10, 2024 •

Copy link
Copy Markdown

ah im not approved for github workflow actions, but locally it doesnt seem to build not sure its because of my system (new pc -- have never used rust on this before) or rust crate incompatibility

edit: it seems like this branch is just missing latest commits from main

@Troublor

Copy link
Copy Markdown
Contributor Author

The test cases of foundry-rs/compilers (in the CI) seem to indicate there are some problems with Windows. I don't have a Windows machine. Could someone offer some help to look into the issues?

Comment thread src/remappings.rs Outdated
Comment thread src/remappings.rs Outdated
Comment thread src/remappings.rs Outdated
Comment thread src/remappings.rs Outdated
@DaniPopes
DaniPopes requested a review from mattsse April 11, 2024 18:38
Comment thread src/remappings.rs Outdated

@DaniPopes DaniPopes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, pending @mattsse

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm,

really sorry about the delay

@mattsse

mattsse commented Apr 13, 2024

Copy link
Copy Markdown
Member

hmm this results in a bunch of failing tests

foundry-rs/foundry#7623

can't proceed with this until sorted out

@BlazeWasHere

BlazeWasHere commented Apr 13, 2024 •

Copy link
Copy Markdown

hmm this results in a bunch of failing tests

foundry-rs/foundry#7623

can't proceed with this until sorted out

i havent updated my fork yet, can you retrigger ci again now

edit:

https://github.com/foundry-rs/foundry/actions/runs/8672405018/job/23783250651?pr=7623#step:12:316
windows (the bane of oss dev) has missing trailing /

gnu/linux ditto. 😢
https://github.com/foundry-rs/foundry/actions/runs/8672405018/job/23783250255?pr=7623#step:12:153

https://github.com/foundry-rs/foundry/blob/89f0fb923773cf0f8f966290e579bae92f505077/crates/forge/tests/cli/config.rs#L233
seems to fail because of

compilers/src/remappings.rs

Lines 364 to 376 in 66d2677

impl From<RelativeRemapping> for Remapping {
fn from(r: RelativeRemapping) -> Self {
let RelativeRemapping { context, mut name, path } = r;
let mut path = format!("{}", path.relative().display());
if !path.ends_with('/') {
path.push('/');
}
if !name.ends_with('/') {
name.push('/');
}
Remapping { context, name, path }
}
}

@klkvr

klkvr commented Jun 30, 2024 •

Copy link
Copy Markdown
Member

hey @Troublor do you have plans for finishing this?

considering that CI fails I am thinking that perhaps we should take a different approach? currently in remappings.txt of a foundry project you can specify remappings in any format: any of project=src, project=src/, project/=src, etc would get updated to project/=src/ because it's the way conversion RelativeRemapping -> Remapping works:

if !path.ends_with('/') {
path.push('/');
}
if !name.ends_with('/') {
name.push('/');
}

however, when working with i.e. etherscan projects or any sources of remappings requiring deserialization directly into Remapping we don't go through that conversion and validation and name and path are kept as-is.

Thus, I think we can either just update Display impl for Remapping to also push / to name if it's not present (currently we are only pushing it to path):

if !s.ends_with('/') {
s.push('/');
}

Also, we can consider adding this additional logic to serde::Serialize impl which should also work

@Troublor

Troublor commented Jul 5, 2024 •

Copy link
Copy Markdown
Contributor Author

@klkvr Thanks. I restructured the patch. Please approve the CI tests.

@Troublor

Troublor commented Jul 5, 2024

Copy link
Copy Markdown
Contributor Author

@klkvr I fixed some regression test oracles. Please trigger CI again. Thx.

@Troublor

Troublor commented Jul 5, 2024 •

Copy link
Copy Markdown
Contributor Author

@klkvr There seems to be some race: the last commit (just some refactoring) is not included in the CI. But the previous CI passes, so everything should look good now. Thanks for your efforts.

@klkvr

klkvr commented Jul 5, 2024

Copy link
Copy Markdown
Member

@Troublor mind updating patch in foundry-rs/foundry#7623? (or creating a new PR if you don't have access to that branch)

@Troublor

Troublor commented Jul 6, 2024 •

Copy link
Copy Markdown
Contributor Author

@klkvr It seems @BlazeWasHere has already updated that PR.

@Troublor

Troublor commented Jul 6, 2024 •

Copy link
Copy Markdown
Contributor Author

@klkvr I created another PR to test on foundry: foundry-rs/foundry#8377

Foundry would need a little patch as well for one integration test: can_extract_config_values: The expected value of remapping name should have a trailing slash.

Other than this, all tests pass and everything looks good.

@klkvr

klkvr commented Jul 6, 2024

Copy link
Copy Markdown
Member

@Troublor nice! does this solve the initial issue you had in #47 with compiling contract from Etherscan? If so, I think this is good to merge

@ZhangZhuoSJTU

Copy link
Copy Markdown
Contributor

@Troublor nice! does this solve the initial issue you had in #47 with compiling contract from Etherscan? If so, I think this is good to merge

I think the original issue is solved after this patch.

@DaniPopes
DaniPopes merged commit 56911f2 into foundry-rs:main Jul 6, 2024
@Troublor

Troublor commented Jul 6, 2024

Copy link
Copy Markdown
Contributor Author

@klkvr Yes, problem solved. Thx.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent tailing slash in remapping name and path

6 participants