From 49eb17b2219aea50e7d7522513603f4b15348f3a Mon Sep 17 00:00:00 2001 From: rjwats Date: Sun, 2 Jun 2019 14:27:55 +0100 Subject: [PATCH] resolve build issue under windows with pre-build script --- platformio.ini | 2 ++ timelib_fix.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 timelib_fix.py diff --git a/platformio.ini b/platformio.ini index ea7848c..bde98ba 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,6 +12,8 @@ platform = espressif8266 board = esp12e board_build.f_cpu = 160000000L +extra_scripts = pre:timelib_fix.py + framework = arduino ;upload_flags = --port=8266 --auth=esp-react ;upload_port = 192.168.0.6 diff --git a/timelib_fix.py b/timelib_fix.py new file mode 100644 index 0000000..84c0ec1 --- /dev/null +++ b/timelib_fix.py @@ -0,0 +1,31 @@ +import os +import sys +import re +Import("env") + +# Find files under 'root' of a given 'fileName' in directories matching 'subDirectoryPattern' +# This will allow us to safely find the offending Time.h file for removal prior to building +def findSubDirectoryFiles(root, subDirectoryPattern, fileName): + subDirectories = os.listdir(root) + subDirectories = filter(lambda d: re.match(subDirectoryPattern, d), subDirectories) + result = [] + for subDirectory in subDirectories: + candidateFile = os.path.join(root, subDirectory, fileName) + if os.path.isfile(candidateFile): + result.append(candidateFile) + return result + +# lib deps directory +libDepsDir = os.path.join(env.subst('$PROJECT_DIR'), '.piolibdeps') +timeHeaderFile = "Time.h" +timeLibDirectoryPattern = "Time(_ID[0-9]+)?" + +# delete the file, as long as we only find one +if os.path.isdir(libDepsDir) : + deletionCandidates = findSubDirectoryFiles(libDepsDir, timeLibDirectoryPattern, timeHeaderFile) + numDeletionCandidates = len(deletionCandidates) + if numDeletionCandidates == 1: + os.remove(deletionCandidates[0]) + elif numDeletionCandidates > 1: + os.write(2, 'Can\'t delete Time.h, more than one instance found:\n' + '\n'.join(deletionCandidates)) + sys.exit(1)