@@ -135,7 +135,9 @@ def filter(self, rec):
135135
136136# Since default handler is not created, make sure only specific levels go through to stderr
137137TO_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+ )
139141TO_STDERR .setLevel (logging .NOTSET )
140142TO_STDERR .addFilter (
141143 LoggingFilter (
@@ -305,12 +307,13 @@ def synchronize_utime(stat: Union[os.stat_result, pathlib.Path], *rest: pathlib.
305307 Retrieve stats from the first 'file' and apply to the 'rest'
306308 """
307309 if not isinstance (stat , os .stat_result ):
308- logging .debug ("using stats from %s" , stat .name )
309310 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+ )
310314 for p in rest :
311315 if is_different_utime (stat , p .stat ()):
312316 os .utime (p , ns = (stat .st_atime_ns , stat .st_mtime_ns ))
313- logging .debug ("synchronized %s" , p .name )
314317
315318
316319def as_include_line (p : pathlib .Path ) -> str :
@@ -358,15 +361,15 @@ def ensure_exists_and_empty(*paths: pathlib.Path):
358361
359362 if not p .exists () or (p .exists () and p .stat ().st_size ):
360363 p .write_bytes (b"" )
361- logging .debug ("placeholder for %s " , p .name )
364+ logging .debug ("%s is a placeholder " , p .name )
362365 else :
363- logging .debug ("up-to-date %s " , p .name )
366+ logging .debug ("%s is up-to-date" , p .name )
364367
365368
366369def ensure_normal_time (* paths : pathlib .Path ):
367370 for p in paths :
368371 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 )
370373 p .touch ()
371374
372375
@@ -391,8 +394,10 @@ def write_or_replace(p: pathlib.Path, contents: str, encoding=FILE_ENCODING) ->
391394
392395 if contents != actual :
393396 p .write_text (contents , encoding = encoding )
397+ logging .debug ("%s contents written" , p .name )
394398 return True
395399
400+ logging .debug ("%s is up-to-date" , p .name )
396401 return False
397402
398403
@@ -427,12 +432,7 @@ def ensure_common_header_bound(ctx: Context):
427432 """
428433 Record currently used command-line options file
429434 """
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 ))
436436
437437
438438def make_build_opt_name (ctx : Context , debug : bool ) -> str :
@@ -460,18 +460,7 @@ def ensure_build_opt_written(ctx: Context, buffer: io.StringIO):
460460 for p in includes :
461461 buffer .write (f"{ as_include_line (p )} \n " )
462462
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 )
475464
476465
477466def maybe_empty_or_missing (p : pathlib .Path ):
@@ -525,14 +514,13 @@ def main_build(args: argparse.Namespace):
525514 )
526515
527516 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+ )
536524
537525 # notify when other files similar to .globals.h are in the sketch directory
538526 other_build_options = check_other_build_options (ctx .source_sketch_header )
@@ -558,19 +546,19 @@ def main_build(args: argparse.Namespace):
558546 build_opt_buffer = io .StringIO ()
559547
560548 try :
561- logging .debug ("searching for %s" , name )
562549 extract_build_opt_from_path (build_opt_buffer , name , ctx .source_sketch_header )
563550 except ParsingException as e :
564- raise e from None
551+ raise
565552
566553 # when command-line options were not created / found, it means the same thing as empty or missing .globals.h
567554 if not len (build_opt_buffer .getvalue ()):
568555 build_with_minimal_build_opt (ctx )
569556 return
570557
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+ )
574562
575563 # at this point, it is necessary to synchronize timestamps of every file
576564 ensure_build_opt_written (ctx , build_opt_buffer )
0 commit comments