78
78
build.globals.path={build.path}/core
79
79
globals.h.fqfn={build.globals.path}/{build.project_name}.globals.h
80
80
build.opt.fqfn={build.globals.path}/build.opt
81
- sketchbook.globals.h.rfn=
82
81
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}"
84
83
85
84
compiler.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"
86
85
"""
181
180
import os
182
181
import sys
183
182
import filecmp
183
+ import time
184
184
from shutil import copyfile
185
185
186
186
# 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):
228
228
if not os .path .exists (include_fqfn ):
229
229
# If file is missing, we need an place holder
230
230
open (include_fqfn , 'w' ).close ()
231
+ print ("add_include_line: Created " + include_fqfn )
231
232
build_opt = open (build_opt_fqfn , 'a' )
232
233
build_opt .write ('-include "' + include_fqfn .replace ('\\ ' , '\\ \\ ' ) + '"\n ' )
233
234
build_opt .close ()
@@ -309,41 +310,49 @@ def extract_create_build_opt_file(globals_h_fqfn, file_name, build_opt_fqfn):
309
310
return complete_comment
310
311
311
312
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 ))
322
330
323
331
324
332
def main ():
325
333
global build_opt_signature
326
334
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
327
340
328
- if len (sys .argv ) >= 4 :
341
+ if len (sys .argv ) >= 5 :
329
342
source_globals_h_fqfn = os .path .normpath (sys .argv [1 ])
330
343
globals_name = os .path .basename (source_globals_h_fqfn )
331
344
globals_h_fqfn = os .path .normpath (sys .argv [2 ])
332
345
build_path = os .path .dirname (globals_h_fqfn )
333
346
build_opt_fqfn = os .path .normpath (sys .argv [3 ])
334
347
# Assumption: globals_h_fqfn and build_opt_fqfn have the same dirname
348
+ commonhfile_fqfn = os .path .normpath (sys .argv [4 ])
335
349
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 )
344
354
else :
345
- sketchbook_globals_path = ""
346
- num_include_lines = 1
355
+ enable_override (False , commonhfile_fqfn )
347
356
348
357
if os .path .exists (globals_h_fqfn ):
349
358
# Check for signs of "Aggressive Caching core.a"
@@ -354,14 +363,15 @@ def main():
354
363
# report often enough to draw attention to the issue. Some aborted
355
364
# builds with incomplete ./core compiles may later produce false
356
365
# 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 :
358
369
print_err ("Aggressive caching of core.a might be enabled. This may create build errors." )
359
370
print_err (" Suggest turning off in preferences.txt: \" compiler.cache_core=false\" " )
360
371
print_err (" Read more at " + docs_url )
361
-
362
372
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,
365
375
# makecorever.py may have run before us and recreaded the directory.
366
376
if not os .path .exists (build_path ):
367
377
os .makedirs (build_path )
@@ -377,6 +387,21 @@ def main():
377
387
# w/o triggering a needless rebuild.
378
388
embedded_options = extract_create_build_opt_file (globals_h_fqfn , globals_name , build_opt_fqfn )
379
389
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
+
380
405
# Provide context help for build option support.
381
406
source_build_opt_h_fqfn = os .path .join (os .path .dirname (source_globals_h_fqfn ), "build_opt.h" )
382
407
if os .path .exists (source_build_opt_h_fqfn ) and not embedded_options :
@@ -389,11 +414,6 @@ def main():
389
414
print_msg ("Tip: Embedd compiler command-line options in a block comment starting with '" + build_opt_signature + "'." )
390
415
print_msg (" Read more at " + docs_url )
391
416
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
-
397
417
else :
398
418
print_err ("Too few arguments. Add arguments:" )
399
419
print_err (" Source FQFN SketchName.ino.globals.h, Build FQFN SketchName.ino.globals.h, Build FQFN build.opt" )
0 commit comments