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

Raise warning if path specified in forge build does not match and fallback is triggered #9304

Closed
2 tasks done
dyedm1 opened this issue Nov 12, 2024 · 2 comments · Fixed by #9329
Closed
2 tasks done
Labels
Cmd-forge-build Command: forge build first issue A good way to start contributing T-feature Type: feature
Milestone

Comments

@dyedm1
Copy link
Contributor

dyedm1 commented Nov 12, 2024

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (4817280 2024-11-12T00:20:42.760650000Z)

What command(s) is the bug in?

forge build

Operating System

macOS (Apple Silicon)

Describe the bug

forge build with the ./path/to/contract:contractName syntax appears to behave identically to contractName syntax, compiling the entire project and searching the output for the desired contract name.

e.g.:

  • forge build ./path/to/contract compiles 15 files
  • forge build ./path/to/contract:contractName compiles 132 files
  • forge build contractName also compiles 132 files

Perhaps as a result of the behavior described in the first part of this issue, the ./path/to/contract appears to be ignored entirely, with compilation succeeding even when ./path/to/contract does not contain contractName.


PoC:

A.sol

pragma solidity ^0.8.0; 
contract B {}

C.sol

pragma solidity ^0.8.0; 
contract D {}

Results

  • i. forge build ./A.sol compiles B
  • ii. forge build ./A.sol:B compiles both B and D
  • iii. forge build B compiles both B and D
  • iv. forge build ./A.sol:D succeeds and compiles both B and D

Expected behavior

  • ii. should only compile D if it is in the same file as A or somewhere in the inheritance tree (in other words, the same contracts should be compiled as the i. case)
  • iv. should fail? If ii. is implemented correctly, then D wouldn't be anywhere in the compiler output
@dyedm1 dyedm1 added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Nov 12, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Nov 12, 2024
@grandizzy
Copy link
Collaborator

@dyedm1 thank you for your report. This behavior is not supported (and I don't think can be added either), how forge build [PATHS] works is to build specific paths / files and not contracts

  [PATHS]...
          Build source files from specified paths

as shown here https://book.getfoundry.sh/reference/cli/forge/build
If there's no match then it simply ignores given paths and falls back to regular forge build, hence your results
i. A.sol file exists and can be built
ii. ./A.sol:B file doesn't exist so execution is equivalent to forge build
iii. B file doesn't exist so execution is equivalent to forge build
iv. ./A.sol:D file doesn't exist so execution is equivalent to forge build

@zerosnacks pls comment, thanks!

@zerosnacks
Copy link
Member

I agree, I think the way we should address this would be to raise a warning if the path is missed and a fallback is triggered informing the user that there was no match in their specified path.

@zerosnacks zerosnacks changed the title Building with the ./path/to/contract:contractName syntax triggers compilation of the entire project Raise warning if path specified in forge build does not match and fallback is triggered Nov 13, 2024
@zerosnacks zerosnacks added Cmd-forge-build Command: forge build first issue A good way to start contributing and removed T-needs-triage Type: this issue needs to be labelled labels Nov 13, 2024
@grandizzy grandizzy added T-feature Type: feature and removed T-bug Type: bug labels Nov 14, 2024
@grandizzy grandizzy added this to the v1.0.0 milestone Nov 14, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmd-forge-build Command: forge build first issue A good way to start contributing T-feature Type: feature
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants