Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

  1. import atexit
  2. import os
  3. import shutil
  4. import tempfile
  5. from .display import print_warning
  6. def try_remove(path):
  7. try:
  8. os.remove(path)
  9. except: # pylint: disable=bare-except
  10. print_warning("Please manually remove the file `{}`".format(path))
  11. def copy_release(target, source, env):
  12. # target filename and subdir for release files
  13. name = env["ESPURNA_RELEASE_NAME"]
  14. version = env["ESPURNA_RELEASE_VERSION"]
  15. destdir = env["ESPURNA_RELEASE_DESTINATION"]
  16. if not name or not version or not destdir:
  17. raise ValueError("Cannot set up release without release variables present")
  18. if not os.path.exists(destdir):
  19. os.makedirs(destdir)
  20. dest = os.path.join(
  21. destdir, "espurna-{version}-{name}.bin".format(version=version, name=name)
  22. )
  23. src = env.subst("$BUILD_DIR/${PROGNAME}.bin")
  24. shutil.copy(src, dest)
  25. # emulate .ino concatenation to speed up compilation times
  26. def merge_cpp(sources, output):
  27. with tempfile.TemporaryFile() as tmp:
  28. tmp.write(b"// !!! Automatically generated file; DO NOT EDIT !!! \n")
  29. tmp.write(b'#include "espurna.h"\n')
  30. for source in sources:
  31. with open(source, "rb") as fobj:
  32. shutil.copyfileobj(fobj, tmp)
  33. tmp.seek(0)
  34. with open(output, "wb") as fobj:
  35. shutil.copyfileobj(tmp, fobj)
  36. atexit.register(try_remove, output)