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/avrdude.py | |
parent | 9a10b59ba5a894e704d37a51c562c905d486b72e (diff) |
spi
Diffstat (limited to 'hid/avrdude.py')
-rw-r--r-- | hid/avrdude.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/hid/avrdude.py b/hid/avrdude.py new file mode 100644 index 00000000..1eef53b4 --- /dev/null +++ b/hid/avrdude.py @@ -0,0 +1,53 @@ +# https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html + +from os import rename +from os import symlink +from os.path import exists +from os.path import join + +import platform + +Import("env") + + +# ===== +def _get_tool_path() -> str: + path = env.PioPlatform().get_package_dir("tool-avrdude") + assert exists(path) + return path + + +def _fix_ld_arm() -> None: + tool_path = _get_tool_path() + flag_path = join(tool_path, ".fix-ld-arm.done") + + if not exists(flag_path): + def patch(*_, **__) -> None: + symlink("/usr/lib/libtinfo.so.6", join(tool_path, "libtinfo.so.5")) + open(flag_path, "w").close() + + env.Execute(patch) + + +def _replace_to_system(new_path: str) -> None: + tool_path = _get_tool_path() + flag_path = join(tool_path, ".replace-to-system.done") + + if not exists(flag_path): + def patch(*_, **__) -> None: + old_path = join(tool_path, "avrdude") + bak_path = join(tool_path, "_avrdude_bak") + rename(old_path, bak_path) + symlink(new_path, old_path) + open(flag_path, "w").close() + + env.Execute(patch) + + +# ===== +if "arm" in platform.machine(): + _fix_ld_arm() + +_path = "/usr/bin/avrdude" +if exists(_path): + _replace_to_system(_path) |