|
8 | 8 | import re
|
9 | 9 | import urllib.request
|
10 | 10 | from json.decoder import JSONDecodeError
|
11 |
| -from pathlib import Path |
| 11 | +from pathlib import Path, PurePosixPath |
12 | 12 | from typing import TYPE_CHECKING, Dict, List, Union, Tuple, Optional
|
13 | 13 |
|
14 | 14 | from crytic_compile.compilation_unit import CompilationUnit
|
@@ -147,16 +147,25 @@ def _handle_multiple_files(
|
147 | 147 |
|
148 | 148 | filtered_paths: List[str] = []
|
149 | 149 | for filename, source_code in source_codes.items():
|
150 |
| - path_filename = Path(filename) |
| 150 | + path_filename = PurePosixPath(filename) |
151 | 151 | if "contracts" in path_filename.parts and not filename.startswith("@"):
|
152 |
| - path_filename = Path(*path_filename.parts[path_filename.parts.index("contracts") :]) |
| 152 | + path_filename = PurePosixPath( |
| 153 | + *path_filename.parts[path_filename.parts.index("contracts") :] |
| 154 | + ) |
| 155 | + |
| 156 | + # Convert "absolute" paths such as "/interfaces/IFoo.sol" into relative ones. |
| 157 | + # This is needed due to the following behavior from pathlib.Path: |
| 158 | + # > When several absolute paths are given, the last is taken as an anchor |
| 159 | + # We need to make sure this is relative, so that Path(directory, ...) remains anchored to directory |
| 160 | + if path_filename.is_absolute(): |
| 161 | + path_filename = PurePosixPath(*path_filename.parts[1:]) |
153 | 162 |
|
154 |
| - filtered_paths.append(str(path_filename)) |
155 |
| - path_filename = Path(directory, path_filename) |
| 163 | + filtered_paths.append(path_filename.as_posix()) |
| 164 | + path_filename_disk = Path(directory, path_filename) |
156 | 165 |
|
157 |
| - if not os.path.exists(path_filename.parent): |
158 |
| - os.makedirs(path_filename.parent) |
159 |
| - with open(path_filename, "w", encoding="utf8") as file_desc: |
| 166 | + if not os.path.exists(path_filename_disk.parent): |
| 167 | + os.makedirs(path_filename_disk.parent) |
| 168 | + with open(path_filename_disk, "w", encoding="utf8") as file_desc: |
160 | 169 | file_desc.write(source_code["content"])
|
161 | 170 |
|
162 | 171 | return list(filtered_paths), directory
|
|
0 commit comments