1
1
import sys
2
2
import os
3
3
import shutil
4
+ import subprocess
4
5
5
6
6
7
class ProjectTools :
@@ -22,14 +23,24 @@ def __init__(self):
22
23
exit ()
23
24
24
25
def guiconfig (self , path ):
25
- print ("Start menu config." )
26
- os .system ("cd " + path + " && python3 " + self .kconfig_path + "/guiconfig.py" )
27
- print ("Menu config done." )
26
+ print ("Start GUI config." )
27
+ try :
28
+ # 使用sys.executable调用当前虚拟环境的Python解释器
29
+ subprocess .run ([sys .executable , self .kconfig_path + "/guiconfig.py" ], cwd = path , check = True )
30
+ except subprocess .CalledProcessError as e :
31
+ print ("Failed to run GUI config: " , e )
32
+ else :
33
+ print ("GUI config done." )
28
34
29
35
def menuconfig (self , path ):
30
36
print ("Start menu config." )
31
- os .system ("cd " + path + " && python3 " + self .kconfig_path + "/menuconfig.py" )
32
- print ("Menu config done." )
37
+ try :
38
+ # 使用sys.executable调用当前虚拟环境的Python解释器
39
+ subprocess .run ([sys .executable , self .kconfig_path + "/menuconfig.py" ], cwd = path , check = True )
40
+ except subprocess .CalledProcessError as e :
41
+ print ("Failed to run menu config: " , e )
42
+ else :
43
+ print ("Menu config done." )
33
44
34
45
def clean_cache (self ):
35
46
filepath = self .project_path + "/build"
@@ -48,13 +59,20 @@ def clean_cache(self):
48
59
shutil .rmtree (file_path )
49
60
50
61
def config_cmake (self , type = "Debug" ):
51
- os .system (
52
- "cd "
53
- + self .project_path
54
- + " && cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=utils/CMake/toolchain.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING="
55
- + type
56
- + " -Bbuild -G Ninja"
57
- )
62
+ try :
63
+ subprocess .run ([
64
+ "cmake" ,
65
+ "--no-warn-unused-cli" ,
66
+ f"-DCMAKE_TOOLCHAIN_FILE:STRING=utils/CMake/toolchain.cmake" ,
67
+ "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE" ,
68
+ f"-DCMAKE_BUILD_TYPE:STRING={ type } " ,
69
+ "-Bbuild" ,
70
+ "-G" , "Ninja"
71
+ ], cwd = self .project_path , check = True )
72
+ except subprocess .CalledProcessError as e :
73
+ print (f"Failed to configure CMake: { e } " )
74
+ else :
75
+ print ("CMake configuration successful." )
58
76
59
77
def config_cmake_idf (self , type = "Debug" ):
60
78
os .system (
0 commit comments