Allow multiple patch directories per environment
This commit is contained in:
parent
2608080708
commit
6556268056
@ -9,7 +9,10 @@ import re
|
|||||||
Import("env")
|
Import("env")
|
||||||
|
|
||||||
def getPatchPath(env):
|
def getPatchPath(env):
|
||||||
return os.path.join(env["PROJECT_DIR"], "patches", env.GetProjectOption('custom_patches'))
|
patchList = []
|
||||||
|
for patch in env.GetProjectOption('custom_patches').split(","):
|
||||||
|
patchList.append(os.path.join(env["PROJECT_DIR"], "patches", patch))
|
||||||
|
return patchList
|
||||||
|
|
||||||
def is_tool(name):
|
def is_tool(name):
|
||||||
"""Check whether `name` is on PATH and marked as executable."""
|
"""Check whether `name` is on PATH and marked as executable."""
|
||||||
@ -44,35 +47,36 @@ def main():
|
|||||||
print('Git not found. Will not apply custom patches!')
|
print('Git not found. Will not apply custom patches!')
|
||||||
return
|
return
|
||||||
|
|
||||||
directory = getPatchPath(env)
|
directories = getPatchPath(env)
|
||||||
if (not os.path.isdir(directory)):
|
for directory in directories:
|
||||||
print('Patch directory not found: ' + directory)
|
if (not os.path.isdir(directory)):
|
||||||
return
|
print('Patch directory not found: ' + directory)
|
||||||
|
return
|
||||||
|
|
||||||
for file in os.listdir(directory):
|
for file in os.listdir(directory):
|
||||||
if (not file.endswith('.patch')):
|
if (not file.endswith('.patch')):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fullPath = os.path.join(directory, file)
|
fullPath = os.path.join(directory, file)
|
||||||
preparePath = fullPath + '.prepare'
|
preparePath = fullPath + '.prepare'
|
||||||
replaceInFile(fullPath, preparePath, '$$$env$$$', env['PIOENV'])
|
replaceInFile(fullPath, preparePath, '$$$env$$$', env['PIOENV'])
|
||||||
print('Working on patch: ' + fullPath + '... ', end='')
|
print('Working on patch: ' + fullPath + '... ', end='')
|
||||||
|
|
||||||
|
# Check if patch was already applied
|
||||||
|
process = subprocess.run(['git', 'apply', '--reverse', '--check', preparePath], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
if (process.returncode == 0):
|
||||||
|
print('already applied')
|
||||||
|
os.remove(preparePath)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Apply patch
|
||||||
|
process = subprocess.run(['git', 'apply', preparePath])
|
||||||
|
if (process.returncode == 0):
|
||||||
|
print('applied')
|
||||||
|
else:
|
||||||
|
print('failed')
|
||||||
|
|
||||||
# Check if patch was already applied
|
|
||||||
process = subprocess.run(['git', 'apply', '--reverse', '--check', preparePath], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
||||||
if (process.returncode == 0):
|
|
||||||
print('already applied')
|
|
||||||
os.remove(preparePath)
|
os.remove(preparePath)
|
||||||
continue
|
|
||||||
|
|
||||||
# Apply patch
|
|
||||||
process = subprocess.run(['git', 'apply', preparePath])
|
|
||||||
if (process.returncode == 0):
|
|
||||||
print('applied')
|
|
||||||
else:
|
|
||||||
print('failed')
|
|
||||||
|
|
||||||
os.remove(preparePath)
|
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@ -59,6 +59,8 @@ board_build.embed_files =
|
|||||||
webapp_dist/js/app.js.gz
|
webapp_dist/js/app.js.gz
|
||||||
webapp_dist/site.webmanifest
|
webapp_dist/site.webmanifest
|
||||||
|
|
||||||
|
custom_patches =
|
||||||
|
|
||||||
monitor_filters = esp32_exception_decoder, time, log2file, colorize
|
monitor_filters = esp32_exception_decoder, time, log2file, colorize
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
@ -75,13 +77,13 @@ build_flags = ${env.build_flags}
|
|||||||
|
|
||||||
[env:generic_esp32c3]
|
[env:generic_esp32c3]
|
||||||
board = esp32-c3-devkitc-02
|
board = esp32-c3-devkitc-02
|
||||||
custom_patches = esp32c3
|
custom_patches = ${env.custom_patches},esp32c3
|
||||||
build_flags = ${env.build_flags}
|
build_flags = ${env.build_flags}
|
||||||
|
|
||||||
|
|
||||||
[env:generic_esp32c3_usb]
|
[env:generic_esp32c3_usb]
|
||||||
board = esp32-c3-devkitc-02
|
board = esp32-c3-devkitc-02
|
||||||
custom_patches = esp32c3
|
custom_patches = ${env.custom_patches},esp32c3
|
||||||
build_flags = ${env.build_flags}
|
build_flags = ${env.build_flags}
|
||||||
-DARDUINO_USB_MODE=1
|
-DARDUINO_USB_MODE=1
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user