Skip to content

Commit 846fd1d

Browse files
andywhite37bobzhang
authored andcommitted
Fix buildocaml.js issue with extracting vendor ocaml.tar.gz
The getVersionPrefix function fails if the ocaml directory doesn't exist before attempting the tar xzvf in that directory.
1 parent 39f2664 commit 846fd1d

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

scripts/buildocaml.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ var path = require("path");
55
var fs = require("fs");
66

77
var ocamlSrcDir = path.join(__dirname, "..", "ocaml");
8+
var ocamlVersionFilePath = path.join(ocamlSrcDir, "VERSION");
9+
10+
/**
11+
* Ensures the ocaml folder exists at the root of the project, either from the submodule,
12+
* or by extracting the vendor/ocaml.tar.gz there
13+
*/
14+
function ensureOCamlExistsSync() {
15+
if (!fs.existsSync(ocamlSrcDir)) {
16+
fs.mkdirSync(ocamlSrcDir);
17+
}
18+
if (!fs.existsSync(ocamlVersionFilePath)) {
19+
cp.execSync(`tar xzvf ../vendor/ocaml.tar.gz`, {
20+
cwd: ocamlSrcDir,
21+
stdio: [0, 1, 2]
22+
});
23+
}
24+
}
25+
826
/**
927
* @type {string}
1028
*/
@@ -19,16 +37,10 @@ function getVersionPrefix() {
1937
return cached;
2038
}
2139

22-
var file = path.join(__dirname, "..", "ocaml", "VERSION");
23-
if (!fs.existsSync(file)) {
24-
cp.execSync(`tar xzvf ../vendor/ocaml.tar.gz`, {
25-
cwd: ocamlSrcDir,
26-
stdio: [0, 1, 2]
27-
});
28-
}
40+
ensureOCamlExistsSync();
2941

30-
console.log(`${file} is used in version detection`);
31-
var version = fs.readFileSync(file, "ascii");
42+
console.log(`${ocamlVersionFilePath} is used in version detection`);
43+
var version = fs.readFileSync(ocamlVersionFilePath, "ascii");
3244
cached = version.substr(0, version.indexOf("+"));
3345
return cached;
3446
}
@@ -39,15 +51,7 @@ exports.getVersionPrefix = getVersionPrefix;
3951
* @param {boolean} config
4052
*/
4153
function build(config) {
42-
if (!fs.existsSync(ocamlSrcDir)) {
43-
fs.mkdirSync(ocamlSrcDir);
44-
}
45-
if (!fs.existsSync(path.join(ocamlSrcDir, "VERSION"))) {
46-
cp.execSync(`tar xzvf ../vendor/ocaml.tar.gz`, {
47-
cwd: ocamlSrcDir,
48-
stdio: [0, 1, 2]
49-
});
50-
}
54+
ensureOCamlExistsSync();
5155

5256
var prefix = path.normalize(
5357
path.join(__dirname, "..", "native", getVersionPrefix())

0 commit comments

Comments
 (0)