@@ -7,20 +7,48 @@ var fs = require('fs')
7
7
8
8
9
9
10
+ /**
11
+ * @type {string }
12
+ */
13
+ var cached = undefined
10
14
// FIXME: this works in CI, but for release build, submodule
11
15
// is carried, so it needs to be fixed
12
16
/**
13
17
* @returns {string }
14
18
*/
15
19
function getVersionPrefix ( ) {
16
- var version = fs . readFileSync ( path . join ( __dirname , '..' , 'ocaml' , 'VERSION' ) , 'ascii' )
17
- return version . substr ( 0 , version . indexOf ( '+' ) )
20
+ if ( cached !== undefined ) {
21
+ return cached
22
+ }
23
+ var file = path . join ( __dirname , '..' , 'ocaml' , 'VERSION' )
24
+ if ( fs . existsSync ( file ) ) {
25
+ var version = fs . readFileSync ( file , 'ascii' )
26
+ cached = version . substr ( 0 , version . indexOf ( '+' ) )
27
+ return cached
28
+ }
29
+
30
+ file = path . join ( __dirname , '..' , 'OCAML_VERSION' )
31
+ if ( fs . existsSync ( file ) ) {
32
+ var version = fs . readFileSync ( file , 'ascii' )
33
+ cached = version . substr ( 0 , version . indexOf ( '+' ) )
34
+ return cached
35
+ }
36
+ throw new Error ( "version file not found" )
37
+
18
38
}
19
39
exports . getVersionPrefix = getVersionPrefix
20
40
21
41
22
42
function build ( ) {
23
- var prefix = path . normalize ( path . join ( __dirname , '..' , 'native' , getVersionPrefix ( ) ) )
43
+ var ocamlSrcDir = path . join ( __dirname , '..' , 'ocaml' )
44
+ if ( ! fs . existsSync ( ocamlSrcDir ) ) {
45
+ fs . mkdirSync ( ocamlSrcDir )
46
+ }
47
+ if ( ! fs . existsSync ( path . join ( ocamlSrcDir , 'VERSION' ) ) ) {
48
+ cp . execSync ( `tar xzvf ocaml.tar.gz` , { cwd : ocamlSrcDir , stdio : [ 0 , 1 , 2 ] } )
49
+ }
50
+
51
+ var prefix = path . normalize ( path . join ( __dirname , '..' , 'native' , getVersionPrefix ( ) ) )
24
52
cp . execSync ( './configure -prefix ' + prefix + ' -no-ocamlbuild -no-curses -no-graph -no-pthread -no-debugger && make clean && make -j9 world.opt && make install '
25
53
, { cwd : path . join ( __dirname , '..' , 'ocaml' ) , stdio : [ 0 , 1 , 2 ] } )
26
54
}
0 commit comments