From e11162456eac0d79b5a7fd24de52b8ba0209b958 Mon Sep 17 00:00:00 2001 From: Palina Tolmach Date: Mon, 23 Sep 2024 15:00:04 +0800 Subject: [PATCH] Use `build_info_path` in `load_build_info`, update TOML parsing logic (#825) * WIP: use `build_info_path` in `load_build_info` * toml: use `default` profile values for keys absent from the current profile * Formatting * Add default value for `build_info_path` (`out/build-info`) --- src/kontrol/__main__.py | 2 +- src/kontrol/foundry.py | 17 +++++++++++++++-- src/kontrol/solc.py | 4 ++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/kontrol/__main__.py b/src/kontrol/__main__.py index 8eb5dd23c..8aff9d67f 100644 --- a/src/kontrol/__main__.py +++ b/src/kontrol/__main__.py @@ -312,7 +312,7 @@ def exec_view_kcfg(options: ViewKcfgOptions) -> None: contract_name, _ = test_id.split('.') proof = foundry.get_apr_proof(test_id) - compilation_unit = CompilationUnit.load_build_info(options.foundry_root) + compilation_unit = CompilationUnit.load_build_info(foundry.build_info) def _short_info(cterm: CTerm) -> Iterable[str]: return foundry.short_info_for_contract(contract_name, cterm) diff --git a/src/kontrol/foundry.py b/src/kontrol/foundry.py index 84c56871a..1dbb4f92f 100644 --- a/src/kontrol/foundry.py +++ b/src/kontrol/foundry.py @@ -182,7 +182,11 @@ def lookup_full_contract_name(self, contract_name: str) -> str: @property def profile(self) -> dict[str, Any]: profile_name = os.getenv('FOUNDRY_PROFILE', default='default') - return self._toml['profile'][profile_name] + + current_profile = self._toml['profile'].get(profile_name, {}) + default_profile = self._toml['profile'].get('default', {}) + + return {**default_profile, **current_profile} @property def out(self) -> Path: @@ -212,6 +216,15 @@ def main_file(self) -> Path: def contracts_file(self) -> Path: return self.kompiled / 'contracts.k' + @property + def build_info(self) -> Path: + build_info_path = self.profile.get('build_info_path') + + if build_info_path: + return self._root / build_info_path + else: + return self.out / 'build-info' + @cached_property def kevm(self) -> KEVM: use_directory = self.out / 'tmp' @@ -1364,7 +1377,7 @@ def __init__(self, foundry: Foundry, contract_name: str, omit_unstable_output: b self.foundry = foundry self.contract_name = contract_name self.omit_unstable_output = omit_unstable_output - self.compilation_unit = CompilationUnit.load_build_info(foundry._root) + self.compilation_unit = CompilationUnit.load_build_info(foundry.build_info) def print_node(self, kcfg: KCFG, node: KCFG.Node) -> list[str]: ret_strs = super().print_node(kcfg, node) diff --git a/src/kontrol/solc.py b/src/kontrol/solc.py index a13f5626b..d8e9f9559 100644 --- a/src/kontrol/solc.py +++ b/src/kontrol/solc.py @@ -495,8 +495,8 @@ def uuid(self) -> int: return self._id @staticmethod - def load_build_info(foundry_root: Path) -> CompilationUnit: - build_info_files = (foundry_root / 'out' / 'build-info').glob('*.json') + def load_build_info(foundry_build_info: Path) -> CompilationUnit: + build_info_files = foundry_build_info.glob('*.json') build_info = json.loads(max(build_info_files, key=os.path.getmtime).read_text()) sources: dict[int, Source] = {} # Source id => Source contracts: dict[bytes, ContractSource] = {} # CBOR metadata => contract