17
17
from solc_select .solc_select import (
18
18
install_artifacts ,
19
19
installed_versions ,
20
- current_version ,
21
20
artifact_path ,
22
21
)
23
22
from crytic_compile .compilation_unit import CompilationUnit
@@ -86,6 +85,31 @@ def _extract_libraries(libraries_str: Optional[str]) -> Optional[Dict[str, int]]
86
85
return ret
87
86
88
87
88
+ def _configure_solc (solc_requested : str , offline : bool ) -> str :
89
+ """
90
+ Determine which solc binary to use based on the requested version or path (e.g. '0.8.0' or '/usr/bin/solc-0.8.0').
91
+
92
+ Args:
93
+ solc_requested (str): solc version or path
94
+ offline (bool): whether to allow network requests
95
+
96
+ Returns:
97
+ str: path to solc binary
98
+ """
99
+ if Path (solc_requested ).exists ():
100
+ solc_path = Path (solc_requested )
101
+ else :
102
+ solc_version = solc_requested
103
+ if solc_requested in installed_versions ():
104
+ solc_path = artifact_path (solc_requested )
105
+ else :
106
+ # Respect foundry offline option and skip installation.
107
+ if not offline :
108
+ install_artifacts ([solc_version ])
109
+ solc_path = artifact_path (solc_version )
110
+ return solc_path .absolute ().as_posix ()
111
+
112
+
89
113
# pylint: disable=too-many-instance-attributes
90
114
class CryticCompile :
91
115
"""
@@ -139,7 +163,7 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None:
139
163
),
140
164
None ,
141
165
)
142
- # If no platform has been found or if it's a Solc we can't do anything
166
+ # If no platform has been found or if it's the Solc platform, we can't automatically compile.
143
167
if platform_wd and not isinstance (platform_wd , Solc ):
144
168
platform_config = platform_wd .config (str (self ._working_dir ))
145
169
if platform_config :
@@ -148,18 +172,13 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None:
148
172
149
173
if platform_config .remappings :
150
174
kwargs ["solc_remaps" ] = platform_config .remappings
151
- if (
152
- platform_config .solc_version
153
- and platform_config .solc_version != current_version ()[0 ]
154
- ):
155
- solc_version = platform_config .solc_version
156
- if solc_version in installed_versions ():
157
- kwargs ["solc" ] = str (artifact_path (solc_version ).absolute ())
158
- else :
159
- # Respect foundry offline option and don't install a missing solc version
160
- if not platform_config .offline :
161
- install_artifacts ([solc_version ])
162
- kwargs ["solc" ] = str (artifact_path (solc_version ).absolute ())
175
+ if platform_config .solc_version is None :
176
+ message = f"Could not detect solc version from { platform_wd .NAME } config. Falling back to system version..."
177
+ LOGGER .warning (message )
178
+ else :
179
+ kwargs ["solc" ] = _configure_solc (
180
+ platform_config .solc_version , platform_config .offline
181
+ )
163
182
if platform_config .optimizer :
164
183
kwargs ["solc_args" ] += "--optimize"
165
184
if platform_config .optimizer_runs :
0 commit comments