Skip to content

Commit e111624

Browse files
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`)
1 parent c38bddc commit e111624

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/kontrol/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def exec_view_kcfg(options: ViewKcfgOptions) -> None:
312312
contract_name, _ = test_id.split('.')
313313
proof = foundry.get_apr_proof(test_id)
314314

315-
compilation_unit = CompilationUnit.load_build_info(options.foundry_root)
315+
compilation_unit = CompilationUnit.load_build_info(foundry.build_info)
316316

317317
def _short_info(cterm: CTerm) -> Iterable[str]:
318318
return foundry.short_info_for_contract(contract_name, cterm)

src/kontrol/foundry.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ def lookup_full_contract_name(self, contract_name: str) -> str:
182182
@property
183183
def profile(self) -> dict[str, Any]:
184184
profile_name = os.getenv('FOUNDRY_PROFILE', default='default')
185-
return self._toml['profile'][profile_name]
185+
186+
current_profile = self._toml['profile'].get(profile_name, {})
187+
default_profile = self._toml['profile'].get('default', {})
188+
189+
return {**default_profile, **current_profile}
186190

187191
@property
188192
def out(self) -> Path:
@@ -212,6 +216,15 @@ def main_file(self) -> Path:
212216
def contracts_file(self) -> Path:
213217
return self.kompiled / 'contracts.k'
214218

219+
@property
220+
def build_info(self) -> Path:
221+
build_info_path = self.profile.get('build_info_path')
222+
223+
if build_info_path:
224+
return self._root / build_info_path
225+
else:
226+
return self.out / 'build-info'
227+
215228
@cached_property
216229
def kevm(self) -> KEVM:
217230
use_directory = self.out / 'tmp'
@@ -1364,7 +1377,7 @@ def __init__(self, foundry: Foundry, contract_name: str, omit_unstable_output: b
13641377
self.foundry = foundry
13651378
self.contract_name = contract_name
13661379
self.omit_unstable_output = omit_unstable_output
1367-
self.compilation_unit = CompilationUnit.load_build_info(foundry._root)
1380+
self.compilation_unit = CompilationUnit.load_build_info(foundry.build_info)
13681381

13691382
def print_node(self, kcfg: KCFG, node: KCFG.Node) -> list[str]:
13701383
ret_strs = super().print_node(kcfg, node)

src/kontrol/solc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ def uuid(self) -> int:
495495
return self._id
496496

497497
@staticmethod
498-
def load_build_info(foundry_root: Path) -> CompilationUnit:
499-
build_info_files = (foundry_root / 'out' / 'build-info').glob('*.json')
498+
def load_build_info(foundry_build_info: Path) -> CompilationUnit:
499+
build_info_files = foundry_build_info.glob('*.json')
500500
build_info = json.loads(max(build_info_files, key=os.path.getmtime).read_text())
501501
sources: dict[int, Source] = {} # Source id => Source
502502
contracts: dict[bytes, ContractSource] = {} # CBOR metadata => contract

0 commit comments

Comments
 (0)