-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_libs.py
More file actions
56 lines (42 loc) · 2.15 KB
/
Copy pathpatch_libs.py
File metadata and controls
56 lines (42 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Import("env") #type: ignore
import os
# PATCH 1: Disable ezTime EEPROM cache
def patch_eztime(source, target, env):
path = os.path.join(env["PROJECT_LIBDEPS_DIR"], env["PIOENV"], "ezTime", "src", "ezTime.h")
if not os.path.exists(path):
print(">> ezTime not found, skipping patch")
return
with open(path, "r") as f:
content = f.read()
# Comment out the macro to prevent hardware stalls on SAMD21 boards
if "#define EZTIME_CACHE_EEPROM" in content and "// #define EZTIME_CACHE_EEPROM" not in content:
content = content.replace("#define EZTIME_CACHE_EEPROM", "// #define EZTIME_CACHE_EEPROM")
with open(path, "w") as f:
f.write(content)
print(">> Patched ezTime: EZTIME_CACHE_EEPROM disabled")
# PATCH 2: Fix MKR IoT Carrier 'NONE' enum collision
# Reason: The generic 'NONE' enum leaks into the global namespace causing ODR compilation errors.
# Renaming it to 'SHANE_NONE' resolves conflicts with other libraries.
def patch_carrier(source, target, env):
path = os.path.join(env["PROJECT_LIBDEPS_DIR"], env["PIOENV"], "Arduino_MKRIoTCarrier", "src", "Arduino_MKRIoTCarrier.h")
if not os.path.exists(path):
print(">> Arduino_MKRIoTCarrier not found, skipping patch")
return
with open(path, "r") as f:
content = f.read()
# Apply patch if not already present
if "SHANE_NONE" not in content:
import re
# Exact regex match to replace 'NONE = -1'
content = re.sub(r'\bNONE\s*=\s*-1,', 'SHANE_NONE = -1,', content)
with open(path, "w") as f:
f.write(content)
print(">> Patched Arduino_MKRIoTCarrier: NONE -> SHANE_NONE")
else:
print(">> Arduino_MKRIoTCarrier already patched")
# EXECUTION TRIGGERS
# 1. Run immediately on script load
patch_eztime(None, None, env) #type: ignore
patch_carrier(None, None, env)#type: ignore
# 2. Hook to run right before C++ compilation (handles mid-build fresh library downloads)
env.AddPreAction("compile", lambda source, target, env: [patch_eztime(source, target, env), patch_carrier(source, target, env)]) #type: ignore