forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrescript_postinstall.js
62 lines (53 loc) · 1.58 KB
/
rescript_postinstall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//@ts-check
var child_process = require("child_process");
var fs = require("fs");
var supported_os = ["darwin", "freebsd", "linux", "openbsd", "win32"];
if (supported_os.indexOf(process.platform) < 0) {
throw new Error("Not supported platform" + process.platform);
}
var bsc_exe = require("./bin_path").bsc_exe;
var ninja_bin_output = require("./bin_path").ninja_exe;
function checkNinja() {
var vendor_ninja_version = "1.9.0.git";
// sanity check to make sure the binary actually runs. Used for Linux. Too many variants
/**
*
* @param {string} binary_path
*/
function test_ninja_compatible(binary_path) {
var version;
try {
version = child_process
.execSync(JSON.stringify(binary_path) + " --version", {
encoding: "utf8",
stdio: ["pipe", "pipe", "ignore"], // execSync outputs to stdout even if we catch the error. Silent it here
})
.trim();
} catch (e) {
console.log("ninja not compatible?", String(e));
return false;
}
return version === vendor_ninja_version;
}
if (
fs.existsSync(ninja_bin_output) &&
test_ninja_compatible(ninja_bin_output)
) {
console.log(
"ninja binary is already cached and installed: ",
ninja_bin_output
);
} else {
throw new Error("No matching ninja binary found");
}
}
function checkCompiler() {
try {
var version = String(child_process.execFileSync(bsc_exe, ["-v"]));
console.log("ReScript compiler version:", version);
} catch (e) {
throw new Error("No working ReScript compiler");
}
}
checkNinja();
checkCompiler();