@@ -11,6 +11,19 @@ const swarmhash = require('swarmhash')
11
11
// This script updates the index files list.js and list.txt in the directories containing binaries,
12
12
// as well as the 'latest' and 'nightly' symlinks/files.
13
13
14
+ function generateLegacyListJS ( builds , releases ) {
15
+ return `
16
+ var soljsonSources = ${ JSON . stringify ( builds , null , 2 ) } ;
17
+ var soljsonReleases = ${ JSON . stringify ( releases , null , 2 ) } ;
18
+
19
+ if (typeof(module) !== 'undefined')
20
+ module.exports = {
21
+ 'allVersions': soljsonSources,
22
+ 'releases': soljsonReleases
23
+ };
24
+ `
25
+ }
26
+
14
27
function updateSymlinkSync ( linkPathRelativeToRoot , targetRelativeToLink ) {
15
28
const absoluteLinkPath = path . join ( __dirname , linkPathRelativeToRoot )
16
29
let linkString
@@ -61,25 +74,66 @@ function updateCopy (srcRelativeToRoot, destRelativeToRoot) {
61
74
} )
62
75
}
63
76
64
- function processDir ( dir , listCallback ) {
77
+ function buildVersion ( build ) {
78
+ let version = build . version
79
+ if ( build . prerelease && build . prerelease . length > 0 ) {
80
+ version += '-' + build . prerelease
81
+ }
82
+ if ( build . build && build . build . length > 0 ) {
83
+ version += '+' + build . build
84
+ }
85
+ return version
86
+ }
87
+
88
+ function makeEntry ( dir , parsedFileName , oldList ) {
89
+ const pathRelativeToRoot = path . join ( dir , parsedFileName [ 0 ] )
90
+ const absolutePath = path . join ( __dirname , pathRelativeToRoot )
91
+
92
+ const build = {
93
+ path : parsedFileName [ 0 ] ,
94
+ version : parsedFileName [ 1 ] ,
95
+ prerelease : parsedFileName [ 3 ] ,
96
+ build : parsedFileName [ 5 ]
97
+ }
98
+ build . longVersion = buildVersion ( build )
99
+
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
121
+ }
122
+
123
+ function processDir ( dir , options , listCallback ) {
65
124
fs . readdir ( path . join ( __dirname , dir ) , { withFileTypes : true } , function ( err , files ) {
66
125
if ( err ) {
67
126
throw err
68
127
}
69
128
70
- function buildVersion ( build ) {
71
- var version = build . version
72
- if ( build . prerelease && build . prerelease . length > 0 ) {
73
- version += '-' + build . prerelease
74
- }
75
- if ( build . build && build . build . length > 0 ) {
76
- version += '+' + build . build
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.
77
136
}
78
- return version
79
- }
80
-
81
- function readFile ( file ) {
82
- return fs . readFileSync ( path . join ( __dirname , dir , file ) )
83
137
}
84
138
85
139
const binaryPrefix = ( dir === '/bin' || dir === '/wasm' ? 'soljson' : 'solc-' + dir . slice ( 1 ) )
@@ -106,14 +160,7 @@ function processDir (dir, listCallback) {
106
160
return file . match ( new RegExp ( '^' + binaryPrefix + '-v([0-9.]*)(-([^+]*))?(\\+(.*))?' + escapedExtension + '$' ) )
107
161
} )
108
162
. filter ( function ( version ) { return version } )
109
- . map ( function ( pars ) { return { path : pars [ 0 ] , version : pars [ 1 ] , prerelease : pars [ 3 ] , build : pars [ 5 ] } } )
110
- . map ( function ( pars ) {
111
- const fileContent = readFile ( pars . path )
112
- pars . longVersion = buildVersion ( pars )
113
- pars . keccak256 = '0x' + ethUtil . keccak ( fileContent ) . toString ( 'hex' )
114
- pars . urls = [ 'bzzr://' + swarmhash ( fileContent ) . toString ( 'hex' ) ]
115
- return pars
116
- } )
163
+ . map ( function ( pars ) { return makeEntry ( dir , pars , oldList ) } )
117
164
. sort ( function ( a , b ) {
118
165
if ( a . longVersion === b . longVersion ) {
119
166
return 0
@@ -205,18 +252,36 @@ function processDir (dir, listCallback) {
205
252
} )
206
253
}
207
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
+
208
271
const DIRS = [
209
272
'/bin' ,
210
273
'/linux-amd64' ,
211
274
'/macosx-amd64' ,
212
275
'/windows-amd64'
213
276
]
214
277
278
+ const options = parseCommandLine ( )
279
+
215
280
DIRS . forEach ( function ( dir ) {
216
281
if ( dir !== '/bin' ) {
217
- processDir ( dir )
282
+ processDir ( dir , options )
218
283
} else {
219
- processDir ( dir , function ( parsedList ) {
284
+ processDir ( dir , options , function ( parsedList ) {
220
285
// Any new releases added to bin/ need to be linked in other directories before we can start processing them.
221
286
parsedList . forEach ( function ( release ) {
222
287
if ( release . prerelease === undefined ) {
@@ -235,8 +300,8 @@ DIRS.forEach(function (dir) {
235
300
}
236
301
} )
237
302
238
- processDir ( '/emscripten-asmjs' )
239
- processDir ( '/wasm' , function ( parsedList ) {
303
+ processDir ( '/emscripten-asmjs' , options )
304
+ processDir ( '/wasm' , options , function ( parsedList ) {
240
305
// Any new releases added to wasm/ need to be linked in emscripten-wasm32/ first.
241
306
parsedList . forEach ( function ( release ) {
242
307
if ( release . prerelease === undefined ) {
@@ -247,21 +312,8 @@ DIRS.forEach(function (dir) {
247
312
}
248
313
} )
249
314
250
- processDir ( '/emscripten-wasm32' )
315
+ processDir ( '/emscripten-wasm32' , options )
251
316
} )
252
317
} )
253
318
}
254
319
} )
255
-
256
- function generateLegacyListJS ( builds , releases ) {
257
- return `
258
- var soljsonSources = ${ JSON . stringify ( builds , null , 2 ) } ;
259
- var soljsonReleases = ${ JSON . stringify ( releases , null , 2 ) } ;
260
-
261
- if (typeof(module) !== 'undefined')
262
- module.exports = {
263
- 'allVersions': soljsonSources,
264
- 'releases': soljsonReleases
265
- };
266
- `
267
- }
0 commit comments