Skip to content

Commit f0e771f

Browse files
dguidoclaudeelopez
authored
fix: use build_info_path from forge config instead of hardcoding (#638)
* fix: use build_info_path from forge config instead of hardcoding Foundry projects can configure `build_info_path` separately from `out`. For example, Optimism's contracts-bedrock uses: - out: forge-artifacts - build_info_path: artifacts/build-info Previously crytic-compile assumed build-info was always at `{out}/build-info`, which caused compilation failures for projects with custom build_info_path. Changes: - Add build_info_path field to PlatformConfig - Read build_info_path from forge config --json - Use build_info_path when set, fall back to {out}/build-info otherwise - Fetch forge config before compile check (needed for ignore_compile mode) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: avoid calling forge config when using --ignore-compile Address review feedback: calling config() early breaks --ignore-compile because forge may not be available in CI environments without build tools. Changes: - Move config() call back inside the compile branch - Add --foundry-build-info-directory CLI option for users who need custom build-info paths with --ignore-compile - Priority order: CLI override > forge config > default ({out}/build-info) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: use modern type union syntax for build_info_path Replace `Optional[str]` with `str | None` to match the style of other fields in PlatformConfig and fix the missing import error. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Emilio López <2642849+elopez@users.noreply.github.com>
1 parent 9fcfffe commit f0e771f

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

crytic_compile/cryticparser/cryticparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,14 @@ def _init_foundry(parser: ArgumentParser) -> None:
450450
default=DEFAULTS_FLAG_IN_CONFIG["foundry_out_directory"],
451451
)
452452

453+
group_foundry.add_argument(
454+
"--foundry-build-info-directory",
455+
help="Use an alternative build-info directory (useful with --ignore-compile)",
456+
action="store",
457+
dest="foundry_build_info_directory",
458+
default=DEFAULTS_FLAG_IN_CONFIG["foundry_build_info_directory"],
459+
)
460+
453461
group_foundry.add_argument(
454462
"--foundry-compile-all",
455463
help="Don't skip compiling test and script",

crytic_compile/cryticparser/defaults.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"hardhat_artifacts_directory": None,
4545
"foundry_ignore_compile": False,
4646
"foundry_out_directory": None,
47+
"foundry_build_info_directory": None,
4748
"foundry_compile_all": False,
4849
"export_dir": "crytic-export",
4950
"compile_libraries": None,

crytic_compile/platform/abstract_platform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PlatformConfig:
4242
libs_path: list[str] = field(default_factory=lambda: ["lib"])
4343
scripts_path: str = "script"
4444
out_path: str = "out"
45+
build_info_path: str | None = None
4546

4647

4748
class AbstractPlatform(metaclass=abc.ABCMeta):

crytic_compile/platform/foundry.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
4444
4545
Args:
4646
crytic_compile (CryticCompile): CryticCompile object to populate
47-
**kwargs: optional arguments. Used: "foundry_ignore_compile", "foundry_out_directory"
47+
**kwargs: optional arguments. Used: "foundry_ignore_compile", "foundry_out_directory",
48+
"foundry_build_info_directory"
4849
4950
"""
5051

@@ -92,11 +93,14 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
9293
out_directory_config = kwargs.get("foundry_out_directory", None)
9394
out_directory = out_directory_config if out_directory_config else out_directory_detected
9495

95-
build_directory = Path(
96-
self._project_root,
97-
out_directory,
98-
"build-info",
99-
)
96+
# Determine build-info directory: CLI override > forge config > default
97+
build_info_override = kwargs.get("foundry_build_info_directory", None)
98+
if build_info_override:
99+
build_directory = Path(self._project_root, build_info_override)
100+
elif foundry_config and foundry_config.build_info_path:
101+
build_directory = Path(self._project_root, foundry_config.build_info_path)
102+
else:
103+
build_directory = Path(self._project_root, out_directory, "build-info")
100104

101105
hardhat_like_parsing(
102106
crytic_compile, str(self._target), build_directory, str(self._project_root)
@@ -199,6 +203,7 @@ def config(working_dir: str | Path) -> PlatformConfig | None:
199203
result.libs_path = json_config.get("libs")
200204
result.scripts_path = json_config.get("script")
201205
result.out_path = json_config.get("out")
206+
result.build_info_path = json_config.get("build_info_path")
202207

203208
return result
204209

0 commit comments

Comments
 (0)