@@ -74,10 +74,6 @@ function updateCopy (srcRelativeToRoot, destRelativeToRoot) {
74
74
} )
75
75
}
76
76
77
- function readFile ( dir , file ) {
78
- return fs . readFileSync ( path . join ( __dirname , dir , file ) )
79
- }
80
-
81
77
function buildVersion ( build ) {
82
78
let version = build . version
83
79
if ( build . prerelease && build . prerelease . length > 0 ) {
@@ -89,7 +85,10 @@ function buildVersion (build) {
89
85
return version
90
86
}
91
87
92
- function makeEntry ( dir , parsedFileName ) {
88
+ function makeEntry ( dir , parsedFileName , oldList ) {
89
+ const pathRelativeToRoot = path . join ( dir , parsedFileName [ 0 ] )
90
+ const absolutePath = path . join ( __dirname , pathRelativeToRoot )
91
+
93
92
const build = {
94
93
path : parsedFileName [ 0 ] ,
95
94
version : parsedFileName [ 1 ] ,
@@ -98,19 +97,45 @@ function makeEntry (dir, parsedFileName) {
98
97
}
99
98
build . longVersion = buildVersion ( build )
100
99
101
- const fileContent = readFile ( dir , parsedFileName . path )
102
- parsedFileName . longVersion = buildVersion ( parsedFileName )
103
- parsedFileName . keccak256 = '0x' + ethUtil . keccak ( fileContent ) . toString ( 'hex' )
104
- parsedFileName . urls = [ 'bzzr://' + swarmhash ( fileContent ) . toString ( 'hex' ) ]
105
- return parsedFileName
100
+ if ( oldList ) {
101
+ const entries = oldList . builds . filter ( entry => ( entry . path === parsedFileName [ 0 ] ) )
102
+ if ( entries ) {
103
+ if ( entries . length >= 2 ) {
104
+ throw Error ( "Found multiple list.json entries for binary '" + pathRelativeToRoot + "'" )
105
+ } else if ( entries . length === 1 ) {
106
+ build . keccak256 = entries [ 0 ] . keccak256
107
+ build . urls = entries [ 0 ] . urls
108
+ }
109
+ }
110
+ }
111
+
112
+ if ( ! build . keccak256 || ! build . urls ) {
113
+ const fileContent = fs . readFileSync ( absolutePath )
114
+ build . keccak256 = '0x' + ethUtil . keccak ( fileContent ) . toString ( 'hex' )
115
+ build . urls = [ 'bzzr://' + swarmhash ( fileContent ) . toString ( 'hex' ) ]
116
+
117
+ console . log ( "Hashing '" + pathRelativeToRoot + "'" )
118
+ }
119
+
120
+ return build
106
121
}
107
122
108
- function processDir ( dir , listCallback ) {
123
+ function processDir ( dir , options , listCallback ) {
109
124
fs . readdir ( path . join ( __dirname , dir ) , { withFileTypes : true } , function ( err , files ) {
110
125
if ( err ) {
111
126
throw err
112
127
}
113
128
129
+ let oldList
130
+ if ( options . reuseHashes ) {
131
+ try {
132
+ oldList = JSON . parse ( fs . readFileSync ( path . join ( __dirname , dir , '/list.json' ) ) )
133
+ } catch ( err ) {
134
+ // Not being able to read the existing list is not a critical error.
135
+ // We'll just recreate it from scratch.
136
+ }
137
+ }
138
+
114
139
const binaryPrefix = ( dir === '/bin' || dir === '/wasm' ? 'soljson' : 'solc-' + dir . slice ( 1 ) )
115
140
const binaryExtension = {
116
141
'/bin' : '.js' ,
@@ -135,7 +160,7 @@ function processDir (dir, listCallback) {
135
160
return file . match ( new RegExp ( '^' + binaryPrefix + '-v([0-9.]*)(-([^+]*))?(\\+(.*))?' + escapedExtension + '$' ) )
136
161
} )
137
162
. filter ( function ( version ) { return version } )
138
- . map ( function ( pars ) { return makeEntry ( dir , pars ) } )
163
+ . map ( function ( pars ) { return makeEntry ( dir , pars , oldList ) } )
139
164
. sort ( function ( a , b ) {
140
165
if ( a . longVersion === b . longVersion ) {
141
166
return 0
@@ -227,18 +252,36 @@ function processDir (dir, listCallback) {
227
252
} )
228
253
}
229
254
255
+ function parseCommandLine ( ) {
256
+ if ( process . argv . length > 3 ) {
257
+ console . error ( 'Expected at most one argument, got ' + ( process . argv . length - 2 ) )
258
+ process . exit ( 1 )
259
+ }
260
+
261
+ if ( process . argv . length === 3 && process . argv [ 2 ] !== '--reuse-hashes' ) {
262
+ console . error ( 'Invalid argument: ' + process . argv [ 2 ] )
263
+ process . exit ( 1 )
264
+ }
265
+
266
+ return {
267
+ reuseHashes : process . argv . length === 3 && process . argv [ 2 ] === '--reuse-hashes'
268
+ }
269
+ }
270
+
230
271
const DIRS = [
231
272
'/bin' ,
232
273
'/linux-amd64' ,
233
274
'/macosx-amd64' ,
234
275
'/windows-amd64'
235
276
]
236
277
278
+ const options = parseCommandLine ( )
279
+
237
280
DIRS . forEach ( function ( dir ) {
238
281
if ( dir !== '/bin' ) {
239
- processDir ( dir )
282
+ processDir ( dir , options )
240
283
} else {
241
- processDir ( dir , function ( parsedList ) {
284
+ processDir ( dir , options , function ( parsedList ) {
242
285
// Any new releases added to bin/ need to be linked in other directories before we can start processing them.
243
286
parsedList . forEach ( function ( release ) {
244
287
if ( release . prerelease === undefined ) {
@@ -257,8 +300,8 @@ DIRS.forEach(function (dir) {
257
300
}
258
301
} )
259
302
260
- processDir ( '/emscripten-asmjs' )
261
- processDir ( '/wasm' , function ( parsedList ) {
303
+ processDir ( '/emscripten-asmjs' , options )
304
+ processDir ( '/wasm' , options , function ( parsedList ) {
262
305
// Any new releases added to wasm/ need to be linked in emscripten-wasm32/ first.
263
306
parsedList . forEach ( function ( release ) {
264
307
if ( release . prerelease === undefined ) {
@@ -269,7 +312,7 @@ DIRS.forEach(function (dir) {
269
312
}
270
313
} )
271
314
272
- processDir ( '/emscripten-wasm32' )
315
+ processDir ( '/emscripten-wasm32' , options )
273
316
} )
274
317
} )
275
318
}
0 commit comments