@@ -135,7 +135,9 @@ def filter(self, rec):
135
135
136
136
# Since default handler is not created, make sure only specific levels go through to stderr
137
137
TO_STDERR = logging .StreamHandler (sys .stderr )
138
- TO_STDERR .setFormatter (logging .Formatter ("*** %(levelname)s - %(message)s ***" ))
138
+ TO_STDERR .setFormatter (
139
+ logging .Formatter ("*** %(filename)s %(funcName)s:%(lineno)d ***\n %(message)s\n " )
140
+ )
139
141
TO_STDERR .setLevel (logging .NOTSET )
140
142
TO_STDERR .addFilter (
141
143
LoggingFilter (
@@ -305,12 +307,13 @@ def synchronize_utime(stat: Union[os.stat_result, pathlib.Path], *rest: pathlib.
305
307
Retrieve stats from the first 'file' and apply to the 'rest'
306
308
"""
307
309
if not isinstance (stat , os .stat_result ):
308
- logging .debug ("using stats from %s" , stat .name )
309
310
stat = stat .stat ()
311
+ logging .debug (
312
+ "setting mtime=%d for:\n %s" , stat .st_mtime , "\n " .join (f" { p } " for p in rest )
313
+ )
310
314
for p in rest :
311
315
if is_different_utime (stat , p .stat ()):
312
316
os .utime (p , ns = (stat .st_atime_ns , stat .st_mtime_ns ))
313
- logging .debug ("synchronized %s" , p .name )
314
317
315
318
316
319
def as_include_line (p : pathlib .Path ) -> str :
@@ -358,15 +361,15 @@ def ensure_exists_and_empty(*paths: pathlib.Path):
358
361
359
362
if not p .exists () or (p .exists () and p .stat ().st_size ):
360
363
p .write_bytes (b"" )
361
- logging .debug ("placeholder for %s " , p .name )
364
+ logging .debug ("%s is a placeholder " , p .name )
362
365
else :
363
- logging .debug ("up-to-date %s " , p .name )
366
+ logging .debug ("%s is up-to-date" , p .name )
364
367
365
368
366
369
def ensure_normal_time (* paths : pathlib .Path ):
367
370
for p in paths :
368
371
if p .exists () and is_future_utime (p ):
369
- logging .debug ("fixing timestamp of %s " , p .name )
372
+ logging .debug ("%s has timestamp in the future, fixing " , p .name )
370
373
p .touch ()
371
374
372
375
@@ -391,8 +394,10 @@ def write_or_replace(p: pathlib.Path, contents: str, encoding=FILE_ENCODING) ->
391
394
392
395
if contents != actual :
393
396
p .write_text (contents , encoding = encoding )
397
+ logging .debug ("%s contents written" , p .name )
394
398
return True
395
399
400
+ logging .debug ("%s is up-to-date" , p .name )
396
401
return False
397
402
398
403
@@ -427,12 +432,7 @@ def ensure_common_header_bound(ctx: Context):
427
432
"""
428
433
Record currently used command-line options file
429
434
"""
430
- if write_or_replace (
431
- ctx .common_header , as_arduino_sketch_quoted_header (ctx .build_opt )
432
- ):
433
- logging .debug ("wrote to %s" , ctx .common_header .name )
434
- else :
435
- logging .debug ("up-to-date %s" , ctx .build_opt .name )
435
+ write_or_replace (ctx .common_header , as_arduino_sketch_quoted_header (ctx .build_opt ))
436
436
437
437
438
438
def make_build_opt_name (ctx : Context , debug : bool ) -> str :
@@ -460,18 +460,7 @@ def ensure_build_opt_written(ctx: Context, buffer: io.StringIO):
460
460
for p in includes :
461
461
buffer .write (f"{ as_include_line (p )} \n " )
462
462
463
- value = buffer .getvalue ()
464
-
465
- if (
466
- not ctx .build_opt .exists ()
467
- or is_different_utime (ctx .build_sketch_header , ctx .build_opt )
468
- or ctx .build_opt .read_text (encoding = DEFAULT_ENCODING ) != value
469
- ):
470
- ctx .build_opt .parent .mkdir (parents = True , exist_ok = True )
471
- ctx .build_opt .write_text (value , encoding = DEFAULT_ENCODING )
472
- logging .debug ("wrote to %s" , ctx .build_opt .name )
473
- else :
474
- logging .debug ("up-to-date %s" , ctx .build_opt .name )
463
+ write_or_replace (ctx .build_opt , buffer .getvalue (), encoding = DEFAULT_ENCODING )
475
464
476
465
477
466
def maybe_empty_or_missing (p : pathlib .Path ):
@@ -525,14 +514,13 @@ def main_build(args: argparse.Namespace):
525
514
)
526
515
527
516
if args .debug :
528
- logging .debug ("using the following build context" )
529
- for field in dataclasses .fields (ctx ):
530
- logging .debug (
531
- " %s %s %s" ,
532
- field .name ,
533
- getattr (ctx , field .name ),
534
- field .metadata ["help" ],
535
- )
517
+ logging .debug (
518
+ "Build Context:\n %s" ,
519
+ "" .join (
520
+ f' "{ field .name } " at { getattr (ctx , field .name )} - { field .metadata ["help" ]} \n '
521
+ for field in dataclasses .fields (ctx )
522
+ ),
523
+ )
536
524
537
525
# notify when other files similar to .globals.h are in the sketch directory
538
526
other_build_options = check_other_build_options (ctx .source_sketch_header )
@@ -558,19 +546,19 @@ def main_build(args: argparse.Namespace):
558
546
build_opt_buffer = io .StringIO ()
559
547
560
548
try :
561
- logging .debug ("searching for %s" , name )
562
549
extract_build_opt_from_path (build_opt_buffer , name , ctx .source_sketch_header )
563
550
except ParsingException as e :
564
- raise e from None
551
+ raise
565
552
566
553
# when command-line options were not created / found, it means the same thing as empty or missing .globals.h
567
554
if not len (build_opt_buffer .getvalue ()):
568
555
build_with_minimal_build_opt (ctx )
569
556
return
570
557
571
- logging .debug ("preparing %s" , ctx .build_opt .name )
572
- for line in build_opt_buffer :
573
- logging .debug (" %s" , line )
558
+ logging .info (
559
+ "\n Extra command-line options:\n %s" ,
560
+ "\n " .join (f" { line } " for line in build_opt_buffer .getvalue ().split ("\n " )),
561
+ )
574
562
575
563
# at this point, it is necessary to synchronize timestamps of every file
576
564
ensure_build_opt_written (ctx , build_opt_buffer )
0 commit comments