From c3b25ac2dd045cfd32a1663b954eca58a5502185 Mon Sep 17 00:00:00 2001 From: Andrew Dunai Date: Sun, 3 Mar 2024 01:27:19 +0200 Subject: [PATCH] lib: attempt to speed-up builds by removing unneeded files in extraScript --- sdk/lib/lilka/library.json | 10 +++-- sdk/lib/lilka/prepare.py | 83 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 sdk/lib/lilka/prepare.py diff --git a/sdk/lib/lilka/library.json b/sdk/lib/lilka/library.json index 8aa73e13..1f3649b7 100644 --- a/sdk/lib/lilka/library.json +++ b/sdk/lib/lilka/library.json @@ -1,6 +1,6 @@ { "name": "Lilka", - "version": "1.1.4", + "version": "1.1.5", "license": "MIT", "repository": { "type": "git", @@ -24,6 +24,10 @@ "include": [ "src", "examples", - "README.md" - ] + "README.md", + "prepare.py" + ], + "build": { + "extraScript": "prepare.py" + } } diff --git a/sdk/lib/lilka/prepare.py b/sdk/lib/lilka/prepare.py new file mode 100644 index 00000000..f83c0dda --- /dev/null +++ b/sdk/lib/lilka/prepare.py @@ -0,0 +1,83 @@ +""" +This script removes some files from the libraries that Lilka uses, specifically: + - GFX library code that is not used by the ST7789 display and ESP32 SPI interface + - U8g2 display code (we only use the U8g2lib library for the font data) + +This really speeds up the build process, but I'm not sure if it won't break in the future. +Але, як то кажуть - "це працює на моїй машині" ;) +""" +import os +import re +import shutil +import sys +from pathlib import Path +from itertools import chain + +Import("env") + +keep = ["Arduino_ESP32SPI", "Arduino_ST7789"] + +try: + lib_dir = Path(os.path.join(env.get("PROJECT_LIBDEPS_DIR"), env.get("PIOENV"))) + for lib in lib_dir.glob("*"): + modified_count = 0 + deleted_count = 0 + if lib.name == "GFX Library for Arduino": + # Remote all files in the GFX library that are not used by the ST7789 display and ESP32 SPI interface + + # Delete all files in the databus folder that don't match the pattern "Arduino_ESP32SPI.(c|h)" + databus_dir = lib / "src" / "databus" + for f in chain(databus_dir.glob("*.cpp"), databus_dir.glob("*.h")): + if f.stem not in keep: + # print("Deleting {}".format(f.name)) + f.unlink() + deleted_count += 1 + display_dir = lib / "src" / "display" + for f in chain(display_dir.glob("*.cpp"), display_dir.glob("*.h")): + if f.stem not in keep: + # print("Deleting {}".format(f.name)) + f.unlink() + deleted_count += 1 + + # Remove Arduino_GFX_Library.cpp because it includes some of the files we just deleted + main_cpp = lib / "src" / "Arduino_GFX_Library.cpp" + if main_cpp.exists(): + main_cpp.unlink() + deleted_count += 1 + + # Cleanup includes + main_h = lib / "src" / "Arduino_GFX_Library.h" + text = main_h.read_text() + lines = text.splitlines() + lines = [ + line + for line in lines + if not ( + line.startswith("#include") + and ("databus/" in line or "display/" in line) + and not any([k + ".h" in line for k in keep]) + ) + ] + new_text = "\n".join(lines) + if text != new_text: + main_h.write_text(new_text) + modified_count += 1 + if lib.name == "U8g2": + # Remove all display code + clib_dir = lib / "src" / "clib" + for f in clib_dir.glob("u8x8*.c"): + # print("Deleting {}".format(f.name)) + f.unlink() + deleted_count += 1 + if modified_count + deleted_count > 0: + print( + ' * Cleanup "{}": deleted {}, modified {}'.format( + lib.name, deleted_count, modified_count + ) + ) + +except Exception as e: + # Get exception line number + tb = sys.exc_info()[2] + print(" * Error in Lilka prepare.py script, line {}: {}".format(tb.tb_lineno, e)) + print(" * This is just a warning about failed cleanup. The build will continue.")