@@ -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