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

fix: use target to get config, drop toml for json #515

Merged
merged 9 commits into from
Jan 16, 2024
Merged

Conversation

0xalpharush
Copy link
Contributor

@0xalpharush 0xalpharush commented Nov 7, 2023

Fix #509
Replaces #510

@0xalpharush 0xalpharush marked this pull request as ready for review November 7, 2023 04:45
Copy link
Member

@elopez elopez left a comment

Choose a reason for hiding this comment

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

Nice work! 🎉 I left a few comments inline.

crytic_compile/platform/foundry.py Outdated Show resolved Hide resolved
.strip()
LOGGER.info("'forge config --json' running")
json_config = json.loads(
subprocess.run(["forge", "config", "--json"], stdout=subprocess.PIPE, check=True).stdout
Copy link
Member

Choose a reason for hiding this comment

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

This should run with cwd=target or something like that, right? Otherwise you may get the foundry config from the current directory, which may not work or may not correspond to your target. If target can be a file, then you may need to preprocess it a bit:

target = target if os.path.isdir(target) else os.path.dirname(target)
subprocess.run(..., cwd=target)

Copy link
Member

Choose a reason for hiding this comment

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

On a second look, I think target is always a directory here, so scratch that last part of my comment.

Unrelated to this PR, but I think the check here may be a bit off, wouldn't it make more sense to look for the foundry/etc project in the path of the file rather than in cwd? e.g. if the file is /a/b/c/d/contracts/foo.sol, I'd check to see if any of [/a/b/c/d/contracts, /a/b/c/d, /a/b/c, /a/b, /a, /] is a project. Most users are probably going to be running the tool with cwd=the project folder, so it may work as-is now, but it doesn't feel completely correct.

crytic_compile/platform/foundry.py Outdated Show resolved Hide resolved
@0xalpharush 0xalpharush added this pull request to the merge queue Jan 16, 2024
Merged via the queue into dev with commit ad6dedc Jan 16, 2024
52 checks passed
@0xalpharush 0xalpharush deleted the fix/config-path branch January 16, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants