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