7878build.globals.path={build.path}/core
7979globals.h.fqfn={build.globals.path}/{build.project_name}.globals.h
8080build.opt.fqfn={build.globals.path}/build.opt
81- sketchbook.globals.h.rfn=
8281
83- recipe.hooks.prebuild.2.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.mkbuildoptglobals}" "{globals.h.source.fqfn}" "{globals.h.fqfn}" "{build.opt.fqfn}" "{sketchbook.globals.h.rfn}"
82+ recipe.hooks.prebuild.2.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.mkbuildoptglobals}" "{globals.h.source.fqfn}" "{globals.h.fqfn}" "{build.opt.fqfn}"
8483
8584compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE -DESP8266 @{build.opt.path} "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"
8685"""
181180import os
182181import sys
183182import filecmp
183+ import time
184184from shutil import copyfile
185185
186186# Need to work on signature line used for match to avoid conflicts with
@@ -228,6 +228,7 @@ def add_include_line(build_opt_fqfn, include_fqfn):
228228 if not os .path .exists (include_fqfn ):
229229 # If file is missing, we need an place holder
230230 open (include_fqfn , 'w' ).close ()
231+ print ("add_include_line: Created " + include_fqfn )
231232 build_opt = open (build_opt_fqfn , 'a' )
232233 build_opt .write ('-include "' + include_fqfn .replace ('\\ ' , '\\ \\ ' ) + '"\n ' )
233234 build_opt .close ()
@@ -309,41 +310,49 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
309310 return complete_comment
310311
311312
312- def get_sketchbook_globals (build_path , sketchbook_globals_path , build_opt_fqfn ):
313- """
314- Construct path to sketchbook globals using relative path from users home directory.
315- Append to build options.
316- """
317- source_fqfn = os .path .expanduser ('~/' + sketchbook_globals_path )
318- notused , file_name = os .path .split (source_fqfn )
319- build_target_fqfn = os .path .join (build_path , file_name )
320- copy_create_build_file (source_fqfn , build_target_fqfn )
321- add_include_line (build_opt_fqfn , build_target_fqfn )
313+ def enable_override (enable , commonhfile_fqfn ):
314+ file = open (commonhfile_fqfn , 'w' )
315+ if enable :
316+ file .write ("//Override aggressive caching\n " )
317+ file .close ()
318+ # enabled when getsize(commonhfile_fqfn) is non-zero, disabled when zero
319+
320+
321+ def touch (fname , times = None ):
322+ with open (fname , 'a' ):
323+ os .utime (fname , times )
324+
325+
326+ def time_sync (globals_h_fqfn , commonhfile_fqfn ):
327+ ts = time .time ()
328+ touch (globals_h_fqfn , (ts , ts ))
329+ touch (commonhfile_fqfn , (ts , ts ))
322330
323331
324332def main ():
325333 global build_opt_signature
326334 global docs_url
335+ num_include_lines = 1
336+ use_aggressive_caching_workaround = True
337+ # Enhancement: read preferences.txt and set use_aggressive_caching_workaround
338+ # https://www.arduino.cc/en/hacking/preferences
339+ # :( it can be in 9 different locations
327340
328- if len (sys .argv ) >= 4 :
341+ if len (sys .argv ) >= 5 :
329342 source_globals_h_fqfn = os .path .normpath (sys .argv [1 ])
330343 globals_name = os .path .basename (source_globals_h_fqfn )
331344 globals_h_fqfn = os .path .normpath (sys .argv [2 ])
332345 build_path = os .path .dirname (globals_h_fqfn )
333346 build_opt_fqfn = os .path .normpath (sys .argv [3 ])
334347 # Assumption: globals_h_fqfn and build_opt_fqfn have the same dirname
348+ commonhfile_fqfn = os .path .normpath (sys .argv [4 ])
335349
336- if len (sys .argv ) >= 5 :
337- # Hidden option for advanced programmers
338- # Very few things need to be made available globaly to *all* Sketches
339- # This option can create obfuscation when not used wisely.
340- # Omit from documentation, assume that only an advanced programmer
341- # will discover and use this.
342- sketchbook_globals_path = os .path .normpath (sys .argv [4 ])
343- num_include_lines = 2
350+ if os .path .exists (commonhfile_fqfn ):
351+ if os .path .getsize (commonhfile_fqfn ) and \
352+ not use_aggressive_caching_workaround :
353+ enable_override (False , commonhfile_fqfn )
344354 else :
345- sketchbook_globals_path = ""
346- num_include_lines = 1
355+ enable_override (False , commonhfile_fqfn )
347356
348357 if os .path .exists (globals_h_fqfn ):
349358 # Check for signs of "Aggressive Caching core.a"
@@ -354,14 +363,15 @@ def main():
354363 # report often enough to draw attention to the issue. Some aborted
355364 # builds with incomplete ./core compiles may later produce false
356365 # positives. Only report when globals.h is being used.
357- if os .path .getsize (globals_h_fqfn ) and len (os .listdir (build_path )) < 20 :
366+ if not use_aggressive_caching_workaround and \
367+ os .path .getsize (globals_h_fqfn ) and \
368+ len (os .listdir (build_path )) < 20 :
358369 print_err ("Aggressive caching of core.a might be enabled. This may create build errors." )
359370 print_err (" Suggest turning off in preferences.txt: \" compiler.cache_core=false\" " )
360371 print_err (" Read more at " + docs_url )
361-
362372 else :
363- # Info: When platform.txt, platform.local.txt, or IDE Tools are
364- # changed, our build path directory was cleaned. Note,
373+ # Info: When platform.txt, platform.local.txt, or IDE Tools board
374+ # settings are changed, our build path directory was cleaned. Note,
365375 # makecorever.py may have run before us and recreaded the directory.
366376 if not os .path .exists (build_path ):
367377 os .makedirs (build_path )
@@ -377,6 +387,21 @@ def main():
377387 # w/o triggering a needless rebuild.
378388 embedded_options = extract_create_build_opt_file (globals_h_fqfn , globals_name , build_opt_fqfn )
379389
390+ if use_aggressive_caching_workaround :
391+ if os .path .getsize (commonhfile_fqfn ):
392+ print ("os.path.getmtime(globals_h_fqfn) " + str (os .path .getmtime (globals_h_fqfn )))
393+ print ("os.path.getmtime(commonhfile_fqfn) " + str (os .path .getmtime (commonhfile_fqfn )))
394+ if (os .path .getmtime (globals_h_fqfn ) != os .path .getmtime (commonhfile_fqfn )):
395+ # Need to rebuild core.a
396+ # touching commonhfile_fqfn in the source core tree will cause rebuild.
397+ time_sync (globals_h_fqfn , commonhfile_fqfn )
398+ elif os .path .getsize (globals_h_fqfn ):
399+ enable_override (True , commonhfile_fqfn )
400+ time_sync (globals_h_fqfn , commonhfile_fqfn )
401+
402+ add_include_line (build_opt_fqfn , commonhfile_fqfn )
403+ add_include_line (build_opt_fqfn , globals_h_fqfn )
404+
380405 # Provide context help for build option support.
381406 source_build_opt_h_fqfn = os .path .join (os .path .dirname (source_globals_h_fqfn ), "build_opt.h" )
382407 if os .path .exists (source_build_opt_h_fqfn ) and not embedded_options :
@@ -389,11 +414,6 @@ def main():
389414 print_msg ("Tip: Embedd compiler command-line options in a block comment starting with '" + build_opt_signature + "'." )
390415 print_msg (" Read more at " + docs_url )
391416
392- add_include_line (build_opt_fqfn , globals_h_fqfn )
393-
394- if len (sketchbook_globals_path ):
395- get_sketchbook_globals (build_path , sketchbook_globals_path , build_opt_fqfn )
396-
397417 else :
398418 print_err ("Too few arguments. Add arguments:" )
399419 print_err (" Source FQFN SketchName.ino.globals.h, Build FQFN SketchName.ino.globals.h, Build FQFN build.opt" )
0 commit comments