Skip to content

Commit fe7aadf

Browse files
authored
Merge pull request #312 from crytic/dev-auto-clean
Auto-clean projects before compiling
2 parents 5af9cbb + 1b08cef commit fe7aadf

19 files changed

+219
-9
lines changed

crytic_compile/crytic_compile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ def _compile(self, **kwargs: str) -> None:
525525
self._run_custom_build(custom_build)
526526

527527
else:
528+
if not kwargs.get("skip_clean", False) and not kwargs.get("ignore_compile", False):
529+
self._platform.clean(**kwargs)
528530
self._platform.compile(self, **kwargs)
529531

530532
remove_metadata = kwargs.get("compile_remove_metadata", False)

crytic_compile/cryticparser/cryticparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def init(parser: ArgumentParser) -> None:
5050
default=DEFAULTS_FLAG_IN_CONFIG["ignore_compile"],
5151
)
5252

53+
group_compile.add_argument(
54+
"--skip-clean",
55+
help="Do not attempt to clean before compiling with a platform",
56+
action="store_true",
57+
dest="skip_clean",
58+
default=DEFAULTS_FLAG_IN_CONFIG["skip_clean"],
59+
)
60+
5361
_init_solc(parser)
5462
_init_truffle(parser)
5563
_init_embark(parser)

crytic_compile/cryticparser/defaults.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"waffle_config_file": None,
3737
"npx_disable": False,
3838
"ignore_compile": False,
39+
"skip_clean": False,
3940
"buidler_ignore_compile": False,
4041
"buidler_cache_directory": "cache",
4142
"buidler_skip_directory_name_fix": False,

crytic_compile/platform/abstract_platform.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
119119
"""
120120
return
121121

122+
@abc.abstractmethod
123+
def clean(self, **kwargs: str) -> None:
124+
"""Clean compilation artifacts
125+
126+
Args:
127+
**kwargs: optional arguments.
128+
"""
129+
return
130+
122131
@staticmethod
123132
@abc.abstractmethod
124133
def is_supported(target: str, **kwargs: str) -> bool:

crytic_compile/platform/archive.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def compile(self, crytic_compile: "CryticCompile", **_kwargs: str) -> None:
7171
"""Run the compilation
7272
7373
Args:
74-
crytic_compile (CryticCompile): asscoiated CryticCompile object
74+
crytic_compile (CryticCompile): associated CryticCompile object
7575
**_kwargs: unused
7676
"""
7777
# pylint: disable=import-outside-toplevel
@@ -97,6 +97,9 @@ def compile(self, crytic_compile: "CryticCompile", **_kwargs: str) -> None:
9797

9898
crytic_compile.src_content = loaded_json["source_content"]
9999

100+
def clean(self, **_kwargs: str) -> None:
101+
pass
102+
100103
@staticmethod
101104
def is_supported(target: str, **kwargs: str) -> bool:
102105
"""Check if the target is an archive

crytic_compile/platform/brownie.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
8282

8383
_iterate_over_files(crytic_compile, Path(self._target), filenames)
8484

85+
def clean(self, **_kwargs: str) -> None:
86+
# brownie does not offer a way to clean a project
87+
pass
88+
8589
@staticmethod
8690
def is_supported(target: str, **kwargs: str) -> bool:
8791
"""Check if the target is a brownie project

crytic_compile/platform/buidler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
171171
source_unit = compilation_unit.create_source_unit(path)
172172
source_unit.ast = info["ast"]
173173

174+
def clean(self, **kwargs: str) -> None:
175+
# TODO: call "buldler clean"?
176+
pass
177+
174178
@staticmethod
175179
def is_supported(target: str, **kwargs: str) -> bool:
176180
"""Check if the target is a buidler project

crytic_compile/platform/dapp.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from crytic_compile.platform.abstract_platform import AbstractPlatform
2020
from crytic_compile.platform.types import Type
2121
from crytic_compile.utils.naming import convert_filename, extract_name
22+
from crytic_compile.utils.subprocess import run
2223

2324
# Handle cycle
2425
from crytic_compile.utils.natspec import Natspec
@@ -118,6 +119,21 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
118119
compiler="solc", version=version, optimized=optimized
119120
)
120121

122+
def clean(self, **kwargs: str) -> None:
123+
"""Clean compilation artifacts
124+
125+
Args:
126+
**kwargs: optional arguments.
127+
"""
128+
129+
dapp_ignore_compile = kwargs.get("dapp_ignore_compile", False) or kwargs.get(
130+
"ignore_compile", False
131+
)
132+
if dapp_ignore_compile:
133+
return
134+
135+
run(["dapp", "clean"], cwd=self._target)
136+
121137
@staticmethod
122138
def is_supported(target: str, **kwargs: str) -> bool:
123139
"""Check if the target is a dapp project

crytic_compile/platform/embark.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
167167
natspec = Natspec(userdoc, devdoc)
168168
source_unit.natspec[contract_name] = natspec
169169

170+
def clean(self, **_kwargs: str) -> None:
171+
"""Clean compilation artifacts
172+
173+
Args:
174+
**_kwargs: unused.
175+
"""
176+
return
177+
170178
@staticmethod
171179
def is_supported(target: str, **kwargs: str) -> bool:
172180
"""Check if the target is an embark project

crytic_compile/platform/etherlime.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None:
159159
compiler=compiler, version=version, optimized=_is_optimized(compile_arguments)
160160
)
161161

162+
def clean(self, **_kwargs: str) -> None:
163+
# TODO: research if there's a way to clean artifacts
164+
pass
165+
162166
@staticmethod
163167
def is_supported(target: str, **kwargs: str) -> bool:
164168
"""Check if the target is an etherlime project

0 commit comments

Comments
 (0)