2019-06-02 13:27:55 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import re
|
2019-12-29 17:54:12 +00:00
|
|
|
|
2019-06-02 13:27:55 +00:00
|
|
|
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
|
|
|
|
|
2019-07-14 21:14:22 +00:00
|
|
|
def deleteTimeHeader(libDepsDir):
|
|
|
|
timeHeaderFile = "Time.h"
|
|
|
|
timeLibDirectoryPattern = "Time(_ID[0-9]+)?"
|
2019-06-02 13:27:55 +00:00
|
|
|
|
2019-07-14 21:14:22 +00:00
|
|
|
# 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:
|
2019-12-29 17:54:12 +00:00
|
|
|
os.write(2, "Can\'t delete Time.h, more than one instance found:\n" + "\n".join(deletionCandidates))
|
2019-07-14 21:14:22 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# old lib deps directory
|
2019-12-29 17:54:12 +00:00
|
|
|
deleteTimeHeader(os.path.join(env.subst("$PROJECT_DIR"), ".piolibdeps"))
|
2019-07-14 21:14:22 +00:00
|
|
|
|
2019-11-27 09:21:34 +00:00
|
|
|
# pre 4.x lib deps directory
|
2019-12-29 17:54:12 +00:00
|
|
|
deleteTimeHeader(os.path.join(env.subst("$PROJECTLIBDEPS_DIR"), env.subst("$PIOENV")))
|
2019-11-27 09:21:34 +00:00
|
|
|
|
|
|
|
# >4.x lib deps directory
|
2019-12-29 17:54:12 +00:00
|
|
|
deleteTimeHeader(os.path.join(env.subst("$PROJECT_LIBDEPS_DIR"), env.subst("$PIOENV")))
|