Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use build_info_path in load_build_info, update TOML parsing logic #825

Merged
merged 4 commits into from
Sep 23, 2024
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
2 changes: 1 addition & 1 deletion src/kontrol/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions src/kontrol/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/kontrol/solc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading