diff options
author | Devaev Maxim <[email protected]> | 2020-10-19 23:31:46 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-11-11 22:24:25 +0300 |
commit | c27b8909dc425b4c06a12264de77877419a13497 (patch) | |
tree | f0fe668c14518cd180d3949070bc67bce02d94f0 /hid/patch.py | |
parent | 9a10b59ba5a894e704d37a51c562c905d486b72e (diff) |
spi
Diffstat (limited to 'hid/patch.py')
-rw-r--r-- | hid/patch.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/hid/patch.py b/hid/patch.py index 100c0d5b..7b88eeb1 100644 --- a/hid/patch.py +++ b/hid/patch.py @@ -1,20 +1,32 @@ -from os.path import join +# https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html + from os.path import exists +from os.path import join +from os.path import basename + +from typing import Dict Import("env") # ===== -deps_path = env.get("PROJECT_LIBDEPS_DIR", env.get("PROJECTLIBDEPS_DIR")) -assert deps_path, deps_path -env_path = join(deps_path, env["PIOENV"]) -flag_path = join(env_path, ".patched") +def _get_libs() -> Dict[str, str]: + return { + builder.name: builder.path + for builder in env.GetLibBuilders() + } + -if not exists(flag_path): - env.Execute(f"patch -p1 -d {join(env_path, 'HID-Project')} < {join('patches', 'absmouse.patch')}") +def _patch_lib(lib_path: str, patch_path: str) -> None: + assert exists(lib_path) + flag_path: str = join(lib_path, f".{basename(patch_path)}.done") + if not exists(flag_path): + env.Execute(f"patch -p1 -d {lib_path} < {patch_path}") + env.Execute(lambda *_, **__: open(flag_path, "w").close()) - def touch_flag(*_, **__) -> None: - with open(flag_path, "w") as flag_file: - pass - env.Execute(touch_flag) +# ===== +_libs = _get_libs() +assert "TimerOne" in _libs # Just checking +if "HID-Project" in _libs: + _patch_lib(_libs["HID-Project"], "patches/absmouse.patch") |