@@ -57,9 +57,34 @@ 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 , autolink_path : str ) -> None :
61
+ """Export linking information to a separate file"""
62
+
63
+ # Get library addresses if they exist
64
+ library_addresses = {}
65
+ if compilation_unit .crytic_compile .libraries :
66
+ library_addresses = {
67
+ name : f"0x{ addr :040x} "
68
+ for name , addr in compilation_unit .crytic_compile .libraries .items ()
69
+ }
70
+
71
+ # Filter deployment order to only include libraries that have addresses
72
+ full_deployment_order = compilation_unit .crytic_compile .deployment_order or []
73
+ filtered_deployment_order = [lib for lib in full_deployment_order if lib in library_addresses ]
74
+
75
+ # Create autolink output with deployment order and library addresses
76
+ autolink_output = {
77
+ "deployment_order" : filtered_deployment_order ,
78
+ "library_addresses" : library_addresses ,
79
+ }
80
+
81
+ with open (autolink_path , "w" , encoding = "utf8" ) as file_desc :
82
+ json .dump (autolink_output , file_desc , indent = 2 )
83
+
84
+
60
85
def export_to_solc_from_compilation_unit (
61
86
compilation_unit : "CompilationUnit" , key : str , export_dir : str
62
- ) -> Optional [str ]:
87
+ ) -> Optional [List [ str ] ]:
63
88
"""Export the compilation unit to the standard solc output format.
64
89
The exported file will be $key.json
65
90
@@ -69,7 +94,7 @@ def export_to_solc_from_compilation_unit(
69
94
export_dir (str): Export directory
70
95
71
96
Returns:
72
- Optional[str]: path to the file generated
97
+ Optional[List[ str]] : path to the files generated
73
98
"""
74
99
contracts = _build_contract_data (compilation_unit )
75
100
@@ -88,7 +113,16 @@ def export_to_solc_from_compilation_unit(
88
113
89
114
with open (path , "w" , encoding = "utf8" ) as file_desc :
90
115
json .dump (output , file_desc )
91
- return path
116
+
117
+ paths = [path ]
118
+
119
+ # Export link info if compile_autolink or compile_libraries was used
120
+ if compilation_unit .crytic_compile .libraries :
121
+ link_path = os .path .join (export_dir , f"{ key } .link" )
122
+ _export_link_info (compilation_unit , key , link_path )
123
+ paths .append (link_path )
124
+
125
+ return paths
92
126
return None
93
127
94
128
@@ -110,17 +144,18 @@ def export_to_solc(crytic_compile: "CryticCompile", **kwargs: str) -> List[str]:
110
144
111
145
if len (crytic_compile .compilation_units ) == 1 :
112
146
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 ]
147
+ paths = export_to_solc_from_compilation_unit (compilation_unit , "combined_solc" , export_dir )
148
+ if paths :
149
+ return paths
116
150
return []
117
151
118
- paths = []
152
+ all_paths = []
119
153
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
154
+ paths = export_to_solc_from_compilation_unit (compilation_unit , key , export_dir )
155
+ if paths :
156
+ all_paths .extend (paths )
157
+
158
+ return all_paths
124
159
125
160
126
161
class Solc (AbstractPlatform ):
0 commit comments