@@ -160,14 +160,14 @@ function category(target, obj) {
160
160
return obj ;
161
161
}
162
162
/**
163
- *
163
+ * @param { string } file
164
164
* @param {boolean } showAll
165
165
*/
166
- function readTargets ( showAll ) {
166
+ function readTargets ( file , showAll ) {
167
167
let lastEndSeen = 0 ;
168
168
let targets = new Map ( ) ;
169
169
processEntry (
170
- path . join ( "lib" , "bs" , ".ninja_log" ) ,
170
+ file ,
171
171
line => {
172
172
let lineTrim = line . trim ( ) ;
173
173
if ( lineTrim . startsWith ( "#" ) ) {
@@ -200,12 +200,44 @@ function readTargets(showAll) {
200
200
} )
201
201
) ;
202
202
}
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` ;
205
205
console . log ( ` ${ file } is produced, loade it via chrome://tracing/` ) ;
206
206
fs . writeFileSync ( file , JSON . stringify ( jsonArray ) , "utf8" ) ;
207
207
}
208
208
) ;
209
209
}
210
+ let logName = ".ninja_log" ;
210
211
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