wpioasm.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # WizIO 2021 Georgi Angelov
  2. # http://www.wizio.eu/
  3. # https://github.com/Wiz-IO/wizio-pico
  4. from __future__ import print_function
  5. import os, platform
  6. from platform import system, machine
  7. from os.path import join
  8. from SCons.Script import (AlwaysBuild, Builder, COMMAND_LINE_TARGETS, Default, DefaultEnvironment)
  9. from colorama import Fore
  10. from subprocess import check_output, CalledProcessError, call, Popen, PIPE
  11. from time import sleep
  12. def execute(cmd):
  13. proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
  14. out, err = proc.communicate()
  15. lines = out.decode().split("\r\n")
  16. error = err.decode().split("\r\n")
  17. if proc.returncode == 0:
  18. COLOR = Fore.GREEN
  19. else:
  20. COLOR = Fore.RED
  21. for i in range( len(error) ):
  22. print( COLOR + error[i] )
  23. sleep(0.05)
  24. return proc.returncode
  25. def dev_pioasm(env):
  26. sys_dir = system() +'_'+ machine()
  27. sys_dir = sys_dir.lower()
  28. if 'windows' in sys_dir:
  29. sys_dir = 'windows'
  30. tool = env.PioPlatform().get_package_dir("tool-wizio-pico")
  31. if None == tool:
  32. print( Fore.RED + '[PIO-ASM] ERROR: The', sys_dir, 'is no supported yet...' )
  33. return
  34. names = env.BoardConfig().get("build.pio", "0")
  35. if '0' == names:
  36. return
  37. for src_name in names.split():
  38. dst_name = src_name + '.h'
  39. src = join(env.subst("$PROJECT_DIR"), src_name).replace("\\", "/")
  40. dst = join(env.subst("$PROJECT_DIR"), dst_name).replace("\\", "/")
  41. if True == os.path.isfile( dst ):
  42. print(Fore.CYAN + '[PIO-ASM] File (', os.path.basename(dst), ') exist' )
  43. continue
  44. if False == os.path.isfile( src ):
  45. print(Fore.RED + '[PIO-ASM] ERROR: Source file not exist ', src, "\n")
  46. exit(1)
  47. if False == os.path.isdir( os.path.dirname( dst ) ):
  48. print(Fore.RED + '[PIO-ASM] ERROR: Destination folder not exist', os.path.dirname( dst ), "\n")
  49. exit(1)
  50. cmd = []
  51. cmd.append(join(tool, sys_dir, 'pioasm') )
  52. cmd.append(join(env.subst("$PROJECT_DIR"), src))
  53. cmd.append(join(env.subst("$PROJECT_DIR"), dst))
  54. if execute(cmd) != 0:
  55. exit(1)