Skip to content

Commit 43dbf43

Browse files
committed
fix editor tooling
1 parent d0e834d commit 43dbf43

File tree

3 files changed

+63
-54
lines changed

3 files changed

+63
-54
lines changed

scripts/install.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,5 @@ var stdlib = ocamlVersion.includes("4.02") ? "stdlib-402" : "stdlib-406";
224224

225225
if (process.env.BS_TRAVIS_CI) {
226226
buildLibs(stdlib);
227+
require('./installUtils.js').install()
227228
}

scripts/installUtils.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env node
2+
//@ts-check
3+
var fs = require("fs");
4+
var path = require("path");
5+
var assert = require("assert");
6+
/**
7+
*
8+
* @param {string} src
9+
* @param {(file:string)=>boolean} filter
10+
* @param {string} dest
11+
*/
12+
function installDirBy(src, dest, filter) {
13+
fs.readdir(src, function(err, files) {
14+
if (err === null) {
15+
files.forEach(function(file) {
16+
if (filter(file)) {
17+
var x = path.join(src, file);
18+
var y = path.join(dest, file);
19+
// console.log(x, '----->', y )
20+
fs.copyFile(x, y, err => assert.equal(err, null));
21+
}
22+
});
23+
} else {
24+
throw err;
25+
}
26+
});
27+
}
28+
29+
function install() {
30+
var root_dir = path.join(__dirname, "..");
31+
var lib_dir = path.join(root_dir, "lib");
32+
var jscomp_dir = path.join(root_dir, "jscomp");
33+
var runtime_dir = path.join(jscomp_dir, "runtime");
34+
var others_dir = path.join(jscomp_dir, "others");
35+
var ocaml_dir = path.join(lib_dir, "ocaml");
36+
var stdlib_dir = path.join(jscomp_dir, "stdlib-406");
37+
if (!fs.existsSync(ocaml_dir)) {
38+
fs.mkdirSync(ocaml_dir);
39+
}
40+
// sync up with cmij_main.ml
41+
installDirBy(runtime_dir, ocaml_dir, function(file) {
42+
var y = path.parse(file);
43+
return y.name === "js" && y.ext !== ".cmj";
44+
// install js.cmi, js.mli
45+
});
46+
47+
// for merlin or other IDE
48+
var installed_suffixes = [".ml", ".mli", ".cmi", ".cmt", ".cmti"];
49+
installDirBy(others_dir, ocaml_dir, function(file) {
50+
var y = path.parse(file);
51+
if (y.ext === ".cmi") {
52+
return !y.base.includes("Belt_internal");
53+
}
54+
return installed_suffixes.includes(y.ext);
55+
});
56+
installDirBy(stdlib_dir, ocaml_dir, function(file) {
57+
var y = path.parse(file);
58+
return installed_suffixes.includes(y.ext);
59+
});
60+
}
61+
exports.install = install;

scripts/prebuilt.js

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,6 @@ function rebuild() {
1717
stdio: [0, 1, 2]
1818
});
1919
}
20-
var assert = require("assert");
21-
/**
22-
*
23-
* @param {string} src
24-
* @param {(file:string)=>boolean} filter
25-
* @param {string} dest
26-
*/
27-
function installDirBy(src, dest, filter) {
28-
fs.readdir(src, function(err, files) {
29-
if (err === null) {
30-
files.forEach(function(file) {
31-
if (filter(file)) {
32-
var x = path.join(src, file);
33-
var y = path.join(dest, file);
34-
// console.log(x, '----->', y )
35-
fs.copyFile(x, y, err => assert.equal(err, null));
36-
}
37-
});
38-
} else {
39-
throw err;
40-
}
41-
});
42-
}
43-
44-
function install() {
45-
var root_dir = path.join(__dirname, "..");
46-
var lib_dir = path.join(root_dir, "lib");
47-
var jscomp_dir = path.join(root_dir, "jscomp");
48-
var runtime_dir = path.join(jscomp_dir, "runtime");
49-
var others_dir = path.join(jscomp_dir, "others");
50-
var ocaml_dir = path.join(lib_dir, "ocaml");
51-
var stdlib_dir = path.join(jscomp_dir, "stdlib-406");
52-
if(!fs.existsSync(ocaml_dir)){
53-
fs.mkdirSync(ocaml_dir)
54-
}
55-
// sync up with cmij_main.ml
56-
installDirBy(runtime_dir, ocaml_dir, function(file) {
57-
var y = path.parse(file);
58-
return y.name === "js" && y.ext !== ".cmj";
59-
// install js.cmi, js.mli
60-
});
61-
62-
// for merlin or other IDE
63-
var installed_suffixes = [".ml", ".mli", ".cmi",".cmt", ".cmti"];
64-
installDirBy(others_dir, ocaml_dir, function(file) {
65-
var y = path.parse(file);
66-
return installed_suffixes.includes(y.ext);
67-
});
68-
installDirBy(stdlib_dir, ocaml_dir, function(file) {
69-
var y = path.parse(file);
70-
return installed_suffixes.includes(y.ext)
71-
});
72-
}
7320

7421
function buildCompiler() {
7522
// for 4.02.3 it relies on OCAMLLIB to find stdlib path
@@ -104,7 +51,7 @@ if (!is_windows) {
10451

10552
function createOCamlTar() {
10653
if (process.platform === hostPlatform) {
107-
install();
54+
require("./installUtils.js").install();
10855
cp.execSync(`git -C ocaml status -uno`, { cwd: root, stdio: [0, 1, 2] });
10956
cp.execSync(
11057
`git -C ocaml archive --format=tar.gz HEAD -o ../vendor/ocaml.tar.gz`,

0 commit comments

Comments
 (0)