Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tools/mdk5] 如果本地设置了UV4.exe 命令,则进行MDK编译 #9951

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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