181
181
import sys
182
182
import filecmp
183
183
import time
184
+ import platform
184
185
from shutil import copyfile
185
186
186
187
# Need to work on signature line used for match to avoid conflicts with
@@ -317,6 +318,50 @@ def enable_override(enable, commonhfile_fqfn):
317
318
file .close ()
318
319
# enabled when getsize(commonhfile_fqfn) is non-zero, disabled when zero
319
320
321
+ def find_preferences_txt ():
322
+ platform_name = platform .system ()
323
+ # OS Path list from:
324
+ # https://www.arduino.cc/en/hacking/preferences
325
+ if "Windows" == platform_name :
326
+ fqfn = os .path .expanduser ("\Arduino15\preferences.txt" ) # Windows
327
+ if os .path .exists (fqfn ):
328
+ return fqfn
329
+ fqfn = os .path .expanduser ("\Documents\ArduinoData\preferences.txt" ) # Windows app version
330
+ if os .path .exists (fqfn ):
331
+ return fqfn
332
+ elif "Darwin" == platform_name :
333
+ fqfn = os .path .expanduser ("~/Library/Arduino15/preferences.txt" ) # Max OS X
334
+ if os .path .exists (fqfn ):
335
+ return fqfn
336
+ elif "Linux" == platform_name :
337
+ fqfn = os .path .expanduser ("~/.arduino15/preferences.txt" ) # Linux - works
338
+ if os .path .exists (fqfn ):
339
+ return fqfn
340
+ # Where and how would I find this?
341
+ # <Arduino IDE installation folder>/portable/preferences.txt (when used in portable mode)
342
+ return ""
343
+
344
+
345
+ def get_preferences_txt (file_fqfn , key ):
346
+ with open (file_fqfn ) as fd :
347
+ for line in fd :
348
+ name , value = line .partition ("=" )[::2 ]
349
+ if name .strip ().lower () == key :
350
+ if value .strip ().lower () == 'true' :
351
+ print_msg ("found compiler.cache_core " + value .strip ()) #D debug
352
+ return True
353
+ else :
354
+ return False
355
+ return True # If we don't find it just assume it is set True
356
+
357
+
358
+ def check_preferences_txt ():
359
+ file_fqfn = find_preferences_txt ()
360
+ if file_fqfn == "" :
361
+ return True # cannot find file assume enabled
362
+ print_msg ("\n found preferences " + file_fqfn ) #D debug
363
+ return get_preferences_txt (file_fqfn , "compiler.cache_core" )
364
+
320
365
321
366
def touch (fname , times = None ):
322
367
with open (fname , 'a' ):
@@ -333,10 +378,7 @@ def main():
333
378
global build_opt_signature
334
379
global docs_url
335
380
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
381
+ use_aggressive_caching_workaround = check_preferences_txt () #? preliminary
340
382
341
383
if len (sys .argv ) >= 5 :
342
384
source_globals_h_fqfn = os .path .normpath (sys .argv [1 ])
0 commit comments