diff --git a/crytic_compile/cryticparser/cryticparser.py b/crytic_compile/cryticparser/cryticparser.py index 682cfec5..c96f7a29 100755 --- a/crytic_compile/cryticparser/cryticparser.py +++ b/crytic_compile/cryticparser/cryticparser.py @@ -456,3 +456,11 @@ def _init_foundry(parser: ArgumentParser) -> None: dest="foundry_compile_all", default=DEFAULTS_FLAG_IN_CONFIG["foundry_compile_all"], ) + + group_foundry.add_argument( + "--foundry-no-force", + help="Do not use --force flag for incremental compilation", + action="store_true", + dest="foundry_no_force", + default=DEFAULTS_FLAG_IN_CONFIG["foundry_no_force"], + ) diff --git a/crytic_compile/cryticparser/defaults.py b/crytic_compile/cryticparser/defaults.py index 9635f365..cafc92fc 100755 --- a/crytic_compile/cryticparser/defaults.py +++ b/crytic_compile/cryticparser/defaults.py @@ -46,6 +46,7 @@ "foundry_ignore_compile": False, "foundry_out_directory": "out", "foundry_compile_all": False, + "foundry_no_force": False, "export_dir": "crytic-export", "compile_libraries": None, } diff --git a/crytic_compile/platform/foundry.py b/crytic_compile/platform/foundry.py index 79c418b4..083c3271 100755 --- a/crytic_compile/platform/foundry.py +++ b/crytic_compile/platform/foundry.py @@ -61,6 +61,19 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None: ] compile_all = kwargs.get("foundry_compile_all", False) + no_force = kwargs.get("foundry_no_force", False) + + # When no_force is enabled, we must compile all files (including tests) + # to ensure test changes are detected. Otherwise tests would be skipped + # and test modifications wouldn't trigger recompilation. + # We also clean build-info to prevent multiple compilation units from accumulating. + if no_force: + compile_all = True + build_info_dir = Path(self._target, out_directory, "build-info") + if build_info_dir.exists(): + import shutil + shutil.rmtree(build_info_dir) + LOGGER.info(f"Cleaned {build_info_dir} for fresh build-info generation") if not compile_all: foundry_config = self.config(self._target)