Skip to content

Commit 2458328

Browse files
committed
Fall back to build from source when prebuilt not available
1 parent 9cd159a commit 2458328

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

scripts/buildocaml.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,48 @@ var fs = require('fs')
77

88

99

10+
/**
11+
* @type {string}
12+
*/
13+
var cached = undefined
1014
// FIXME: this works in CI, but for release build, submodule
1115
// is carried, so it needs to be fixed
1216
/**
1317
* @returns{string}
1418
*/
1519
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+
1838
}
1939
exports.getVersionPrefix = getVersionPrefix
2040

2141

2242
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()))
2452
cp.execSync('./configure -prefix ' + prefix + ' -no-ocamlbuild -no-curses -no-graph -no-pthread -no-debugger && make clean && make -j9 world.opt && make install '
2553
, { cwd: path.join(__dirname, '..', 'ocaml'), stdio: [0, 1, 2] })
2654
}

scripts/prebuilt.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ts-check
2-
var child_process = require('child_process')
2+
var cp = require('child_process')
33
var path = require('path')
44
var {sys_extension, is_windows} = require('./config.js')
55

@@ -10,6 +10,7 @@ process.env.BS_RELEASE_BUILD = 'true'
1010

1111
var version = require('./buildocaml.js').getVersionPrefix()
1212
var fs = require('fs')
13+
var hostPlatform = 'darwin'
1314
function buildCompiler() {
1415
var prebuilt = 'prebuilt.ninja'
1516
var content = `
@@ -19,11 +20,22 @@ INCL = ${version}
1920
include body.ninja
2021
`
2122
fs.writeFileSync(path.join(root,'lib',prebuilt),content,'ascii')
22-
child_process.execSync(`ninja -C lib -f ${prebuilt} -t clean && ninja -C lib -f ${prebuilt}`,root_config)
23+
cp.execSync(`ninja -C lib -f ${prebuilt} -t clean && ninja -C lib -f ${prebuilt}`,root_config)
2324
}
2425
if(!is_windows){
2526
require('./ninja.js').updateRelease()
2627
}
27-
28+
var os = require('os')
29+
function createOCamlTar(){
30+
if(os.platform ()=== hostPlatform){
31+
cp.execSync(`git -C ocaml status -uno`, { cwd: root, stdio: [0, 1, 2] })
32+
cp.execSync(`git -C ocaml archive --format=tar.gz HEAD -o ../ocaml.tar.gz`,
33+
{ cwd: root, stdio: [0, 1, 2] }
34+
)
35+
fs.copyFileSync(path.join(root,'ocaml','VERSION'),path.join(root,'OCAML_VERSION'))
36+
}
37+
}
38+
createOCamlTar()
2839
buildCompiler()
2940

41+
//

0 commit comments

Comments
 (0)