@@ -28,19 +28,6 @@ var sys_extension = config.sys_extension;
28
28
29
29
process . env . BS_RELEASE_BUILD = "true" ;
30
30
31
- /**
32
- * @type {string }
33
- */
34
- var ocamlVersion ;
35
-
36
- /**
37
- *
38
- * @param {string } p
39
- */
40
- function addPath ( p ) {
41
- process . env . PATH = p + path . delimiter + process . env . PATH ;
42
- }
43
-
44
31
var ninja_bin_output = path . join ( root_dir , "lib" , "ninja.exe" ) ;
45
32
46
33
/**
@@ -189,7 +176,11 @@ function ensureExists(dir) {
189
176
fs . mkdirSync ( dir ) ;
190
177
}
191
178
}
192
- function install ( ) {
179
+
180
+ /**
181
+ * @param {string } stdlib
182
+ */
183
+ function install ( stdlib ) {
193
184
installDirBy ( runtime_dir , ocaml_dir , function ( file ) {
194
185
var y = path . parse ( file ) ;
195
186
return y . name === "js" || y . ext . includes ( "cm" ) ;
@@ -198,62 +189,13 @@ function install() {
198
189
var y = path . parse ( file ) ;
199
190
return y . ext === ".ml" || y . ext === ".mli" || y . ext . includes ( "cm" ) ;
200
191
} ) ;
201
- var stdlib_dir = path . join (
202
- jscomp_dir ,
203
- ocamlVersion . includes ( "4.02" ) ? "stdlib-402" : "stdlib-406"
204
- ) ;
192
+ var stdlib_dir = path . join ( jscomp_dir , stdlib ) ;
205
193
installDirBy ( stdlib_dir , ocaml_dir , function ( file ) {
206
194
var y = path . parse ( file ) ;
207
195
return y . ext === ".ml" || y . ext === ".mli" || y . ext . includes ( "cm" ) ;
208
196
} ) ;
209
197
}
210
198
211
- /**
212
- * raise an exception if not matched
213
- */
214
- function matchedCompilerExn ( ) {
215
- var output = cp . execSync ( "ocamlc.opt -v" , { encoding : "ascii" } ) ;
216
-
217
- if ( output . indexOf ( ocamlVersion ) >= 0 ) {
218
- console . log ( output ) ;
219
- console . log ( "Use the compiler above" ) ;
220
- } else {
221
- console . log (
222
- "version" ,
223
- output ,
224
- "needed version" ,
225
- ocamlVersion ,
226
- "No matched compiler found, may re-try"
227
- ) ;
228
- throw "" ;
229
- }
230
- }
231
- function tryToProvideOCamlCompiler ( ) {
232
- try {
233
- if ( process . env . BS_ALWAYS_BUILD_YOUR_COMPILER ) {
234
- throw "FORCED TO REBUILD" ;
235
- }
236
- matchedCompilerExn ( ) ;
237
- } catch ( e ) {
238
- console . log (
239
- "Build a local version of OCaml compiler, it may take a couple of minutes"
240
- ) ;
241
- try {
242
- require ( "./buildocaml.js" ) . build ( true ) ;
243
- } catch ( e ) {
244
- console . log ( e . stdout . toString ( ) ) ;
245
- console . log ( e . stderr . toString ( ) ) ;
246
- console . log (
247
- "Building a local version of the OCaml compiler failed, check the output above for more information. A possible problem is that you don't have a compiler installed."
248
- ) ;
249
- throw e ;
250
- }
251
- console . log ( "configure again with local ocaml installed" ) ;
252
- matchedCompilerExn ( ) ;
253
- console . log ( "config finished" ) ;
254
- }
255
- }
256
-
257
199
/**
258
200
*
259
201
* @param {string } sys_extension
@@ -295,36 +237,42 @@ function copyPrebuiltCompilers() {
295
237
}
296
238
297
239
/**
298
- * @returns {boolean }
240
+ * @returns {string|undefined }
299
241
*/
300
242
function checkPrebuiltBscCompiler ( ) {
301
243
try {
302
244
var version = String (
303
245
cp . execFileSync ( path . join ( lib_dir , "bsc" + sys_extension ) , [ "-v" ] )
304
246
) ;
305
247
306
- ocamlVersion = version . substr (
248
+ var myOCamlVersion = version . substr (
307
249
version . indexOf ( ":" ) + 1 ,
308
250
version . lastIndexOf ( " " ) - version . indexOf ( ":" ) - 1
309
251
) ;
310
- console . log ( "checkoutput:" , version , "ocaml version" , ocamlVersion ) ;
252
+ console . log ( "checkoutput:" , version , "ocaml version" , myOCamlVersion ) ;
311
253
console . log ( "Prebuilt compiler works good" ) ;
312
254
313
- return true ;
255
+ return myOCamlVersion ;
314
256
} catch ( e ) {
315
257
console . log ( "No working prebuilt buckleScript compiler" ) ;
316
- return false ;
258
+ if ( is_windows ) {
259
+ throw new Error ( "no prebuilt bsc compiler on windows" ) ;
260
+ }
261
+ return ;
317
262
}
318
263
}
319
-
320
- function buildLibs ( ) {
264
+ /**
265
+ *
266
+ * @param {string } stdlib
267
+ */
268
+ function buildLibs ( stdlib ) {
321
269
ensureExists ( lib_dir ) ;
322
270
ensureExists ( ocaml_dir ) ;
323
271
ensureExists ( path . join ( lib_dir , "js" ) ) ;
324
272
ensureExists ( path . join ( lib_dir , "es6" ) ) ;
325
273
process . env . NINJA_IGNORE_GENERATOR = "true" ;
326
274
var releaseNinja = `
327
- stdlib = ${ ocamlVersion . includes ( "4.06" ) ? " stdlib-406" : "stdlib-402" }
275
+ stdlib = ${ stdlib }
328
276
subninja runtime/release.ninja
329
277
subninja others/release.ninja
330
278
subninja $stdlib/release.ninja
@@ -352,25 +300,35 @@ build all: phony runtime others $stdlib
352
300
console . log ( "Build finished" ) ;
353
301
}
354
302
303
+ /**
304
+ * @returns {string }
305
+ */
355
306
function provideCompiler ( ) {
356
- // FIXME: weird logic
357
- // if (fs.existsSync(path.join(lib_dir,'ocaml','pervasives.cmi'))) {
358
- // console.log('Found pervasives.cmi, assume it was already built')
359
- // return true // already built before
360
- // }
361
- if ( checkPrebuiltBscCompiler ( ) ) {
307
+ var myVersion = checkPrebuiltBscCompiler ( ) ;
308
+ if ( myVersion !== undefined ) {
362
309
copyPrebuiltCompilers ( ) ;
310
+ return myVersion ;
363
311
} else {
364
- ocamlVersion = require ( "./buildocaml.js" ) . getVersionPrefix ( ) ;
365
- addPath ( path . join ( __dirname , ".." , "native" , ocamlVersion , "bin" ) ) ;
366
- // when not having bsc.exe
367
- tryToProvideOCamlCompiler ( ) ;
312
+ myVersion = require ( "./buildocaml.js" ) . getVersionPrefix ( ) ;
313
+ var ocamlcPath = path . join (
314
+ __dirname ,
315
+ ".." ,
316
+ "native" ,
317
+ myVersion ,
318
+ "bin" ,
319
+ "ocamlc.opt"
320
+ ) ;
321
+ if ( ! fs . existsSync ( ocamlcPath ) ) {
322
+ require ( "./buildocaml.js" ) . build ( true ) ;
323
+ } else {
324
+ console . log ( ocamlcPath , "is already there" ) ;
325
+ }
368
326
// Note this ninja file only works under *nix due to the suffix
369
327
// under windows require '.exe'
370
328
var releaseNinja = require ( "./ninjaFactory.js" ) . libNinja ( {
371
329
ocamlopt : "ocamlopt.opt" ,
372
330
ext : ".exe" ,
373
- INCL : ocamlVersion ,
331
+ INCL : myVersion ,
374
332
isWin : is_windows
375
333
} ) ;
376
334
@@ -381,17 +339,15 @@ function provideCompiler() {
381
339
stdio : [ 0 , 1 , 2 ]
382
340
} ) ;
383
341
fs . unlinkSync ( filePath ) ;
342
+ return myVersion ;
384
343
}
385
344
}
386
345
387
346
provideNinja ( ) ;
388
347
389
- if ( is_windows ) {
390
- copyPrebuiltCompilers ( ) ;
391
- } else {
392
- provideCompiler ( ) ;
393
- }
348
+ var ocamlVersion = provideCompiler ( ) ;
394
349
395
- buildLibs ( ) ;
350
+ var stdlib = ocamlVersion . includes ( "4.02" ) ? "stdlib-402" : "stdlib-406" ;
396
351
397
- install ( ) ;
352
+ buildLibs ( stdlib ) ;
353
+ install ( stdlib ) ;
0 commit comments