forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprebuilt.js
executable file
·112 lines (102 loc) · 3.14 KB
/
prebuilt.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
//@ts-check
var cp = require("child_process");
var path = require("path");
var { is_windows } = require("./config.js");
var root = path.join(__dirname, "..");
var root_config = { cwd: root, stdio: [0, 1, 2], encoding: "utf8" };
process.env.BS_RELEASE_BUILD = "true";
var ocamlVersion = require("./buildocaml.js").getVersionPrefix();
var fs = require("fs");
var hostPlatform = "darwin";
function rebuild() {
cp.execSync(`node ${path.join(__dirname, "ninja.js")} cleanbuild`, {
cwd: __dirname,
stdio: [0, 1, 2]
});
}
var assert = require('assert')
/**
*
* @param {string} src
* @param {(file:string)=>boolean} filter
* @param {string} dest
*/
function installDirBy(src, dest, filter) {
fs.readdir(src, function(err, files) {
if (err === null) {
files.forEach(function(file) {
if (filter(file)) {
var x = path.join(src, file);
var y = path.join(dest, file);
// console.log(x, '----->', y )
fs.copyFile(x, y, (err) => assert.equal(err,null));
}
});
} else {
throw err;
}
});
}
function install() {
var root_dir = path.join(__dirname, "..");
var lib_dir = path.join(root_dir, "lib");
var jscomp_dir = path.join(root_dir, "jscomp");
var runtime_dir = path.join(jscomp_dir, "runtime");
var others_dir = path.join(jscomp_dir, "others");
var ocaml_dir = path.join(lib_dir, "ocaml");
var stdlib_dir = path.join(jscomp_dir, "stdlib-406");
installDirBy(runtime_dir, ocaml_dir, function(file) {
var y = path.parse(file);
return y.name === "js" || y.ext.includes("cm");
// install js.cmi, js.mli
});
installDirBy(others_dir, ocaml_dir, function(file) {
var y = path.parse(file);
return y.ext === ".ml" || y.ext === ".mli" || y.ext.includes("cm");
});
installDirBy(stdlib_dir, ocaml_dir, function(file) {
var y = path.parse(file);
return y.ext === ".ml" || y.ext === ".mli" || y.ext.includes("cm");
});
}
function buildCompiler() {
// for 4.02.3 it relies on OCAMLLIB to find stdlib path
// for 4.06.1 OCAMLLIB is another PATH
// delete process.env.OCAMLLIB
var prebuilt = "prebuilt.ninja";
var content = require("./ninjaFactory.js").libNinja({
ocamlopt: is_windows
? `ocamlopt.opt.exe`
: `../native/${ocamlVersion}/bin/ocamlopt.opt`,
INCL: ocamlVersion,
isWin: is_windows
});
fs.writeFileSync(path.join(root, "lib", prebuilt), content, "ascii");
process.env.PATH = `${path.join(__dirname, "..", process.platform)}${
path.delimiter
}${process.env.PATH}`;
let ninjaPath = `ninja.exe`;
cp.execSync(
`${ninjaPath} -C lib -f ${prebuilt} -v -t clean && ${ninjaPath} -v -C lib -f ${prebuilt}`,
root_config
);
}
if (!is_windows) {
if (!process.argv.includes("-noclean")) {
rebuild();
}
require("./ninja.js").updateRelease();
}
function createOCamlTar() {
if (process.platform === hostPlatform) {
install();
cp.execSync(`git -C ocaml status -uno`, { cwd: root, stdio: [0, 1, 2] });
cp.execSync(
`git -C ocaml archive --format=tar.gz HEAD -o ../vendor/ocaml.tar.gz`,
{ cwd: root, stdio: [0, 1, 2] }
);
}
}
createOCamlTar();
buildCompiler();