Skip to content

Commit 9be28db

Browse files
supperthomasmysterywolf
authored andcommitted
[tools/mdk5] 如果本地设置了UV4.exe 命令,则进行MDK编译
1 parent 40f3b6a commit 9be28db

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

tools/keil.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import sys
2727
import string
28+
import shutil
2829

2930
import xml.etree.ElementTree as etree
3031
from xml.etree.ElementTree import SubElement
@@ -337,7 +338,26 @@ 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+
empty_line_count = 0
347+
with open(log_file_path, 'r') as log_file:
348+
while True:
349+
line = log_file.readline()
350+
if line:
351+
print(line.strip())
352+
if 'Build Time Elapsed' in line:
353+
break
354+
empty_line_count = 0
355+
else:
356+
empty_line_count += 1
357+
time.sleep(1)
358+
if empty_line_count > 30:
359+
print("Timeout reached or too many empty lines, exiting log monitoring thread.")
360+
break
341361
def MDK5Project(target, script):
342362

343363
if os.path.isfile('template.uvprojx') is False:
@@ -356,6 +376,22 @@ def MDK5Project(target, script):
356376
if os.path.exists('template.uvoptx'):
357377
import shutil
358378
shutil.copy2('template.uvoptx', '{}.uvoptx'.format(os.path.splitext(target)[0]))
379+
# build with UV4.exe
380+
381+
if shutil.which('UV4.exe') is not None:
382+
target_name = template_tree.find('Targets/Target/TargetName')
383+
print('target_name:', target_name.text)
384+
log_file_path = 'keil.log'
385+
if os.path.exists(log_file_path):
386+
os.remove(log_file_path)
387+
log_thread = threading.Thread(target=monitor_log_file, args=(log_file_path,))
388+
log_thread.start()
389+
cmd = 'UV4.exe -b project.uvprojx -q -j0 -t '+ target_name.text +' -o '+log_file_path
390+
print('Start to build keil project')
391+
print(cmd)
392+
os.system(cmd)
393+
else:
394+
print('UV4.exe is not available, please check your keil installation')
359395

360396
def MDK2Project(target, script):
361397
template = open('template.Uv2', "r")

0 commit comments

Comments
 (0)