Skip to content

Commit dc3d37c

Browse files
committed
inital pass at searching for and reading preferences.txt
1 parent f119fea commit dc3d37c

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

tools/mkbuildoptglobals.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
import sys
182182
import filecmp
183183
import time
184+
import platform
184185
from shutil import copyfile
185186

186187
# Need to work on signature line used for match to avoid conflicts with
@@ -317,6 +318,50 @@ def enable_override(enable, commonhfile_fqfn):
317318
file.close()
318319
# enabled when getsize(commonhfile_fqfn) is non-zero, disabled when zero
319320

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("\nfound preferences " + file_fqfn) #D debug
363+
return get_preferences_txt(file_fqfn, "compiler.cache_core")
364+
320365

321366
def touch(fname, times=None):
322367
with open(fname, 'a'):
@@ -333,10 +378,7 @@ def main():
333378
global build_opt_signature
334379
global docs_url
335380
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
340382

341383
if len(sys.argv) >= 5:
342384
source_globals_h_fqfn = os.path.normpath(sys.argv[1])

0 commit comments

Comments
 (0)