@@ -62,10 +62,10 @@ function setUpNinja() {
62
62
} ;
63
63
64
64
65
- var ninja_os_path = path . join ( ninja_build_dir , 'ninja' + sys_extension )
65
+ var ninja_os_path = path . join ( ninja_build_dir , 'ninja' + sys_extension )
66
66
if ( fs . existsSync ( ninja_bin_output ) && test_ninja_compatible ( ninja_bin_output ) ) {
67
67
console . log ( "ninja binary is already cached: " , ninja_bin_output )
68
- }
68
+ }
69
69
else if ( fs . existsSync ( ninja_os_path ) ) {
70
70
fs . renameSync ( ninja_os_path , ninja_bin_output )
71
71
if ( test_ninja_compatible ( ninja_bin_output ) ) {
@@ -92,10 +92,7 @@ function matchedCompilerExn() {
92
92
throw ""
93
93
}
94
94
}
95
-
96
-
97
- function non_windows_npm_release ( ) {
98
-
95
+ function tryToProvideOCamlCompiler ( ) {
99
96
try {
100
97
if ( process . env . BS_ALWAYS_BUILD_YOUR_COMPILER ) {
101
98
throw 'FORCED TO REBUILD'
@@ -114,29 +111,52 @@ function non_windows_npm_release() {
114
111
console . log ( 'configure again with local ocaml installed' )
115
112
matchedCompilerExn ( )
116
113
console . log ( "config finished" )
117
- }
118
- child_process . execSync ( make + " world && " + make + " install" , root_dir_config )
114
+ }
119
115
}
120
116
121
- var build_util = require ( './build_util.js' )
122
- setUpNinja ( )
123
- if ( is_windows ) {
124
- process . env . WIN32 = '1'
125
- console . log ( "Installing on Windows" )
117
+ function non_windows_npm_release ( ) {
118
+
119
+ if ( checkPrebuilt ( ) ) {
120
+ child_process . execSync ( make + " libs && " + make + " install" , root_dir_config )
121
+ } else {
122
+ tryToProvideOCamlCompiler ( )
123
+ child_process . execSync ( make + " world && " + make + " install" , root_dir_config )
124
+ }
125
+ }
126
+ function checkPrebuilt ( ) {
127
+ try {
128
+ if ( fs . existsSync ( path . join ( lib_dir , 'bsc.exe' ) ) ) {
129
+ console . log ( 'Found bsc.exe, assume it was already built' )
130
+ return true // already built before
131
+ }
132
+ var version = child_process . execFileSync ( path . join ( lib_dir , 'bsc' + sys_extension ) , [ '-v' ] )
133
+ console . log ( "checkoutput:" , String ( version ) )
134
+ return copyBinToExe ( )
135
+ } catch ( e ) {
136
+ console . log ( "No working prebuilt compiler" )
137
+ return false
138
+ }
139
+ }
140
+
141
+ function copyBinToExe ( ) {
126
142
var indeed_windows_release = 0
127
143
fs . readdirSync ( lib_dir ) . forEach ( function ( f ) {
128
- var last_index = f . lastIndexOf ( '.win' )
144
+ var last_index = f . lastIndexOf ( sys_extension )
129
145
if ( last_index !== - 1 ) {
130
- var new_file = f . slice ( 0 , - 4 ) + ".exe"
146
+ var new_file = f . slice ( 0 , - sys_extension . length ) + ".exe"
131
147
build_util . poor_copy_sync ( path . join ( lib_dir , f ) , path . join ( lib_dir , new_file ) ) ;
132
148
// we do have .win file which means windows npm release
133
149
++ indeed_windows_release
134
150
}
135
151
136
152
} )
137
- if ( indeed_windows_release > 1 ) {
138
- // Make it more fault tolerant
139
- // =1 can still be okay (only ninja.win in this case)
153
+ return indeed_windows_release > 1
154
+ }
155
+ var build_util = require ( './build_util.js' )
156
+
157
+ setUpNinja ( )
158
+ if ( is_windows ) {
159
+ if ( copyBinToExe ( ) ) {
140
160
child_process . execFileSync (
141
161
path . join ( __dirname , 'win_build.bat' ) ,
142
162
{ cwd : path . join ( root_dir , 'jscomp' ) , stdio : [ 0 , 1 , 2 ] }
0 commit comments