From 56e4afa8babaab9be1cec39331158c88edad6568 Mon Sep 17 00:00:00 2001 From: Daniel Perez Date: Sun, 16 Jan 2022 14:50:21 +0200 Subject: [PATCH] Fix incremental compilation --- CHANGELOG.md | 1 + brownie/project/main.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37a26b0a2..884539556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Improve support for Ganache 7 reverted transactions +- Fix incremental compilation failing because of mismatching compiler versions ## [1.17.2](https://github.com/eth-brownie/brownie/tree/v1.17.2) - 2021-12-04 ### Changed diff --git a/brownie/project/main.py b/brownie/project/main.py index f96c78200..606b4cee6 100644 --- a/brownie/project/main.py +++ b/brownie/project/main.py @@ -291,17 +291,19 @@ def _compare_build_json(self, contract_name: str) -> bool: if build_json["sha1"] != sha1(source.encode()).hexdigest(): return True # compare compiler settings - if _compare_settings(config, build_json["compiler"]): - return True if build_json["language"] == "Solidity": # compare solc-specific compiler settings solc_config = config["solc"].copy() solc_config["remappings"] = None - if _compare_settings(solc_config, build_json["compiler"]): + if not _solidity_compiler_equal(solc_config, build_json["compiler"]): return True # compare solc pragma against compiled version if Version(build_json["compiler"]["version"]) not in get_pragma_spec(source): return True + else: + vyper_config = config["vyper"].copy() + if not _vyper_compiler_equal(vyper_config, build_json["compiler"]): + return True return False def _compile_interfaces(self, compiled_hashes: Dict) -> None: @@ -950,6 +952,22 @@ def _compare_settings(left: Dict, right: Dict) -> bool: ) +def _normalize_solidity_version(version: str) -> str: + return version.split("+")[0] + + +def _solidity_compiler_equal(config: dict, build: dict) -> bool: + return ( + config["version"] is None + or _normalize_solidity_version(config["version"]) + == _normalize_solidity_version(build["version"]) + ) and config["optimizer"] == build["optimizer"] + + +def _vyper_compiler_equal(config: dict, build: dict) -> bool: + return config["version"] is None or config["version"] == build["version"] + + def _load_sources(project_path: Path, subfolder: str, allow_json: bool) -> Dict: contract_sources: Dict = {} suffixes: Tuple = (".sol", ".vy")