Skip to content

Commit cf24024

Browse files
authored
New handling of missing perferences.txt in mkbuildoptglobals (#8814)
* Only rely on `perferences.txt ` when requested * Always assume shared `core.a` caching is in use * Ignore the passed-in IDE version. Too often, the value is not correct
1 parent bed2fa3 commit cf24024

File tree

1 file changed

+9
-105
lines changed

1 file changed

+9
-105
lines changed

Diff for: tools/mkbuildoptglobals.py

+9-105
Original file line numberDiff line numberDiff line change
@@ -416,68 +416,6 @@ def discover_1st_time_run(build_path):
416416
return 0 == count
417417

418418

419-
def find_preferences_txt(runtime_ide_path):
420-
"""
421-
Check for perferences.txt in well-known locations. Most OSs have two
422-
possibilities. When "portable" is present, it takes priority. Otherwise, the
423-
remaining path wins. However, Windows has two. Depending on the install
424-
source, the APP store or website download, both may appear and create an
425-
ambiguous result.
426-
427-
Return two item list - Two non "None" items indicate an ambiguous state.
428-
429-
OS Path list for Arduino IDE 1.6.0 and newer
430-
from: https://www.arduino.cc/en/hacking/preferences
431-
"""
432-
platform_name = platform.system()
433-
if "Linux" == platform_name:
434-
# Test for portable 1ST
435-
# <Arduino IDE installation folder>/portable/preferences.txt (when used in portable mode)
436-
# For more on portable mode see https://docs.arduino.cc/software/ide-v1/tutorials/PortableIDE
437-
fqfn = os.path.normpath(runtime_ide_path + "/portable/preferences.txt")
438-
# Linux - verified with Arduino IDE 1.8.19
439-
if os.path.exists(fqfn):
440-
return [fqfn, None]
441-
fqfn = os.path.expanduser("~/.arduino15/preferences.txt")
442-
# Linux - verified with Arduino IDE 1.8.18 and 2.0 RC5 64bit and AppImage
443-
if os.path.exists(fqfn):
444-
return [fqfn, None]
445-
elif "Windows" == platform_name:
446-
fqfn = os.path.normpath(runtime_ide_path + "\portable\preferences.txt")
447-
# verified on Windows 10 with Arduino IDE 1.8.19
448-
if os.path.exists(fqfn):
449-
return [fqfn, None]
450-
# It is never simple. Arduino from the Windows APP store or the download
451-
# Windows 8 and up option will save "preferences.txt" in one location.
452-
# The downloaded Windows 7 (and up version) will put "preferences.txt"
453-
# in a different location. When both are present due to various possible
454-
# scenarios, give preference to the APP store.
455-
fqfn = os.path.expanduser("~\Documents\ArduinoData\preferences.txt")
456-
# Path for "Windows app" - verified on Windows 10 with Arduino IDE 1.8.19 from APP store
457-
fqfn2 = os.path.normpath(os.getenv("LOCALAPPDATA") + "\Arduino15\preferences.txt")
458-
# Path for Windows 7 and up - verified on Windows 10 with Arduino IDE 1.8.19
459-
if os.path.exists(fqfn):
460-
if os.path.exists(fqfn2):
461-
print_err("Multiple 'preferences.txt' files found:")
462-
print_err(" " + fqfn)
463-
print_err(" " + fqfn2)
464-
return [fqfn, fqfn2]
465-
else:
466-
return [fqfn, None]
467-
elif os.path.exists(fqfn2):
468-
return [fqfn2, None]
469-
elif "Darwin" == platform_name:
470-
# Portable is not compatable with Mac OS X
471-
# see https://docs.arduino.cc/software/ide-v1/tutorials/PortableIDE
472-
fqfn = os.path.expanduser("~/Library/Arduino15/preferences.txt")
473-
# Mac OS X - unverified
474-
if os.path.exists(fqfn):
475-
return [fqfn, None]
476-
477-
print_err("File preferences.txt not found on " + platform_name)
478-
return [None, None]
479-
480-
481419
def get_preferences_txt(file_fqfn, key):
482420
# Get Key Value, key is allowed to be missing.
483421
# We assume file file_fqfn exists
@@ -505,27 +443,12 @@ def check_preferences_txt(runtime_ide_path, preferences_file):
505443
else:
506444
print_err(f"Override preferences file '{preferences_file}' not found.")
507445

508-
elif runtime_ide_path != None:
509-
# For a particular install, search the expected locations for platform.txt
510-
# This should never fail.
511-
file_fqfn = find_preferences_txt(runtime_ide_path)
512-
if file_fqfn[0] != None:
513-
print_msg(f"Using preferences from '{file_fqfn[0]}'")
514-
val0 = get_preferences_txt(file_fqfn[0], key)
515-
val1 = val0
516-
if file_fqfn[1] != None:
517-
val1 = get_preferences_txt(file_fqfn[1], key)
518-
if val0 == val1: # We can safely ignore that there were two preferences.txt files
519-
return val0
520-
else:
521-
print_err(f"Found too many preferences.txt files with different values for '{key}'")
522-
raise UserWarning
523-
else:
524-
# Something is wrong with the installation or our understanding of the installation.
525-
print_err("'preferences.txt' file missing from well known locations.")
526-
527-
return None
528-
446+
# Referencing the preferences.txt for an indication of shared "core.a"
447+
# caching is unreliable. There are too many places reference.txt can be
448+
# stored and no hints of which the Arduino build might be using. Unless
449+
# directed otherwise, assume "core.a" caching true.
450+
print_msg(f"Assume aggressive 'core.a' caching enabled.")
451+
return True
529452

530453
def touch(fname, times=None):
531454
with open(fname, "ab") as file:
@@ -555,12 +478,8 @@ def synchronous_touch(globals_h_fqfn, commonhfile_fqfn):
555478
def determine_cache_state(args, runtime_ide_path, source_globals_h_fqfn):
556479
global docs_url
557480
print_dbg(f"runtime_ide_version: {args.runtime_ide_version}")
558-
if args.runtime_ide_version < 10802: # CI also has version 10607 -- and args.runtime_ide_version != 10607:
559-
# Aggresive core caching - not implemented before version 1.8.2
560-
# Note, Arduino IDE 2.0 rc5 has version 1.6.7 and has aggressive caching.
561-
print_dbg(f"Old version ({args.runtime_ide_version}) of Arduino IDE no aggressive caching option")
562-
return False
563-
elif args.cache_core != None:
481+
482+
if args.cache_core != None:
564483
print_msg(f"Preferences override, this prebuild script assumes the 'compiler.cache_core' parameter is set to {args.cache_core}")
565484
print_msg(f"To change, modify 'mkbuildoptglobals.extra_flags=(--cache_core | --no_cache_core)' in 'platform.local.txt'")
566485
return args.cache_core
@@ -594,19 +513,7 @@ def determine_cache_state(args, runtime_ide_path, source_globals_h_fqfn):
594513
preferences_fqfn = os.path.expanduser(preferences_fqfn)
595514
print_dbg(f"determine_cache_state: preferences_fqfn: {preferences_fqfn}")
596515

597-
try:
598-
caching_enabled = check_preferences_txt(ide_path, preferences_fqfn)
599-
except UserWarning:
600-
if os.path.exists(source_globals_h_fqfn):
601-
caching_enabled = None
602-
print_err(f" runtime_ide_version: {args.runtime_ide_version}")
603-
print_err(f" This must be resolved to use '{globals_name}'")
604-
print_err(f" Read more at {docs_url}")
605-
else:
606-
# We can quietly ignore the problem because we are not needed.
607-
caching_enabled = True
608-
609-
return caching_enabled
516+
return check_preferences_txt(ide_path, preferences_fqfn)
610517

611518

612519
"""
@@ -744,9 +651,6 @@ def main():
744651
print_dbg("First run since Arduino IDE started.")
745652

746653
use_aggressive_caching_workaround = determine_cache_state(args, runtime_ide_path, source_globals_h_fqfn)
747-
if use_aggressive_caching_workaround == None:
748-
# Specific rrror messages already buffered
749-
handle_error(1)
750654

751655
print_dbg(f"first_time: {first_time}")
752656
print_dbg(f"use_aggressive_caching_workaround: {use_aggressive_caching_workaround}")

0 commit comments

Comments
 (0)