|
4 | 4 | import json
|
5 | 5 | import logging
|
6 | 6 | import os
|
7 |
| -import shutil |
8 |
| -import subprocess |
| 7 | +import tempfile |
9 | 8 | from pathlib import Path
|
10 | 9 | from typing import TYPE_CHECKING, Dict, List, Optional
|
11 | 10 |
|
@@ -73,13 +72,15 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
|
73 | 72 | self.add_source_files([target])
|
74 | 73 |
|
75 | 74 | vyper_bin = kwargs.get("vyper", "vyper")
|
76 |
| - output_file = Path("crytic-export/standard_input.json") |
77 |
| - output_file.parent.mkdir(exist_ok=True, parents=True) |
78 |
| - with open(output_file, "w") as f: |
79 |
| - f.write(json.dumps(self.standard_json_input)) |
80 |
| - |
81 |
| - compilation_artifacts = _run_vyper_standard_json(output_file.as_posix(), vyper_bin) |
82 |
| - |
| 75 | + compilation_artifacts = None |
| 76 | + with tempfile.NamedTemporaryFile(mode="a+") as f: |
| 77 | + json.dump(self.standard_json_input, f) |
| 78 | + f.seek(0) |
| 79 | + compilation_artifacts = _run_vyper_standard_json(f.name, vyper_bin) |
| 80 | + |
| 81 | + if "errors" in compilation_artifacts: |
| 82 | + # TODO format errors |
| 83 | + raise InvalidCompilation(compilation_artifacts["errors"]) |
83 | 84 | compilation_unit = CompilationUnit(crytic_compile, str(target))
|
84 | 85 |
|
85 | 86 | compiler_version = compilation_artifacts["compiler"].split("-")[1]
|
@@ -187,12 +188,13 @@ def _run_vyper_standard_json(
|
187 | 188 | Returns:
|
188 | 189 | Dict: Vyper json compilation artifact
|
189 | 190 | """
|
190 |
| - cmd = [vyper, standard_input_path, "--standard-json", "-o", "crytic-export/artifacts.json"] |
191 |
| - success = run(cmd, cwd=working_dir, extra_env=env) |
192 |
| - if success is None: |
193 |
| - raise InvalidCompilation("Vyper compilation failed") |
194 |
| - with open("crytic-export/artifacts.json", "r") as f: |
195 |
| - return json.load(f) |
| 191 | + with tempfile.NamedTemporaryFile(mode="a+") as f: |
| 192 | + cmd = [vyper, standard_input_path, "--standard-json", "-o", f.name] |
| 193 | + success = run(cmd, cwd=working_dir, extra_env=env) |
| 194 | + if success is None: |
| 195 | + raise InvalidCompilation("Vyper compilation failed") |
| 196 | + f.seek(0) |
| 197 | + return json.loads(f.read()) |
196 | 198 |
|
197 | 199 |
|
198 | 200 | def _relative_to_short(relative: Path) -> Path:
|
|
0 commit comments