@@ -57,9 +57,46 @@ def _build_contract_data(compilation_unit: "CompilationUnit") -> Dict:
57
57
return contracts
58
58
59
59
60
+ def _export_link_info (compilation_unit : "CompilationUnit" , key : str , export_dir : str ) -> str :
61
+ """Export linking information to a separate file.
62
+
63
+ Args:
64
+ compilation_unit (CompilationUnit): Compilation unit to export
65
+ key (str): Filename Id
66
+ export_dir (str): Export directory
67
+
68
+ Returns:
69
+ str: path to the generated file"""
70
+
71
+ autolink_path = os .path .join (export_dir , f"{ key } .link" )
72
+
73
+ # Get library addresses if they exist
74
+ library_addresses = {}
75
+ if compilation_unit .crytic_compile .libraries :
76
+ library_addresses = {
77
+ name : f"0x{ addr :040x} "
78
+ for name , addr in compilation_unit .crytic_compile .libraries .items ()
79
+ }
80
+
81
+ # Filter deployment order to only include libraries that have addresses
82
+ full_deployment_order = compilation_unit .crytic_compile .deployment_order or []
83
+ filtered_deployment_order = [lib for lib in full_deployment_order if lib in library_addresses ]
84
+
85
+ # Create autolink output with deployment order and library addresses
86
+ autolink_output = {
87
+ "deployment_order" : filtered_deployment_order ,
88
+ "library_addresses" : library_addresses ,
89
+ }
90
+
91
+ with open (autolink_path , "w" , encoding = "utf8" ) as file_desc :
92
+ json .dump (autolink_output , file_desc , indent = 2 )
93
+
94
+ return autolink_path
95
+
96
+
60
97
def export_to_solc_from_compilation_unit (
61
98
compilation_unit : "CompilationUnit" , key : str , export_dir : str
62
- ) -> Optional [str ]:
99
+ ) -> Optional [List [ str ] ]:
63
100
"""Export the compilation unit to the standard solc output format.
64
101
The exported file will be $key.json
65
102
@@ -69,7 +106,7 @@ def export_to_solc_from_compilation_unit(
69
106
export_dir (str): Export directory
70
107
71
108
Returns:
72
- Optional[str]: path to the file generated
109
+ Optional[List[ str]] : path to the files generated
73
110
"""
74
111
contracts = _build_contract_data (compilation_unit )
75
112
@@ -88,7 +125,15 @@ def export_to_solc_from_compilation_unit(
88
125
89
126
with open (path , "w" , encoding = "utf8" ) as file_desc :
90
127
json .dump (output , file_desc )
91
- return path
128
+
129
+ paths = [path ]
130
+
131
+ # Export link info if compile_autolink or compile_libraries was used
132
+ if compilation_unit .crytic_compile .libraries :
133
+ link_path = _export_link_info (compilation_unit , key , export_dir )
134
+ paths .append (link_path )
135
+
136
+ return paths
92
137
return None
93
138
94
139
@@ -110,17 +155,18 @@ def export_to_solc(crytic_compile: "CryticCompile", **kwargs: str) -> List[str]:
110
155
111
156
if len (crytic_compile .compilation_units ) == 1 :
112
157
compilation_unit = list (crytic_compile .compilation_units .values ())[0 ]
113
- path = export_to_solc_from_compilation_unit (compilation_unit , "combined_solc" , export_dir )
114
- if path :
115
- return [ path ]
158
+ paths = export_to_solc_from_compilation_unit (compilation_unit , "combined_solc" , export_dir )
159
+ if paths :
160
+ return paths
116
161
return []
117
162
118
- paths = []
163
+ all_paths = []
119
164
for key , compilation_unit in crytic_compile .compilation_units .items ():
120
- path = export_to_solc_from_compilation_unit (compilation_unit , key , export_dir )
121
- if path :
122
- paths .append (path )
123
- return paths
165
+ paths = export_to_solc_from_compilation_unit (compilation_unit , key , export_dir )
166
+ if paths :
167
+ all_paths .extend (paths )
168
+
169
+ return all_paths
124
170
125
171
126
172
class Solc (AbstractPlatform ):
0 commit comments