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