Skip to content

Commit 1ee8082

Browse files
iceshadowsJiu-xiao
iceshadows
authored andcommitted
update utils/python/tool.py for windows
Signed-off-by: iceshadows <[email protected]>
1 parent 99a94d0 commit 1ee8082

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

utils/python/tool.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import os
33
import shutil
4+
import subprocess
45

56

67
class ProjectTools:
@@ -22,14 +23,24 @@ def __init__(self):
2223
exit()
2324

2425
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.")
2834

2935
def menuconfig(self, path):
3036
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.")
3344

3445
def clean_cache(self):
3546
filepath = self.project_path + "/build"
@@ -48,13 +59,20 @@ def clean_cache(self):
4859
shutil.rmtree(file_path)
4960

5061
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.")
5876

5977
def config_cmake_idf(self, type="Debug"):
6078
os.system(

0 commit comments

Comments
 (0)