Skip to content

Commit 81ad88c

Browse files
committed
auto-clean: first draft implementation
1 parent 9520549 commit 81ad88c

File tree

16 files changed

+151
-21
lines changed

16 files changed

+151
-21
lines changed

crytic_compile/crytic_compile.py

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

547547
else:
548+
if not kwargs.get("skip_clean", False) and not kwargs.get("ignore_compile", False):
549+
self._platform.clean(**kwargs)
548550
self._platform.compile(self, **kwargs)
549551

550552
remove_metadata = kwargs.get("compile_remove_metadata", 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
crytic_compile.filenames.add(path)
172172
compilation_unit.asts[path.absolute] = 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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
116116
compiler="solc", version=version, optimized=optimized
117117
)
118118

119+
def clean(self, **kwargs: str) -> None:
120+
"""Clean compilation artifacts
121+
122+
Args:
123+
**kwargs: optional arguments.
124+
"""
125+
126+
dapp_ignore_compile = kwargs.get("dapp_ignore_compile", False) or kwargs.get(
127+
"ignore_compile", False
128+
)
129+
if dapp_ignore_compile:
130+
return
131+
132+
cmd = ["dapp", "clean"]
133+
LOGGER.info(
134+
"'%s' running",
135+
" ".join(cmd),
136+
)
137+
subprocess.run(
138+
cmd,
139+
cwd=self._target,
140+
executable=shutil.which(cmd[0]),
141+
)
142+
119143
@staticmethod
120144
def is_supported(target: str, **kwargs: str) -> bool:
121145
"""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
@@ -168,6 +168,14 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
168168
natspec = Natspec(userdoc, devdoc)
169169
compilation_unit.natspec[contract_name] = natspec
170170

171+
def clean(self, **_kwargs: str) -> None:
172+
"""Clean compilation artifacts
173+
174+
Args:
175+
**kwargs: unused.
176+
"""
177+
return
178+
171179
@staticmethod
172180
def is_supported(target: str, **kwargs: str) -> bool:
173181
"""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
@@ -157,6 +157,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None:
157157
compiler=compiler, version=version, optimized=_is_optimized(compile_arguments)
158158
)
159159

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

crytic_compile/platform/etherscan.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
357357

358358
solc_standard_json.standalone_compile(filenames, compilation_unit, working_dir=working_dir)
359359

360+
def clean(self, **_kwargs: str) -> None:
361+
pass
362+
360363
@staticmethod
361364
def is_supported(target: str, **kwargs: str) -> bool:
362365
"""Check if the target is a etherscan project

crytic_compile/platform/foundry.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
157157
compiler=compiler, version=version, optimized=optimized, optimize_runs=runs
158158
)
159159

160+
def clean(self, **_kwargs: str) -> None:
161+
"""Clean compilation artifacts
162+
163+
Args:
164+
**kwargs: unused.
165+
"""
166+
return
167+
160168
@staticmethod
161169
def is_supported(target: str, **kwargs: str) -> bool:
162170
"""Check if the target is a foundry project

0 commit comments

Comments
 (0)