Skip to content

Commit fc2a403

Browse files
committed
not generating linum by default
1 parent fd31ee1 commit fc2a403

File tree

2 files changed

+139
-9
lines changed

2 files changed

+139
-9
lines changed

jscomp/main/bspack_main.ml

+12-9
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,18 @@ let interface sourcefile =
134134
ast in
135135
ast, content
136136

137+
let emit_line_directive = ref false
137138

138139
let emit out_chan name =
139-
output_string out_chan "#1 \"";
140-
(*Note here we do this is mostly to avoid leaking user's
141-
information, like private path, in the future, we can have
142-
a flag
143-
*)
144-
output_string out_chan (Filename.basename name) ;
145-
output_string out_chan "\"\n"
146-
140+
if !emit_line_directive then begin
141+
output_string out_chan "#1 \"";
142+
(*Note here we do this is mostly to avoid leaking user's
143+
information, like private path, in the future, we can have
144+
a flag
145+
*)
146+
output_string out_chan (Filename.basename name) ;
147+
output_string out_chan "\"\n"
148+
end
147149
let decorate_module
148150
?(module_bound=true)
149151
out_chan base mli_name ml_name mli_content ml_content =
@@ -326,7 +328,8 @@ let define_symbol (s : string) =
326328
| _ -> raise (Arg.Bad ("illegal definition: " ^ s))
327329

328330
let specs : (string * Arg.spec * string) list =
329-
[
331+
[ "-bs-loc", (Arg.Set emit_line_directive),
332+
" Add # linum filename directive";
330333
"-bs-no-implicit-include", (Arg.Set no_implicit_include),
331334
" Not including cwd as search path";
332335
"-prelude-str", (Arg.String set_prelude_str),

scripts/shake.js

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
//@ts-check
2+
// usage : node ./script/shake.js bsb
3+
var cp = require("child_process");
4+
var path = require("path");
5+
var fs = require("fs");
6+
7+
var bsc = path.join(__dirname, "..", process.platform, "bsc");
8+
var ocamlopt = path.join(
9+
__dirname,
10+
"..",
11+
"native",
12+
"4.06.1",
13+
"bin",
14+
"ocamlopt.opt"
15+
);
16+
17+
var base = process.argv[2];
18+
if (base === undefined) {
19+
console.error(`please specifiy a base`);
20+
process.exit(2);
21+
}
22+
var file = `${base}.ml`;
23+
var cwd = path.join(__dirname, "..", "lib", "4.06.1");
24+
25+
// TODO replace it with yours
26+
var esy = `/Users/hongbozhang/git/genType/_esy/default/build/install/default/bin`;
27+
28+
/**
29+
*
30+
* @param {string} file
31+
*/
32+
function dsource(file) {
33+
var output = cp.spawnSync(
34+
`${bsc} -bs-no-builtin-ppx -bs-syntax-only -dsource -c ${file} `,
35+
{
36+
cwd,
37+
encoding: "utf8",
38+
shell: true
39+
}
40+
);
41+
// check output.status
42+
if(output.status === 0){
43+
fs.writeFileSync(path.join(cwd, file), output.stderr);
44+
} else {
45+
console.error(`dsource failure`)
46+
console.error(output.stderr)
47+
process.exit(2)
48+
}
49+
50+
// fs.copyFileSync(path.join(cwd, tmp), path.join(cwd, file));
51+
}
52+
53+
/**
54+
*
55+
* @param {string} file
56+
* @param {string} msg
57+
*/
58+
function checkDiff(file, msg) {
59+
var output = cp.spawnSync(`git diff --quiet ${file}`, { shell: true , encoding : 'utf8',cwd});
60+
if (output.status !== 0) {
61+
var output = cp.spawnSync(`git add ${file} && git commit -m "${msg} for ${file}"`, { shell: true,encoding:'utf8',cwd });
62+
if(output.status !== 0){
63+
console.error(`diff failure for ${file} -- ${msg}`)
64+
process.exit(2)
65+
} else {
66+
console.log(output.stdout)
67+
}
68+
69+
} else {
70+
console.log(`nothing changes to ${file}`);
71+
}
72+
}
73+
/**
74+
*
75+
* @param {string} file
76+
*/
77+
function shake(file) {
78+
var output = cp.spawnSync(
79+
`${bsc} -bs-no-builtin-ppx -bs-syntax-only -dsource -ppx ${esy}/deadcodeppx.exe -c ${file}`,
80+
{
81+
cwd,
82+
encoding: "utf8",
83+
shell: true
84+
}
85+
);
86+
if(output.status !== 0){
87+
console.error(`shake failure`)
88+
console.error(output.stderr)
89+
process.exit(2)
90+
} else {
91+
fs.writeFileSync(path.join(cwd, file), output.stderr);
92+
}
93+
}
94+
95+
/**
96+
*
97+
* @param {string} file
98+
*/
99+
function attachDead(file) {
100+
var output = cp.spawnSync(`${ocamlopt} -bin-annot -c ${file}`, {
101+
cwd,
102+
encoding: "utf8",
103+
shell : true
104+
});
105+
106+
var genType = path.join(esy, "genType.exe");
107+
108+
output = cp.spawnSync(`Write=1 ${genType} -dce-cmt ${base}.cmt`, {
109+
cwd,
110+
encoding: "utf8",
111+
shell: true
112+
});
113+
if(output.status!==0){
114+
console.error(`dce failure`)
115+
console.error(output.stderr)
116+
process.exit(2)
117+
}
118+
// fs.writeFileSync(path.join(cwd,file),output.stderr)
119+
}
120+
121+
122+
// normalize files
123+
dsource(file);
124+
checkDiff(file, `dsource changes`);
125+
attachDead(file);
126+
shake(file);
127+
checkDiff(file, `shake`);

0 commit comments

Comments
 (0)