From 9be28dbc67523d39404a05cb70b8a2f98853082f Mon Sep 17 00:00:00 2001 From: Supper Thomas <78900636@qq.com> Date: Sun, 26 Jan 2025 15:34:36 +0800 Subject: [PATCH] =?UTF-8?q?[tools/mdk5]=20=E5=A6=82=E6=9E=9C=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E8=AE=BE=E7=BD=AE=E4=BA=86UV4.exe=20=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=EF=BC=8C=E5=88=99=E8=BF=9B=E8=A1=8CMDK=E7=BC=96?= =?UTF-8?q?=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/keil.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tools/keil.py b/tools/keil.py index 8cd58c03994..c878f5f5080 100644 --- a/tools/keil.py +++ b/tools/keil.py @@ -25,6 +25,7 @@ import os import sys import string +import shutil import xml.etree.ElementTree as etree from xml.etree.ElementTree import SubElement @@ -337,7 +338,26 @@ def MDK4Project(target, script): if os.path.exists('template.uvopt'): import shutil shutil.copy2('template.uvopt', '{}.uvopt'.format(os.path.splitext(target)[0])) - +import threading +import time +def monitor_log_file(log_file_path): + if not os.path.exists(log_file_path): + open(log_file_path, 'w').close() + empty_line_count = 0 + with open(log_file_path, 'r') as log_file: + while True: + line = log_file.readline() + if line: + print(line.strip()) + if 'Build Time Elapsed' in line: + break + empty_line_count = 0 + else: + empty_line_count += 1 + time.sleep(1) + if empty_line_count > 30: + print("Timeout reached or too many empty lines, exiting log monitoring thread.") + break def MDK5Project(target, script): if os.path.isfile('template.uvprojx') is False: @@ -356,6 +376,22 @@ def MDK5Project(target, script): if os.path.exists('template.uvoptx'): import shutil shutil.copy2('template.uvoptx', '{}.uvoptx'.format(os.path.splitext(target)[0])) + # build with UV4.exe + + if shutil.which('UV4.exe') is not None: + target_name = template_tree.find('Targets/Target/TargetName') + print('target_name:', target_name.text) + log_file_path = 'keil.log' + if os.path.exists(log_file_path): + os.remove(log_file_path) + log_thread = threading.Thread(target=monitor_log_file, args=(log_file_path,)) + log_thread.start() + cmd = 'UV4.exe -b project.uvprojx -q -j0 -t '+ target_name.text +' -o '+log_file_path + print('Start to build keil project') + print(cmd) + os.system(cmd) + else: + print('UV4.exe is not available, please check your keil installation') def MDK2Project(target, script): template = open('template.Uv2', "r")