Skip to content

Commit 49eb17b

Browse files
committed
resolve build issue under windows with pre-build script
1 parent a98f1d4 commit 49eb17b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ platform = espressif8266
1212
board = esp12e
1313
board_build.f_cpu = 160000000L
1414

15+
extra_scripts = pre:timelib_fix.py
16+
1517
framework = arduino
1618
;upload_flags = --port=8266 --auth=esp-react
1719
;upload_port = 192.168.0.6

timelib_fix.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import sys
3+
import re
4+
Import("env")
5+
6+
# Find files under 'root' of a given 'fileName' in directories matching 'subDirectoryPattern'
7+
# This will allow us to safely find the offending Time.h file for removal prior to building
8+
def findSubDirectoryFiles(root, subDirectoryPattern, fileName):
9+
subDirectories = os.listdir(root)
10+
subDirectories = filter(lambda d: re.match(subDirectoryPattern, d), subDirectories)
11+
result = []
12+
for subDirectory in subDirectories:
13+
candidateFile = os.path.join(root, subDirectory, fileName)
14+
if os.path.isfile(candidateFile):
15+
result.append(candidateFile)
16+
return result
17+
18+
# lib deps directory
19+
libDepsDir = os.path.join(env.subst('$PROJECT_DIR'), '.piolibdeps')
20+
timeHeaderFile = "Time.h"
21+
timeLibDirectoryPattern = "Time(_ID[0-9]+)?"
22+
23+
# delete the file, as long as we only find one
24+
if os.path.isdir(libDepsDir) :
25+
deletionCandidates = findSubDirectoryFiles(libDepsDir, timeLibDirectoryPattern, timeHeaderFile)
26+
numDeletionCandidates = len(deletionCandidates)
27+
if numDeletionCandidates == 1:
28+
os.remove(deletionCandidates[0])
29+
elif numDeletionCandidates > 1:
30+
os.write(2, 'Can\'t delete Time.h, more than one instance found:\n' + '\n'.join(deletionCandidates))
31+
sys.exit(1)

0 commit comments

Comments
 (0)