- VisualStudio2022插件的安装及使用-编程手把手系列文章
- pprof-在现网场景怎么用
- C#实现的下拉多选框,下拉多选树,多级节点
- 【学习笔记】基础数据结构:猫树
最近想移植个LVGL玩玩,发现文件实在是太多了,加的手疼都没搞完,实在不想搞了就去找脚本和工具,基本没找到一个。。。。。.
主要是自己也懒得去研究写脚本,偶然搜到了一个博主写的脚本,原博客地址:https://blog.csdn.net/riyue2044/article/details/139424599 。
但是有以下问题:
1.这个脚本的.h文件也加在了分组下面,这样一般是不对的,应该加在Target的C/C++的Include path里面 。
2.脚本没有重复添加检测,导致如果多次添加,会损坏工程文件 。
3.输入是命令行式的,使用者可能会忘了参数具体设置 。
。
之前没接触过XML,python也不熟,所以研究了一下,做以下修改 。
1.把之前的命令行式的输入改为先运行再输入,会提示具体的参数设置,有默认参数,是以我的工程包来写的 。
2.把.h文件路径直接加在了Target的C/C++的Include path里面 。
3.加入文件路径检测,重复添加不会导致文件损坏 。
4.加入更多提示 。
5.加入三种模式 0:.c文件和.h路径会一起添加 1:只加.c文件 2:只加.h路径 。
。
使用方法:需要安装python,或者用python打包成exe文件也可,命令参考:pyinstaller -F -i .\icon.ico .\keil_add_file.py,放个百度云的链接,里面有我打包好的,不过注意杀毒软件估计会报毒,请添加信任 。
链接:https://pan.baidu.com/s/1zC7kVboAtQwHZ2Zy5RFmIw?pwd=arzd 提取码:arzd 。
脚本需放在keil工程目录,需要添加的目录则以相对路径填充,比如"../../../external/lvgl",需要注意的是分组需要提前在keil里面创建好,这个懒得改了,有需要的朋友可以自行修改 。
脚本内容如下:
1 import os 2 import glob 3 import xml.etree.ElementTree as ET 4 import argparse 5 6 def indent(elem, level=0): 7 """ Helper function to indent the XML for pretty printing. """ 8 i = "\n" + level * " " 9 if len(elem): 10 if not elem.text or not elem.text.strip(): 11 elem.text = i + " " 12 if not elem.tail or not elem.tail.strip(): 13 elem.tail = i 14 for elem in elem: 15 indent(elem, level + 1) 16 if not elem.tail or not elem.tail.strip(): 17 elem.tail = i 18 else: 19 if level and (not elem.tail or not elem.tail.strip()): 20 elem.tail = i 21 if not elem.tail: 22 elem.tail = "\n" 23 24 def add_files_to_group(uvprojx_file_path, mode,folder_path, group_name_target): 25 # 改变文件扩展名从 .uvprojx 到 .xml 26 base, ext = os.path.splitext(uvprojx_file_path) 27 if ext != '.uvprojx': 28 print("工程文件扩展名不正确") 29 return 30 31 xml_path = base + '.xml' 32 os.rename(uvprojx_file_path, xml_path) 33 34 try: 35 #解析XML文件 36 tree = ET.parse(xml_path) 37 #获取根节点 38 root = tree.getroot() 39 40 if mode == 0 or mode == 1: 41 # 找到指定GroupName的Group节点 42 target_group = None 43 for group in root.findall('.//Group'): 44 group_name = group.find('GroupName') 45 if group_name is not None and group_name.text == group_name_target: 46 target_group = group 47 break 48 49 if target_group is None: 50 print(f"未发现 '{group_name_target}' 分组,请先创建分组后再尝试") 51 # 将文件扩展名改回 .uvprojx 52 os.rename(xml_path, uvprojx_file_path) 53 return 54 55 # 找到目标 Group 节点下的 Files 节点,如果不存在则创建一个 56 files_node = target_group.find('Files') 57 if files_node is None: 58 files_node = ET.SubElement(target_group, 'Files') 59 60 #寻找头文件分组 61 if mode == 0 or mode == 2: 62 print("寻找头文件分组......") 63 target_header = None 64 heard_inc = None 65 target_header = root.find('.//Cads') 66 if target_header == None: 67 print("未发现头文件分组Cads") 68 return 69 else: 70 heard_inc = target_header.find('VariousControls') 71 if heard_inc == None: 72 print("未发现头文件分组VariousControls") 73 return 74 else: 75 heard_inc = heard_inc.find('IncludePath') 76 if heard_inc == None: 77 print("未发现头文件分组IncludePath") 78 return 79 else: 80 print("找到头文件分组") 81 82 83 84 #下面没有节点 85 if mode == 0 or mode == 1: 86 creat_dot = 0 #是否需要创建节点标志,如果有重复则跳过 87 init_creat = 0 88 file_init = files_node.find('File') 89 if file_init == None: 90 creat_dot = 1 91 init_creat = 1 92 print("初始节点为空需要创建节点") 93 94 # 遍历指定文件夹,查找所有 .c 文件 95 if mode == 0 or mode == 2: 96 #print(heard_inc.text) 97 heard_data = heard_inc.text 98 99 for subdir, _, files in os.walk(folder_path): 100 #.h路径 101 if mode == 0 or mode == 2: 102 dir_path = os.path.relpath(subdir, start=os.path.dirname(xml_path)) 103 if dir_path in heard_inc.text: 104 print("需要添加的头文件路径已存在本次跳过") 105 else: 106 heard_data = heard_data + dir_path + ";" 107 108 #.c添加到分组 109 if mode == 0 or mode == 1: 110 for file in files: 111 if file.endswith('.c'): 112 # 计算相对路径 113 file_path = os.path.relpath(os.path.join(subdir, file), start=os.path.dirname(xml_path)) 114 #print("路径",file_path) 115 file_check = files_node.findall('File') 116 if init_creat == 0: 117 #print("长度",len(file_check)) 118 #遍历当前分组下的节点,检测是否已经包含了该路径,如果有直接跳过 119 for i in range(len(file_check)): 120 if file_path in file_check[i].find("FilePath").text: 121 print("节点已存在本次跳过") 122 creat_dot = 0 123 break 124 else: 125 if i == len(file_check) - 1: 126 creat_dot = 1 127 print("节点不存在,创建节点") 128 else: 129 creat_dot = 0 130 continue 131 if creat_dot == 1: 132 # 创建 File 节点并添加到 Files 节点下 133 file_node = ET.SubElement(files_node, 'File') 134 file_name_node = ET.SubElement(file_node, 'FileName') 135 file_name_node.text = file 136 file_type_node = ET.SubElement(file_node, 'FileType') 137 file_type_node.text = '1' # .c 文件类型都为 1 138 139 file_path_node = ET.SubElement(file_node, 'FilePath') 140 file_path_node.text = file_path 141 creat_dot = 0 142 init_creat = 0 143 144 if mode == 0 or mode == 2: 145 heard_data = heard_data.rstrip(";") #移除最后一个多加的; 146 heard_inc.text = heard_data 147 #print(heard_inc.text) 148 149 # 格式化 XML 150 indent(root) 151 152 # 保存修改后的 XML 文件 153 tree.write(xml_path, encoding='utf-8', xml_declaration=True) 154 print("已完成") 155 156 except ET.ParseError as e: 157 print(f"ParseError: {e}") 158 with open(xml_path, 'r', encoding='utf-8') as file: 159 lines = file.readlines() 160 start = max(0, e.position[0] - 5) 161 end = min(len(lines), e.position[0] + 5) 162 print("Context around the error:") 163 for i in range(start, end): 164 print(f"{i+1}: {lines[i].strip()}") 165 166 finally: 167 # 将文件扩展名改回 .uvprojx 168 os.rename(xml_path, uvprojx_file_path) 169 170 #寻找工程文件 171 def find_uvprojx_file(): 172 uvprojx_files = glob.glob("*.uvprojx") 173 if not uvprojx_files: 174 print("未找到工程文件,请把此文件放在keil工程目录下") 175 return None 176 elif len(uvprojx_files) > 1: 177 print("在当前目录中找到多个.uvprojx文件:") 178 for i, file in enumerate(uvprojx_files, start=1): 179 print(f"{i}. {file}") 180 print("请确保目录中只有一个.uvprojx文件") 181 return None 182 else: 183 return uvprojx_files[0] 184 185 if __name__ == "__main__": 186 print("keil一键添加文件和头文件路径脚本\n\ 187 需放在keil工程同级目录下\n\ 188 参数格式,参数用空格隔开\n\ 189 默认模式:0\n\ 190 默认路径:\"../../../external/lvgl\"\n\ 191 默认分组:\"lvgl\"\n\ 192 1.添加模式 0:全部添加(.c文件全添加到分组.h文件夹加入include路径里) 1:只添加.c文件到分组 2:只添加.h文件夹到include里\n\ 193 2.要添加的文件夹路径,请使用相对路径\n\ 194 3.要添加的分组名称,如果没有分组需要先去keil手动添加分组\n") 195 196 param = input("请输入参数:") 197 198 if param: 199 #print(param) 200 args = param.split() 201 args[0] = int(args[0]) 202 print(args) 203 else: 204 args = [0,"../../../external/lvgl","lvgl"] 205 print("使用默认参数:",args) 206 uvprojx_file_path = find_uvprojx_file() 207 if uvprojx_file_path: 208 add_files_to_group(uvprojx_file_path, args[0],args[1],args[2])
。
最后此篇关于Keil一键添加.c文件和头文件路径脚本--可遍历添加整个文件夹的文章就讲到这里了,如果你想了解更多关于Keil一键添加.c文件和头文件路径脚本--可遍历添加整个文件夹的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我正在尝试为 EFM8 微 Controller 项目创建一个结构链表。我想让编译器在编译时为所有节点分配内存。我遇到的问题是没有为结构指针分配内存。 #define FOO_QUEUE_LEN
我想写一个程序来对分数进行排名这是我的尝试: int i,j,s[5][2],tmp,p; for(i=0;is[p][1]) { tmp=s
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度的了解。包括尝试的解决方案、为什么它们不起作用以及预期结果
我动态地将一些代码加载到 RAM 中,并尝试对其进行调试。当在 uVision 中单步执行代码时,它总是会跳过当前项目中不存在的所有代码,并在来自当前项目的第一条指令处停止。这导致它也跳过我的动态加载
在我正在从事的这个项目之前,我从未使用过 keil,但我总是能够只说 printf("hello); 并且它有效。 但是,对于 keil,我无法在调试 (printf) 查看器中显示它。 我在我的主要
我正在使用 Keil uVision v5.14 为 nrf51xx cpu 编译一些代码。我一直使用一个名为 nrf_delay.h 的头文件,它有一些用汇编程序编码的延迟例程。突然,在编译期间,在
这个 C 程序应该模拟一个数字时钟。 Proteus 程序中将有 3 个 7segment 来显示小时、分钟和秒(就像数字时钟) #include void main() { int t, i, j,
Keil 在 ARM7 开发方面与 GCC 相比如何?我正在为一个中等规模的项目选择硬件顾问,有些使用 keil,有些使用 gcc。我想知道使用任何一种选择所涉及的问题...... 最佳答案 从编码/
我想在 Keil uVision 中找到自动对齐快捷键。我尝试了一些快捷键,但我找不到。在 Visual Studio 中我曾经: CTRL + K + D ,但在 keil uVision 中我不知
我正在使用 Keil uVision4 IDE 对 NXP LPC1768 进行编程。我需要组合两个十六进制文件的建议。这两个文件将是一个引导加载程序和一个用于生产编程的应用程序。目前,我能够成功地将
Arduino 有一个delay(ms) 函数来暂停程序一段时间。以毫秒为单位非常准确。 我在用于 AT89C5131 微 Controller 的 Keil uVision 中使用的 C 中有一个延
我使用这些代码从 uart 接收字符串,然后将它们与此枚举匹配,然后将它们放在 switch-case 上。 char temp[3],rx_buf[100]; enum form { GGA = 1
我正在尝试在Keil中使用sprintf();函数。但我有一个烦人的警告。让我用下面的示例代码部分解释我的警告。当我调试时,我得到; warning: #167-D: argument of type
我在尝试 #include iostream 时遇到一些错误。我知道问题出在 iostream 上,因为我的项目之前编译过,但是在包含 iostream 之后我有错误。 我正在尝试使用 iostrea
我正在使用 Keil 4 和用于 Cortex M3 的 ARM 工具集(如果这很重要的话)。我试过这个简单的代码: class Base { public: virtual ~Bas
我正在使用 Keil uVision 为嵌入式项目编译这段代码。 void doSomething(void) { unsigned char a = 0x01; unsigned c
我正在尝试通过通用编程器 (SuperPro) 将 Blinky 程序从 Keil 编译器编程到 P89LPC936 微 Controller 。但是微 Controller 没有运行。但是当我用 a
(数组是用一堆字符初始化的) 当我使数组变大时,我也会收到“数据段太大”的错误消息。如何将数组从“CODE”复制到“XDATA”?或者这不是问题所在? 编辑:同样,当我以这种方式调用该函数时,lcd
我从 Nordic SDK 的 keil 示例项目开始。这个问题不是关于nordic sdk,而是Keil如何连接头文件和源文件。在我能理解的情况下,Keil 隐藏了所有合并到 main.c 文件中的
当我从 main() 调用包含无限循环的 C 函数时,它会在执行该函数之前将一些寄存器压入堆栈。由于该函数包含一个无限循环,因此这些寄存器永远不会被弹出。 举个例子 void My_Func (voi
我是一名优秀的程序员,十分优秀!