|
| 1 | +# Build-time Patches |
| 2 | + |
| 3 | +MicroPythonOS builds from pinned upstream sources (MicroPython, LVGL, the |
| 4 | +`lvgl_micropython` binding) and applies a small set of patches at build time |
| 5 | +instead of forking those projects. This page is the single reference for |
| 6 | +where those patches live, how they are applied, and how to add or update one. |
| 7 | + |
| 8 | +## Two families |
| 9 | + |
| 10 | +| Family | Where the `.patch` files live | What they patch | Applied by | |
| 11 | +|---|---|---|---| |
| 12 | +| **lvgl_micropython patches** | root of the [`lvgl_micropython`](https://github.com/MicroPythonOS/lvgl_micropython) repo (`integration` branch) | files under its `lib/micropython`, `lib/lvgl`, or the repo itself (e.g. `builder/`) | `scripts/build_mpos.sh` (`apply_patch`) | |
| 13 | +| **Web-port patches** | `scripts/web_port/` in the [`MicroPythonOS`](https://github.com/MicroPythonOS/MicroPythonOS) repo | `lvgl_micropython` files needed only by the Emscripten target | `scripts/build_mpos.sh web`, see [Web Port Developer Info](../web-port/developer.md#submodule-patches-applied-automatically) | |
| 14 | + |
| 15 | +Everything else about the two families is the same: a unified diff created |
| 16 | +with `git diff`, applied with `patch -p1 --forward`, idempotent on rebuilds. |
| 17 | + |
| 18 | +## How `apply_patch` behaves |
| 19 | + |
| 20 | +`scripts/build_mpos.sh` applies every patch through one helper: |
| 21 | + |
| 22 | +```bash |
| 23 | +apply_patch <directory to patch in> <patch file> |
| 24 | +``` |
| 25 | + |
| 26 | +1. If the patch applies forward, it is applied. |
| 27 | +2. Else if it applies in reverse — meaning it is already present — it is |
| 28 | + skipped with `Patch ... already applied, skipping.` |
| 29 | +3. Otherwise the build **fails** (`FATAL: patch ... does not apply`). A patch |
| 30 | + that silently stops applying once shipped a broken build, so this is on |
| 31 | + purpose: fix or regenerate the patch instead of ignoring it. |
| 32 | + |
| 33 | +Patches that were added after some pinned `lvgl_micropython` commits are |
| 34 | +**existence-guarded** (`if [ -f "$patch" ]`) so MicroPythonOS can still build |
| 35 | +against older submodule pins; copy that pattern for new patches. |
| 36 | + |
| 37 | +## Current lvgl_micropython patches |
| 38 | + |
| 39 | +Read `scripts/build_mpos.sh` for the authoritative list and the target of |
| 40 | +each; at the time of writing: |
| 41 | + |
| 42 | +- Applied for **every** target, in `lvgl_micropython/lib/micropython` or |
| 43 | + `lvgl_micropython/lib/lvgl`: `esp32_uart_repl_runtime.patch`, |
| 44 | + `mpremote_no_auto_soft_reset.patch`, `lib_lvgl_lv_bmp.c.patch`, |
| 45 | + `lib_lvgl_src_libs_tjpgd_fix_scaling.patch`, `imgfont_set_range.patch` |
| 46 | + (guarded). |
| 47 | +- **ESP32** builds only: `esp32_inisetup_warn_and_format.patch`, |
| 48 | + `esp32_inisetup_readsize_progsize.patch`, |
| 49 | + `network_wlan_country_japan.patch`, `network_wlan_config_country.patch`. |
| 50 | +- **Desktop (unix/macOS)** builds only: `unix_autoimport_main.patch`, |
| 51 | + `unix_native_decorator_fallback.patch` (guarded), and |
| 52 | + `unix_sdl_release_2_32_8.patch` (guarded; patches `builder/unix.py` in the |
| 53 | + `lvgl_micropython` repo itself, applied in that directory). |
| 54 | + |
| 55 | +## Adding a patch |
| 56 | + |
| 57 | +1. Make the change directly in the checked-out submodule tree and verify the |
| 58 | + build. |
| 59 | +2. Generate the diff **from the directory the patch will be applied in**, so |
| 60 | + the paths are right for `patch -p1`: |
| 61 | + |
| 62 | + ```bash |
| 63 | + # a MicroPython change: |
| 64 | + cd lvgl_micropython/lib/micropython |
| 65 | + git diff -- ports/unix/main.c > ../../my_change.patch |
| 66 | + |
| 67 | + # a change to lvgl_micropython itself (e.g. builder/): |
| 68 | + cd lvgl_micropython |
| 69 | + git diff -- builder/unix.py > my_change.patch |
| 70 | + ``` |
| 71 | + |
| 72 | +3. Commit the `.patch` file to `lvgl_micropython` (branch off `integration`, |
| 73 | + see its [CONTRIBUTING.md](https://github.com/MicroPythonOS/lvgl_micropython/blob/integration/CONTRIBUTING.md)) |
| 74 | + and open a **companion PR** in MicroPythonOS adding an `apply_patch` call |
| 75 | + to `scripts/build_mpos.sh` in the right target section, existence-guarded. |
| 76 | +4. Revert your direct edit in the submodule and rebuild: the build must |
| 77 | + re-apply the patch cleanly (no `.rej` files). |
| 78 | + |
| 79 | +Web-port patches follow the same steps but live in `scripts/web_port/` and |
| 80 | +need no companion PR; the update commands are in the |
| 81 | +[Web Port Developer Info](../web-port/developer.md#updating-a-submodule-patch). |
| 82 | + |
| 83 | +## Updating a patch |
| 84 | + |
| 85 | +Regenerate it the same way (edit the file in the submodule, `git diff` from |
| 86 | +the apply directory, overwrite the `.patch`), then rebuild from a clean |
| 87 | +submodule to prove it applies. If a submodule bump makes a patch stop |
| 88 | +applying, the build's `FATAL` message tells you which one. |
0 commit comments