14
14
var cp = require ( 'child_process' )
15
15
var fs = require ( 'fs' )
16
16
var path = require ( 'path' )
17
- // var os = require('os')
18
-
19
- // var os_type = os.type()
20
17
var root_dir = path . join ( __dirname , '..' )
21
18
var lib_dir = path . join ( root_dir , 'lib' )
22
19
var jscomp_dir = path . join ( root_dir , 'jscomp' )
23
20
var runtime_dir = path . join ( jscomp_dir , 'runtime' )
24
21
var others_dir = path . join ( jscomp_dir , 'others' )
25
22
var stdlib_dir = path . join ( jscomp_dir , 'stdlib-402' )
26
- var root_dir_config = { cwd : root_dir , stdio : [ 0 , 1 , 2 ] }
27
23
28
- // var dest_bin = path.join(root_dir, 'lib')
29
- // var dest_lib = path.join(root_dir, 'lib', 'ocaml')
30
24
31
25
var ocaml_dir = path . join ( lib_dir , 'ocaml' )
32
26
var config = require ( './config.js' )
@@ -43,7 +37,13 @@ process.env.PATH =
43
37
process . env . PATH
44
38
45
39
var ninja_bin_output = path . join ( root_dir , 'lib' , 'ninja.exe' )
46
- // Make sure `ninja_bin_output` exists
40
+
41
+
42
+ /**
43
+ * Make sure `ninja_bin_output` exists
44
+ * The installation of `ninja.exe` is re-entrant, since we always pre-check if it is already installed
45
+ * This is less problematic since `ninja.exe` is very stable
46
+ */
47
47
function provideNinja ( ) {
48
48
var vendor_ninja_version = '1.8.2'
49
49
var ninja_source_dir = path . join ( root_dir , 'vendor' , 'ninja' )
@@ -77,7 +77,7 @@ function provideNinja() {
77
77
78
78
var ninja_os_path = path . join ( ninja_source_dir , 'snapshot' , 'ninja' + sys_extension )
79
79
if ( fs . existsSync ( ninja_bin_output ) && test_ninja_compatible ( ninja_bin_output ) ) {
80
- console . log ( "ninja binary is already cached: " , ninja_bin_output )
80
+ console . log ( "ninja binary is already cached and installed : " , ninja_bin_output )
81
81
}
82
82
else if ( fs . existsSync ( ninja_os_path ) ) {
83
83
if ( fs . copyFileSync ) {
@@ -213,18 +213,10 @@ function tryToProvideOCamlCompiler() {
213
213
}
214
214
}
215
215
216
- function renamePrebuiltCompilers ( ) {
217
- fs . readdirSync ( lib_dir ) . forEach ( function ( f ) {
218
- var last_index = f . lastIndexOf ( sys_extension )
219
- if ( last_index !== - 1 ) {
220
- var new_file = f . slice ( 0 , - sys_extension . length ) + ".exe"
221
- var x = path . join ( lib_dir , f )
222
- var y = path . join ( lib_dir , new_file )
223
- console . log ( x , '-->' , y )
224
- fs . renameSync ( x , y ) ;
225
- // we do have .win file which means windows npm release
226
- }
227
- } )
216
+ function copyPrebuiltCompilers ( ) {
217
+ cp . execFileSync ( ninja_bin_output ,
218
+ [ "-f" , "copy" + sys_extension + ".ninja" ] ,
219
+ { cwd : lib_dir , stdio : [ 0 , 1 , 2 ] } )
228
220
}
229
221
230
222
/**
@@ -235,7 +227,7 @@ function checkPrebuilt() {
235
227
var version = cp . execFileSync ( path . join ( lib_dir , 'bsc' + sys_extension ) , [ '-v' ] )
236
228
console . log ( "checkoutput:" , String ( version ) )
237
229
console . log ( "Prebuilt compiler works good" )
238
- renamePrebuiltCompilers ( )
230
+
239
231
return true
240
232
} catch ( e ) {
241
233
console . log ( "No working prebuilt buckleScript compiler" )
@@ -255,7 +247,10 @@ function provideCompiler() {
255
247
console . log ( 'Found pervasives.cmi, assume it was already built' )
256
248
return true // already built before
257
249
}
258
- if ( ! checkPrebuilt ( ) ) {
250
+ if ( checkPrebuilt ( ) ) {
251
+ copyPrebuiltCompilers ( )
252
+ }
253
+ else {
259
254
// when not having bsc.exe
260
255
tryToProvideOCamlCompiler ( )
261
256
// Note this ninja file only works under *nix due to the suffix
@@ -268,7 +263,7 @@ function provideCompiler() {
268
263
provideNinja ( )
269
264
270
265
if ( is_windows ) {
271
- renamePrebuiltCompilers ( )
266
+ copyPrebuiltCompilers ( )
272
267
} else {
273
268
provideCompiler ( )
274
269
}
0 commit comments