2525import os
2626import sys
2727import string
28+ import shutil
2829
2930import xml .etree .ElementTree as etree
3031from xml .etree .ElementTree import SubElement
@@ -337,7 +338,20 @@ def MDK4Project(target, script):
337338 if os .path .exists ('template.uvopt' ):
338339 import shutil
339340 shutil .copy2 ('template.uvopt' , '{}.uvopt' .format (os .path .splitext (target )[0 ]))
340-
341+ import threading
342+ import time
343+ def monitor_log_file (log_file_path ):
344+ if not os .path .exists (log_file_path ):
345+ open (log_file_path , 'w' ).close ()
346+ with open (log_file_path , 'r' ) as log_file :
347+ while True :
348+ line = log_file .readline ()
349+ if line :
350+ print (line .strip ())
351+ if 'Build Time Elapsed' in line :
352+ break
353+ else :
354+ time .sleep (0.1 )
341355def MDK5Project (target , script ):
342356
343357 if os .path .isfile ('template.uvprojx' ) is False :
@@ -356,6 +370,19 @@ def MDK5Project(target, script):
356370 if os .path .exists ('template.uvoptx' ):
357371 import shutil
358372 shutil .copy2 ('template.uvoptx' , '{}.uvoptx' .format (os .path .splitext (target )[0 ]))
373+ # build with UV4.exe
374+ if shutil .which ('UV4.exe' ) is not None :
375+ log_file_path = 'keil.log'
376+ if os .path .exists (log_file_path ):
377+ os .remove (log_file_path )
378+ log_thread = threading .Thread (target = monitor_log_file , args = (log_file_path ,))
379+ log_thread .start ()
380+ cmd = 'UV4.exe -b project.uvprojx -q -j0 -t rt-thread -o ' + log_file_path
381+ print ('Start to build keil project' )
382+ print (cmd )
383+ os .system (cmd )
384+ else :
385+ print ('UV4.exe is not available, please check your keil installation' )
359386
360387def MDK2Project (target , script ):
361388 template = open ('template.Uv2' , "r" )
0 commit comments