File tree Expand file tree Collapse file tree 3 files changed +33
-29
lines changed Expand file tree Collapse file tree 3 files changed +33
-29
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,25 @@ var fs = require("fs");
7
7
var ocamlSrcDir = path . join ( __dirname , ".." , "native" ) ;
8
8
var ocamlVersionFilePath = path . join ( ocamlSrcDir , "VERSION" ) ;
9
9
10
+ /**
11
+ * Checks whether an OCaml compiler is available.
12
+ * If it is, we do not need to build one from the vendored sources.
13
+ */
14
+ function checkEnvCompiler ( ) {
15
+ try {
16
+ var o = cp . execSync ( `ocamlopt.opt -version` , {
17
+ encoding : "utf-8" ,
18
+ } ) ;
19
+ console . log ( "checking env compiler" ) ;
20
+ console . log ( o ) ;
21
+ return true ;
22
+ } catch ( e ) {
23
+ console . log ( e ) ;
24
+ return false ;
25
+ }
26
+ }
27
+ exports . checkEnvCompiler = checkEnvCompiler ;
28
+
10
29
/**
11
30
* Ensures the ocaml folder exists at the root of the project, either from the submodule,
12
31
* or by extracting the vendor/ocaml.tar.gz there
Original file line number Diff line number Diff line change @@ -42,15 +42,19 @@ if (all) {
42
42
}
43
43
44
44
function init ( ) {
45
- var vendorOCamlPath = path . join (
46
- __dirname ,
47
- ".." ,
48
- "native" ,
49
- require ( "./buildocaml.js" ) . getVersionPrefix ( ) ,
50
- "bin"
51
- ) ;
52
-
53
- process . env [ "PATH" ] = vendorOCamlPath + path . delimiter + process . env [ "PATH" ] ;
45
+ if ( ! require ( "./buildocaml.js" ) . checkEnvCompiler ( ) ) {
46
+ // No compiler available on path.
47
+ // Assume that we built the compiler from source beforehand and add it to the path.
48
+ var vendorOCamlPath = path . join (
49
+ __dirname ,
50
+ ".." ,
51
+ "native" ,
52
+ require ( "./buildocaml.js" ) . getVersionPrefix ( ) ,
53
+ "bin"
54
+ ) ;
55
+
56
+ process . env [ "PATH" ] = vendorOCamlPath + path . delimiter + process . env [ "PATH" ] ;
57
+ }
54
58
55
59
var ninjaPath = path . join ( __dirname , ".." , process . platform , "ninja.exe" ) ;
56
60
Original file line number Diff line number Diff line change @@ -178,25 +178,6 @@ o all: phony runtime others $stdlib
178
178
console . log ( "Build finished" ) ;
179
179
}
180
180
181
- /**
182
- * works only on *unix
183
- * used for dev environment or our prebuilt compiler
184
- * does not work for such version
185
- * @returns {boolean }
186
- */
187
- function checkEnvCompiler ( ) {
188
- try {
189
- var o = child_process . execSync ( `ocamlopt.opt -version` , {
190
- encoding : "utf-8" ,
191
- } ) ;
192
- console . log ( "checking env compiler" ) ;
193
- console . log ( o ) ;
194
- return true ;
195
- } catch ( e ) {
196
- console . log ( e ) ;
197
- return false ;
198
- }
199
- }
200
181
/**
201
182
* @returns {string }
202
183
*/
@@ -207,7 +188,7 @@ function provideCompiler() {
207
188
} else {
208
189
var ocamlopt = "ocamlopt.opt" ;
209
190
myVersion = "4.06.1" ;
210
- if ( ! checkEnvCompiler ( ) ) {
191
+ if ( ! require ( "./buildocaml.js" ) . checkEnvCompiler ( ) ) {
211
192
// no compiler available
212
193
var prefix = require ( "./buildocaml.js" ) . build ( true ) ;
213
194
ocamlopt = `${ prefix } /bin/${ ocamlopt } `
You can’t perform that action at this time.
0 commit comments