foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Forge: duplicate filename artifact location collisions

Open adraffy opened this issue 9 months ago • 2 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (d431f74 2024-04-27T00:17:17.280985407Z)

What command(s) is the bug in?

forge build

Operating System

Linux

Describe the bug

I have two directories with a contract with the same name

  • src/A/C.sol
  • src/B/C.sol

Example scenario: developing a /v2/ rewrite of a /v1/ solution.

  1. forge build --force
    • out/A/C.sol/C.json
    • out/B/C.sol/C.json
  2. modify A/C.solforge build
    • out/C.sol/C.json ← corresponds to A
  3. modify B/C.solforge build
    • out/C.sol/C.json ← now corresponds to B

Incremental builds should either rely on the cached artifact layout, or the artifacts should all be nested inside some fully-expanded hashed layout, like out/${hash(absolute path)}/{file}.sol/{name}.json.

solidity-files-cache.json reflects change (2) but becomes bugged after (3) as there are now 2 cached artifacts with the same path but different sources.

IMO, these file locations should be somewhat predictable. The current solution of creating minimal directories when duplicates exist is weird.

adraffy avatar Apr 27 '24 04:04 adraffy

@klkvr I assume this is an edge case we're missing during caching preprocess

mattsse avatar Apr 27 '24 05:04 mattsse

Not sure how closely related but a similar issue exists for duplicates when multiple compiler versions are used https://github.com/gakonst/ethers-rs/issues/1995

0xalpharush avatar Apr 29 '24 00:04 0xalpharush