Skip to content

Commit 055050d

Browse files
committed
feat: 添加创建.clamd目录及.gitignore文件功能
- 新增`create_clangd_directory()`函数,用于创建.clamd目录并生成.gitignore文件 - 在主函数中添加对`create_clangd_directory()`的调用 - 实现自动创建clangd配置目录及忽略规则,避免编译文件污染版本库
1 parent 5c0b05a commit 055050d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ def write_compile_commands(compile_commands, output_file='compile_commands.json'
101101
except IOError as e:
102102
print(f"Failed to write to {output_file} file: {e}")
103103

104+
def create_clangd_directory():
105+
"""
106+
创建.clamd文件夹并写入.gitignore文件
107+
"""
108+
clangd_dir = os.path.join('.', '.clangd')
109+
try:
110+
os.makedirs(clangd_dir, exist_ok=True)
111+
gitignore_path = os.path.join(clangd_dir, '.gitignore')
112+
with open(gitignore_path, 'w', encoding='utf-8') as f:
113+
f.write('*')
114+
print("Successfully created .clangd directory and .gitignore file")
115+
except Exception as e:
116+
print(f"Failed to create .clangd directory or .gitignore file: {e}")
117+
104118

105119
def get_clangd_query_driver():
106120
"""获取clangd的query-driver路径"""
@@ -152,3 +166,4 @@ def find_compiler_in_settings(settings_path):
152166

153167
compile_info = parse_keil_project(keil_project_file)
154168
write_compile_commands(compile_info)
169+
create_clangd_directory()

0 commit comments

Comments
 (0)