7373
7474runtime.tools.mkbuildoptglobals={runtime.platform.path}/tools/mkbuildoptglobals.py
7575
76- # Fully qualified and relative file names for processing sketch global options
76+ # Fully qualified file names for processing sketch global options
7777globals.h.source.fqfn={build.source.path}/{build.project_name}.globals.h
78- build.globals.path={build.path}/core
79- globals.h.fqfn={build.globals.path}/{build.project_name}.globals.h
80- build.opt.fqfn={build.globals.path}/build.opt
78+ commonhfile.fqfn={build.core.path}/CommonHFile.h
79+ build.opt.fqfn={build.path}/core/build.opt
8180
82- recipe.hooks.prebuild.2.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.mkbuildoptglobals}" "{globals.h.source. fqfn}" "{globals.h.fqfn}" "{build.opt .fqfn}"
81+ recipe.hooks.prebuild.2.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.mkbuildoptglobals}" "{runtime.ide.path}" "{build.path}" "{build.opt. fqfn}" "{globals.h.source. fqfn}" "{commonhfile .fqfn}"
8382
8483compiler.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"
8584"""
180179Build does not work as expected. This does not fail often. Maybe PIC NIC.
181180"""
182181
182+ from shutil import copyfile
183+ import glob
183184import os
185+ import platform
184186import sys
185- import filecmp
186187import time
187- import platform
188- from shutil import copyfile
189188
190189# Need to work on signature line used for match to avoid conflicts with
191190# existing embedded documentation methods.
@@ -323,10 +322,36 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
323322
324323
325324def enable_override (enable , commonhfile_fqfn ):
325+ # Reduce disk IO writes
326+ if os .path .exists (commonhfile_fqfn ):
327+ if os .path .getsize (commonhfile_fqfn ): # workaround active
328+ if enable :
329+ return
330+ elif not enable :
331+ return
326332 with open (commonhfile_fqfn , 'w' ) as file :
327333 if enable :
328334 file .write ("//Override aggressive caching\n " )
329- # enabled when getsize(commonhfile_fqfn) is non-zero, disabled when zero
335+ # enable workaround when getsize(commonhfile_fqfn) is non-zero, disabled when zero
336+
337+
338+ def discover_1st_time_run (build_path ):
339+ # Need to know if this is the 1ST compile of the Arduino IDE starting.
340+ # Use empty cache directory as an indicator for 1ST compile.
341+ # Arduino IDE 2.0 RC5 does not cleanup on exist like 1.6.19. Probably for
342+ # debugging like the irregular version number 10607. For RC5 this indicator
343+ # will be true after a reboot instead of a 1ST compile of the IDE starting.
344+ tmp_path , build = os .path .split (build_path )
345+ ide_2_0 = 'arduino-sketch-'
346+ if ide_2_0 == build [:len (ide_2_0 )]:
347+ search_path = os .path .join (tmp_path , 'arduino-core-cache/*' ) # Arduino IDE 2.0
348+ else :
349+ search_path = os .path .join (tmp_path , 'arduino_cache_*/*' ) # Arduino IDE 1.6.x and up
350+
351+ count = 0
352+ for dirname in glob .glob (search_path ):
353+ count += 1
354+ return 0 == count
330355
331356
332357def find_preferences_txt (runtime_ide_path ):
@@ -423,45 +448,27 @@ def main():
423448 num_include_lines = 1
424449
425450 if len (sys .argv ) >= 6 :
426- source_globals_h_fqfn = os .path .normpath (sys .argv [1 ])
427- globals_name = os .path .basename (source_globals_h_fqfn )
428- globals_h_fqfn = os .path .normpath (sys .argv [2 ])
429- build_path = os .path .dirname (globals_h_fqfn )
430- # Assumption: globals_h_fqfn and build_opt_fqfn have the same dirname
451+ runtime_ide_path = os .path .normpath (sys .argv [1 ])
452+ build_path = os .path .normpath (sys .argv [2 ])
431453 build_opt_fqfn = os .path .normpath (sys .argv [3 ])
432- commonhfile_fqfn = os .path .normpath (sys .argv [4 ])
433- runtime_ide_path = os .path .normpath (sys .argv [5 ])
454+ source_globals_h_fqfn = os .path .normpath (sys .argv [4 ])
455+ commonhfile_fqfn = os .path .normpath (sys .argv [5 ])
456+
457+ globals_name = os .path .basename (source_globals_h_fqfn )
458+ build_path_core , build_opt_name = os .path .split (build_opt_fqfn )
459+ globals_h_fqfn = os .path .join (build_path_core , globals_name )
460+
461+ first_time = discover_1st_time_run (build_path )
434462 use_aggressive_caching_workaround = check_preferences_txt (runtime_ide_path )
435463
436- if os .path .exists (commonhfile_fqfn ):
437- if os .path .getsize (commonhfile_fqfn ) and \
438- not use_aggressive_caching_workaround :
439- enable_override (False , commonhfile_fqfn )
440- else :
464+ if first_time or \
465+ not use_aggressive_caching_workaround or \
466+ not os .path .exists (commonhfile_fqfn ):
441467 enable_override (False , commonhfile_fqfn )
442468
443- if os .path .exists (globals_h_fqfn ):
444- # Check for signs of "Aggressive Caching core.a"
445- # 1ST time run, build path/core will not exist or be nearly empty,
446- # nothing can be learned. The presence of globals_h_fqfn in the
447- # build path/core helps distinguish 1st time run from rebuild.
448- # This method does not report in all scenarios; however, it does
449- # report often enough to draw attention to the issue. Some aborted
450- # builds with incomplete ./core compiles may later produce false
451- # positives. Only report when globals.h is being used.
452- if not use_aggressive_caching_workaround and \
453- os .path .getsize (globals_h_fqfn ) and \
454- len (os .listdir (build_path )) < 20 :
455- print_err ("Aggressive caching of core.a might be enabled. This may create build errors." )
456- print_err (" Suggest turning off in preferences.txt: \" compiler.cache_core=false\" " )
457- print_err (" Read more at " + docs_url )
458- else :
459- # Info: When platform.txt, platform.local.txt, or IDE Tools board
460- # settings are changed, our build path directory was cleaned. Note,
461- # makecorever.py may have run before us and recreaded the directory.
462- if not os .path .exists (build_path ):
463- os .makedirs (build_path )
464- print_msg ("Clean build, created dir " + build_path )
469+ if not os .path .exists (build_path_core ):
470+ os .makedirs (build_path_core )
471+ print_msg ("Clean build, created dir " + build_path_core )
465472
466473 if os .path .exists (source_globals_h_fqfn ):
467474 print_msg ("Using global defines from " + source_globals_h_fqfn )
@@ -478,6 +485,8 @@ def main():
478485 # that exactly matches the timestamp of "CommonHFile.h" in the
479486 # platform source tree, it owns the core cache. If not, or
480487 # "Sketch.ino.globals.h" has changed, rebuild core.
488+ # A non-zero file size for commonhfile_fqfn, means we have seen a
489+ # globals.h file before and workaround is active.
481490 if os .path .getsize (commonhfile_fqfn ):
482491 if (os .path .getmtime (globals_h_fqfn ) != os .path .getmtime (commonhfile_fqfn )):
483492 # Need to rebuild core.a
0 commit comments