Skip to content

Commit

Permalink
[tools/mdk5] 如果本地设置了UV4.exe 命令,则进行MDK编译
Browse files Browse the repository at this point in the history
  • Loading branch information
supperthomas authored and mysterywolf committed Jan 26, 2025
1 parent 40f3b6a commit 9be28db
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tools/keil.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import os
import sys
import string
import shutil

import xml.etree.ElementTree as etree
from xml.etree.ElementTree import SubElement
Expand Down Expand Up @@ -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:
Expand All @@ -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")
Expand Down

0 comments on commit 9be28db

Please sign in to comment.