Skip to content

Commit 97fcbd0

Browse files
authored
Merge pull request #4131 from BuckleScript/bstracing
support bstracing -C dir
2 parents 9a8cdc1 + 39af0f2 commit 97fcbd0

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,4 @@ native/
142142
vendor/ocaml
143143
jscomp/.lsp
144144
.vscode/launch.json
145+
tracing*.json

lib/bstracing

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ function category(target, obj) {
160160
return obj;
161161
}
162162
/**
163-
*
163+
* @param {string} file
164164
* @param {boolean} showAll
165165
*/
166-
function readTargets(showAll) {
166+
function readTargets(file, showAll) {
167167
let lastEndSeen = 0;
168168
let targets = new Map();
169169
processEntry(
170-
path.join("lib", "bs", ".ninja_log"),
170+
file,
171171
line => {
172172
let lineTrim = line.trim();
173173
if (lineTrim.startsWith("#")) {
@@ -200,12 +200,44 @@ function readTargets(showAll) {
200200
})
201201
);
202202
}
203-
let curDate = new Date ()
204-
let file = `tracing_${curDate.getHours()}_${curDate.getMinutes()}_${curDate.getSeconds()}.json`
203+
let curDate = new Date();
204+
let file = `tracing_${curDate.getHours()}_${curDate.getMinutes()}_${curDate.getSeconds()}.json`;
205205
console.log(` ${file} is produced, loade it via chrome://tracing/`);
206206
fs.writeFileSync(file, JSON.stringify(jsonArray), "utf8");
207207
}
208208
);
209209
}
210+
let logName = ".ninja_log";
210211

211-
readTargets(false);
212+
/**
213+
* @type {string}
214+
*/
215+
var file;
216+
/**
217+
*
218+
* @param ps {string[]}
219+
*/
220+
function tryLocation(ps) {
221+
for (let p of ps) {
222+
let log = path.join(p, logName);
223+
if (fs.existsSync(log)) {
224+
file = log;
225+
return;
226+
}
227+
}
228+
console.error(
229+
`no .ninja_log found in specified paths, make sure you set bstracing to the proper directory`
230+
);
231+
process.exit(2);
232+
}
233+
{
234+
let index = process.argv.indexOf(`-C`);
235+
if (index >= 0) {
236+
let p = process.argv[index + 1];
237+
tryLocation([p, path.join(p, "lib", "bs")]);
238+
} else {
239+
tryLocation([".", path.join("lib", "bs")]);
240+
}
241+
}
242+
console.log("loading build log", file, "is used");
243+
readTargets(file, false);

0 commit comments

Comments
 (0)