Skip to content

Commit d0b0cbb

Browse files
authored
Merge pull request #4212 from BuckleScript/fix_editor_tooling
fix editor tooling
2 parents a720330 + 24145a7 commit d0b0cbb

File tree

8 files changed

+132
-91
lines changed

8 files changed

+132
-91
lines changed

jscomp/bsb/bsb_merlin_gen.ml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,20 @@ let output_merlin_namespace buffer ns=
8787
Buffer.add_string buffer "-open ";
8888
Buffer.add_string buffer x
8989

90+
(* Literals.dash_nostdlib::
91+
FIX editor tooling, note merlin does not need -nostdlib since we added S and B
92+
RLS will add -I for those cmi files,
93+
Some consistency check is needed
94+
Unless we tell the editor to peek those cmi for auto-complete and others for building which is too
95+
complicated
96+
*)
9097
let bsc_flg_to_merlin_ocamlc_flg bsc_flags =
91-
merlin_flg ^
92-
String.concat Ext_string.single_space
93-
(List.filter (fun x -> not (Ext_string.starts_with x bs_flg_prefix )) (
94-
Literals.dash_nostdlib::bsc_flags))
98+
let flags = (List.filter (fun x -> not (Ext_string.starts_with x bs_flg_prefix )) (
99+
bsc_flags)) in
100+
if flags <> [] then
101+
merlin_flg ^
102+
String.concat Ext_string.single_space flags
103+
else ""
95104

96105
(* No need for [-warn-error] in merlin *)
97106
let warning_to_merlin_flg (warning: Bsb_warning.t ) : string=

jscomp/bsb/bsb_theme_init.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let run_npm_link cwd dirname =
7676
exit 2
7777
end
7878
else
79-
if Ext_sys.is_windows_or_cygwin then
79+
(* if Ext_sys.is_windows_or_cygwin then *)
8080
begin
8181
let npm_link = "npm link bs-platform" in
8282
let exit_code = Sys.command npm_link in
@@ -86,7 +86,7 @@ let run_npm_link cwd dirname =
8686
exit exit_code
8787
end
8888
end
89-
else
89+
(* else
9090
begin
9191
(* symlink bs-platform and bsb,bsc,bsrefmt to .bin directory
9292
we did not run npm link bs-platform for efficiency reasons
@@ -104,7 +104,7 @@ let run_npm_link cwd dirname =
104104
Unix.symlink
105105
(Filename.dirname (Filename.dirname Sys.executable_name))
106106
(Filename.concat "node_modules" Bs_version.package_name)
107-
end
107+
end *)
108108

109109
let enter_dir cwd x action =
110110
Unix.chdir x ;

jscomp/main/cmij_main.ml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ let from_cmi (files : string list) (output_file : string) =
104104
let content =
105105
Marshal.to_string
106106
cmi
107-
(* cmi_name, crcs can be saved, but only a tiny bit *)
108-
(* (cmi.cmi_sign) *)
109-
(* (Array.of_list cmi.cmi_sign) *)
110-
(* ({ with
111-
(* cmi_crcs = [] *)
112-
cmi_flags = []
113-
}) *)
114107
[] in
115108
Printf.sprintf {|%S (* %d *)|} module_name (String.length content) ,
116109
Printf.sprintf {|(* %s *) %S|} module_name content) in
@@ -141,6 +134,14 @@ let stdlib = "stdlib-406"
141134
let (//) = Filename.concat
142135
let (|~) = Ext_string.contain_substring
143136

137+
let cmi_target_file = (Filename.concat "main" "builtin_cmi_datasets.ml")
138+
let release_cmi = Array.exists ((=) "-release") Sys.argv
139+
let () =
140+
if release_cmi then begin
141+
print_endline "collecting cmi from ../lib/ocaml in release mode" ;
142+
try Sys.remove cmi_target_file with _ ->
143+
Format.fprintf Format.err_formatter "failed to remove %s@." cmi_target_file
144+
end
144145
let () =
145146
let cmj_files =
146147
(
@@ -150,14 +151,18 @@ let () =
150151
from_cmj cmj_files
151152
(Filename.concat "main" "builtin_cmj_datasets.ml");
152153
let cmi_files =
153-
"runtime" // "js.cmi" ::
154-
(get_files Literals.suffix_cmi stdlib @
155-
get_files Literals.suffix_cmi "others" )
156-
|> List.filter (fun x ->
157-
x|~ "js_internalOO" ||
158-
x|~ "camlinternal" ||
159-
not (x |~ "internal"))
154+
if release_cmi then
155+
get_files Literals.suffix_cmi (".."//"lib"//"ocaml")
156+
else
157+
"runtime" // "js.cmi" ::
158+
(get_files Literals.suffix_cmi stdlib @
159+
get_files Literals.suffix_cmi "others" )
160+
|> List.filter (fun x ->
161+
x|~ "js_internalOO" ||
162+
x|~ "camlinternal" ||
163+
not (x |~ "internal"))
160164
in
161-
from_cmi cmi_files
162-
(Filename.concat "main" "builtin_cmi_datasets.ml")
165+
from_cmi
166+
cmi_files
167+
cmi_target_file
163168

lib/4.06.1/bsb.ml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11905,11 +11905,20 @@ let output_merlin_namespace buffer ns=
1190511905
Buffer.add_string buffer "-open ";
1190611906
Buffer.add_string buffer x
1190711907

11908+
(* Literals.dash_nostdlib::
11909+
FIX editor tooling, note merlin does not need -nostdlib since we added S and B
11910+
RLS will add -I for those cmi files,
11911+
Some consistency check is needed
11912+
Unless we tell the editor to peek those cmi for auto-complete and others for building which is too
11913+
complicated
11914+
*)
1190811915
let bsc_flg_to_merlin_ocamlc_flg bsc_flags =
11909-
merlin_flg ^
11910-
String.concat Ext_string.single_space
11911-
(List.filter (fun x -> not (Ext_string.starts_with x bs_flg_prefix )) (
11912-
Literals.dash_nostdlib::bsc_flags))
11916+
let flags = (List.filter (fun x -> not (Ext_string.starts_with x bs_flg_prefix )) (
11917+
bsc_flags)) in
11918+
if flags <> [] then
11919+
merlin_flg ^
11920+
String.concat Ext_string.single_space flags
11921+
else ""
1191311922

1191411923
(* No need for [-warn-error] in merlin *)
1191511924
let warning_to_merlin_flg (warning: Bsb_warning.t ) : string=
@@ -16270,7 +16279,7 @@ let run_npm_link cwd dirname =
1627016279
exit 2
1627116280
end
1627216281
else
16273-
if Ext_sys.is_windows_or_cygwin then
16282+
(* if Ext_sys.is_windows_or_cygwin then *)
1627416283
begin
1627516284
let npm_link = "npm link bs-platform" in
1627616285
let exit_code = Sys.command npm_link in
@@ -16280,7 +16289,7 @@ let run_npm_link cwd dirname =
1628016289
exit exit_code
1628116290
end
1628216291
end
16283-
else
16292+
(* else
1628416293
begin
1628516294
(* symlink bs-platform and bsb,bsc,bsrefmt to .bin directory
1628616295
we did not run npm link bs-platform for efficiency reasons
@@ -16298,7 +16307,7 @@ let run_npm_link cwd dirname =
1629816307
Unix.symlink
1629916308
(Filename.dirname (Filename.dirname Sys.executable_name))
1630016309
(Filename.concat "node_modules" Bs_version.package_name)
16301-
end
16310+
end *)
1630216311

1630316312
let enter_dir cwd x action =
1630416313
Unix.chdir x ;

lib/4.06.1/unstable/bsb_native.ml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12027,11 +12027,20 @@ let output_merlin_namespace buffer ns=
1202712027
Buffer.add_string buffer "-open ";
1202812028
Buffer.add_string buffer x
1202912029

12030+
(* Literals.dash_nostdlib::
12031+
FIX editor tooling, note merlin does not need -nostdlib since we added S and B
12032+
RLS will add -I for those cmi files,
12033+
Some consistency check is needed
12034+
Unless we tell the editor to peek those cmi for auto-complete and others for building which is too
12035+
complicated
12036+
*)
1203012037
let bsc_flg_to_merlin_ocamlc_flg bsc_flags =
12031-
merlin_flg ^
12032-
String.concat Ext_string.single_space
12033-
(List.filter (fun x -> not (Ext_string.starts_with x bs_flg_prefix )) (
12034-
Literals.dash_nostdlib::bsc_flags))
12038+
let flags = (List.filter (fun x -> not (Ext_string.starts_with x bs_flg_prefix )) (
12039+
bsc_flags)) in
12040+
if flags <> [] then
12041+
merlin_flg ^
12042+
String.concat Ext_string.single_space flags
12043+
else ""
1203512044

1203612045
(* No need for [-warn-error] in merlin *)
1203712046
let warning_to_merlin_flg (warning: Bsb_warning.t ) : string=
@@ -16392,7 +16401,7 @@ let run_npm_link cwd dirname =
1639216401
exit 2
1639316402
end
1639416403
else
16395-
if Ext_sys.is_windows_or_cygwin then
16404+
(* if Ext_sys.is_windows_or_cygwin then *)
1639616405
begin
1639716406
let npm_link = "npm link bs-platform" in
1639816407
let exit_code = Sys.command npm_link in
@@ -16402,7 +16411,7 @@ let run_npm_link cwd dirname =
1640216411
exit exit_code
1640316412
end
1640416413
end
16405-
else
16414+
(* else
1640616415
begin
1640716416
(* symlink bs-platform and bsb,bsc,bsrefmt to .bin directory
1640816417
we did not run npm link bs-platform for efficiency reasons
@@ -16420,7 +16429,7 @@ let run_npm_link cwd dirname =
1642016429
Unix.symlink
1642116430
(Filename.dirname (Filename.dirname Sys.executable_name))
1642216431
(Filename.concat "node_modules" Bs_version.package_name)
16423-
end
16432+
end *)
1642416433

1642516434
let enter_dir cwd x action =
1642616435
Unix.chdir x ;

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)