Skip to content

Commit

Permalink
lib: attempt to speed-up builds by removing unneeded files in extraSc…
Browse files Browse the repository at this point in the history
…ript
  • Loading branch information
and3rson committed Mar 2, 2024
1 parent 3875a1b commit c3b25ac
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sdk/lib/lilka/library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Lilka",
"version": "1.1.4",
"version": "1.1.5",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -24,6 +24,10 @@
"include": [
"src",
"examples",
"README.md"
]
"README.md",
"prepare.py"
],
"build": {
"extraScript": "prepare.py"
}
}
83 changes: 83 additions & 0 deletions sdk/lib/lilka/prepare.py
Original file line number Diff line number Diff line change
@@ -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.")

0 comments on commit c3b25ac

Please sign in to comment.