Skip to content

Commit 86e7598

Browse files
authored
Merge pull request #4109 from BuckleScript/improve_dev_workflow
improve dev workflow so that no restart needed in most time
2 parents 240edaa + 643d299 commit 86e7598

File tree

3 files changed

+110
-70
lines changed

3 files changed

+110
-70
lines changed

jscomp/test/string_set.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1 "ext/set.cppo.ml"
1+
22
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
33
*
44
* This program is free software: you can redistribute it and/or modify

scripts/ninja.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,12 +1608,14 @@ function nativeNinja() {
16081608
var templateNative = `
16091609
subninja ${getPreprocessorFileName()}
16101610
rule optc
1611-
command = $ocamlopt -safe-string -I +compiler-libs -opaque ${includes} -g -w +6-40-30-23 -warn-error +a-40-30-23 -absname -c $in
1611+
command = $ocamlopt -safe-string -I +compiler-libs -opaque ${includes} -g -w a-50+6-40-30-23 -warn-error +a -absname -c $in
16121612
description = $out : $in
16131613
rule archive
16141614
command = $ocamlopt -a $in -o $out
1615+
description = arcive -> $out
16151616
rule link
16161617
command = $ocamlopt -g -I +compiler-libs $flags $libs $in -o $out
1618+
description = linking -> $out
16171619
rule mk_bsversion
16181620
command = node $in
16191621
generator = true

scripts/tasks.js

Lines changed: 106 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,121 @@
1-
21
//@ts-check
32

4-
process.env["BS_VSCODE"] = '1'
5-
6-
var fs = require('fs')
7-
var path = require('path')
8-
var cp = require('child_process')
9-
var sourceDirs =
10-
['ext',
11-
'common',
12-
'syntax',
13-
'depends',
14-
'core',
15-
'super_errors',
16-
'outcome_printer',
17-
'bsb',
18-
'main',
19-
'others',
20-
'stdlib-406',
21-
'runtime',
22-
'test',
23-
'ounit_tests',
24-
'bsb_helper'
25-
]
3+
process.env["BS_VSCODE"] = "1";
264

5+
var fs = require("fs");
6+
var path = require("path");
7+
var cp = require("child_process");
8+
var sourceDirs = [
9+
"ext",
10+
"common",
11+
"syntax",
12+
"depends",
13+
"core",
14+
"super_errors",
15+
"outcome_printer",
16+
"bsb",
17+
"main",
18+
"others",
19+
"stdlib-406",
20+
"runtime",
21+
"test",
22+
"ounit_tests",
23+
"bsb_helper"
24+
];
2725

28-
var buildAppending = false
29-
var isBuilding = false
30-
var ninjaFile = require('./ninja.js')
31-
var jscompDir = path.join('..','jscomp')
32-
function rebuild(){
33-
console.log(">>>> Start compiling")
34-
if(isBuilding){
35-
buildAppending = true
36-
} else {
37-
isBuilding = true
38-
var p = cp.spawn(ninjaFile.vendorNinjaPath, [], {stdio:['inherit','inherit','pipe']})
39-
p.on('exit',buildFinished)
40-
}
26+
var buildAppending = false;
27+
var isBuilding = false;
28+
var ninjaFile = require("./ninja.js");
29+
var jscompDir = path.join("..", "jscomp");
30+
function rebuild() {
31+
if (isBuilding) {
32+
buildAppending = true;
33+
} else {
34+
console.log(">>>> Start compiling");
35+
isBuilding = true;
36+
var p = cp.spawn(ninjaFile.vendorNinjaPath, [], {
37+
stdio: ["inherit", "inherit", "pipe"]
38+
});
39+
p.on("exit", buildFinished);
40+
}
4141
}
4242
/**
43-
*
43+
*
4444
* @param {number} code
4545
* @param {string} signal
4646
*/
47-
function buildFinished(code,signal){
48-
isBuilding = false
49-
if(buildAppending ) {
50-
buildAppending = false
51-
rebuild()
52-
} else{
53-
if(code !== 0){
54-
console.log(`File "BUILD", line 1, characters 1-1:`)
55-
console.log(`Error: Failed to build`)
56-
}
57-
console.log(">>>> Finish compiling")
58-
// TODO: check ninja exit error code
59-
if(code===0){
60-
// This is not always correct
61-
ninjaFile.updateDev()
62-
}
63-
47+
function buildFinished(code, signal) {
48+
isBuilding = false;
49+
if (buildAppending) {
50+
buildAppending = false;
51+
rebuild();
52+
} else {
53+
if (code !== 0) {
54+
console.log(`File "BUILD", line 1, characters 1-1:`);
55+
console.log(`Error: Failed to build`);
56+
}
57+
console.log(">>>> Finish compiling (options: R|clean|config)");
58+
// TODO: check ninja exit error code
59+
if (code === 0) {
60+
// This is not always correct
61+
ninjaFile.updateDev();
6462
}
65-
63+
}
6664
}
6765
/**
68-
*
69-
* @param {string} eventType
70-
* @param {string} filename
66+
*
67+
* @param {string} eventType
68+
* @param {string} filename
7169
*/
72-
function onSourceChange(eventType, filename){
73-
// console.log('event ', eventType,filename)
74-
if(filename.endsWith('.ml') || filename.endsWith('.mli')){
75-
rebuild()
76-
}
77-
70+
function onSourceChange(eventType, filename) {
71+
// console.log('event ', eventType,filename)
72+
if (filename.endsWith(".ml") || filename.endsWith(".mli")) {
73+
rebuild();
74+
}
7875
}
7976

80-
sourceDirs.forEach(x=>{
81-
fs.watch(path.join(jscompDir,x), 'utf8',onSourceChange)
82-
})
83-
rebuild()
77+
sourceDirs.forEach(x => {
78+
fs.watch(path.join(jscompDir, x), "utf8", onSourceChange);
79+
});
80+
rebuild();
81+
82+
var child_process = require("child_process");
83+
var readline = require("readline");
84+
readline
85+
.createInterface({
86+
input: process.stdin,
87+
output: process.stdout
88+
})
89+
.on("line", input => {
90+
switch (input.toLowerCase()) {
91+
case "r":
92+
rebuild();
93+
break;
94+
case "config":
95+
if (isBuilding) {
96+
console.log(`it's building`);
97+
} else {
98+
isBuilding = true;
99+
child_process
100+
.fork(path.join(__dirname, "ninja.js"), ["config"])
101+
.on("close", () => {
102+
isBuilding = false;
103+
rebuild();
104+
});
105+
}
106+
break;
107+
case "clean":
108+
if (isBuilding) {
109+
console.log(`it's building`);
110+
} else {
111+
isBuilding = true;
112+
child_process
113+
.fork(path.join(__dirname, "ninja.js"), ["cleanbuild"])
114+
.on("close", () => {
115+
isBuilding = false;
116+
});
117+
}
118+
119+
break;
120+
}
121+
});

0 commit comments

Comments
 (0)