Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crytic_compile/cryticparser/cryticparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,11 @@ def _init_foundry(parser: ArgumentParser) -> None:
dest="foundry_compile_all",
default=DEFAULTS_FLAG_IN_CONFIG["foundry_compile_all"],
)

group_foundry.add_argument(
"--foundry-deny",
help="Forge diagnostic level to deny (never, warn, all). Auto-detected for Foundry 1.4+",
action="store",
dest="foundry_deny",
default=DEFAULTS_FLAG_IN_CONFIG["foundry_deny"],
)
1 change: 1 addition & 0 deletions crytic_compile/cryticparser/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"foundry_out_directory": None,
"foundry_build_info_directory": None,
"foundry_compile_all": False,
"foundry_deny": None,
"export_dir": "crytic-export",
"compile_libraries": None,
}
34 changes: 33 additions & 1 deletion crytic_compile/platform/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import logging
import re
import subprocess
from pathlib import Path
from typing import TYPE_CHECKING, TypeVar
Expand All @@ -22,6 +23,28 @@
LOGGER = logging.getLogger("CryticCompile")


def _get_forge_version() -> tuple[int, int, int] | None:
"""Get forge version as tuple, or None if unable to parse.

Returns:
Version tuple (major, minor, patch) or None if detection fails.
"""
try:
result = subprocess.run(
["forge", "--version"],
capture_output=True,
text=True,
timeout=10,
)
versions = re.findall(r"\d+\.\d+\.\d+", result.stdout)
if versions:
parts = versions[0].split(".")
return (int(parts[0]), int(parts[1]), int(parts[2]))
except Exception: # noqa: BLE001
pass
return None


class Foundry(AbstractPlatform):
"""
Foundry platform
Expand All @@ -45,7 +68,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
Args:
crytic_compile (CryticCompile): CryticCompile object to populate
**kwargs: optional arguments. Used: "foundry_ignore_compile", "foundry_out_directory",
"foundry_build_info_directory"
"foundry_build_info_directory", "foundry_deny"

"""

Expand All @@ -60,12 +83,21 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
"--ignore-compile used, if something goes wrong, consider removing the ignore compile flag"
)
else:
deny_level = kwargs.get("foundry_deny")
if deny_level is None:
forge_version = _get_forge_version()
if forge_version and forge_version >= (1, 4, 0):
deny_level = "never"

compilation_command = [
"forge",
"build",
"--build-info",
]

if deny_level:
compilation_command.extend(["--deny", deny_level])

targeted_build = not self._project_root.samefile(self._target)
if targeted_build:
compilation_command += [
Expand Down