diff --git a/crytic_compile/platform/foundry.py b/crytic_compile/platform/foundry.py index 47c3a890..2ea66a96 100755 --- a/crytic_compile/platform/foundry.py +++ b/crytic_compile/platform/foundry.py @@ -5,9 +5,9 @@ import os import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Optional, Dict, TypeVar +from typing import TYPE_CHECKING, List, Optional, TypeVar -import toml +import json from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.types import Type @@ -63,7 +63,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None: compile_all = kwargs.get("foundry_compile_all", False) if not compile_all: - foundry_config = self.config(str(crytic_compile.working_dir.absolute())) + foundry_config = self.config(self._target) if foundry_config: compilation_command += [ "--skip", @@ -122,64 +122,34 @@ def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: - working_dir (str): path to the working directory + working_dir (str): path to the working_dir Returns: Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ result = PlatformConfig() - result.remappings = ( - subprocess.run(["forge", "remappings"], stdout=subprocess.PIPE, check=True) - .stdout.decode("utf-8") - .replace("\n", " ") - .strip() + LOGGER.info("'forge config --json' running") + json_config = json.loads( + subprocess.run( + ["forge", "config", "--json"], cwd=working_dir, stdout=subprocess.PIPE, check=True + ).stdout ) - with open("foundry.toml", "r", encoding="utf-8") as f: - foundry_toml = toml.loads(f.read()) - default_profile = foundry_toml["profile"]["default"] - - def lookup_by_keys(keys: List[str], dictionary: Dict[str, T]) -> Optional[T]: - for key in keys: - if key in dictionary: - return dictionary[key] - return None - - # Foundry supports snake and kebab case. - result.solc_version = lookup_by_keys( - ["solc", "solc_version", "solc-version"], default_profile - ) - via_ir = lookup_by_keys(["via_ir", "via-ir"], default_profile) - if via_ir: - result.via_ir = via_ir - result.allow_paths = lookup_by_keys(["allow_paths", "allow-paths"], default_profile) - - if "offline" in default_profile: - result.offline = default_profile["offline"] - if "optimizer" in default_profile: - result.optimizer = default_profile["optimizer"] - else: - # Default to true - result.optimizer = True - optimizer_runs = lookup_by_keys(["optimizer_runs", "optimizer-runs"], default_profile) - if optimizer_runs is None: - # Default to 200 - result.optimizer_runs = 200 - else: - result.optimizer_runs = optimizer_runs - evm_version = lookup_by_keys(["evm_version", "evm-version"], default_profile) - if evm_version is None: - result.evm_version = evm_version - else: - # Default to london - result.evm_version = "london" - if "src" in default_profile: - result.src_path = default_profile["src"] - if "test" in default_profile: - result.tests_path = default_profile["test"] - if "libs" in default_profile: - result.libs_path = default_profile["libs"] - if "script" in default_profile: - result.scripts_path = default_profile["script"] + + # Solc configurations + result.solc_version = json_config.get("solc") + result.via_ir = json_config.get("via_ir") + result.allow_paths = json_config.get("allow_paths") + result.offline = json_config.get("offline") + result.evm_version = json_config.get("evm_version") + result.optimizer = json_config.get("optimizer") + result.optimizer_runs = json_config.get("optimizer_runs") + result.remappings = json_config.get("remappings") + + # Foundry project configurations + result.src_path = json_config.get("src") + result.tests_path = json_config.get("test") + result.libs_path = json_config.get("libs") + result.scripts_path = json_config.get("script") return result diff --git a/scripts/ci_test_foundry.sh b/scripts/ci_test_foundry.sh index 726134fc..6e240e4a 100755 --- a/scripts/ci_test_foundry.sh +++ b/scripts/ci_test_foundry.sh @@ -12,6 +12,15 @@ forge init --no-commit crytic-compile . if [ $? -ne 0 ] then - echo "foundry test failed" + echo "foundry test 1 failed" exit 255 fi + +mkdir /tmp/forge_test/test_2 +rsync -a --exclude='test_2' ./ /tmp/forge_test/test_2/ +crytic-compile ./test_2 +if [ $? -ne 0 ] +then + echo "foundry test 2 failed" + exit 255 +fi \ No newline at end of file diff --git a/setup.py b/setup.py index fe021686..e96d7533 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ version="0.3.4", packages=find_packages(), python_requires=">=3.8", - install_requires=["pycryptodome>=3.4.6", "cbor2", "solc-select>=v1.0.4", "toml>=0.10.2"], + install_requires=["pycryptodome>=3.4.6", "cbor2", "solc-select>=v1.0.4"], extras_require={ "test": [ "pytest",