Skip to content

Commit 49950c0

Browse files
committed
[scons] ci.attachconfig.yml is used in combination with scons
1 parent ed3222c commit 49950c0

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

tools/building.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import rtconfig
3434
import platform
3535
import logging
36+
import shutil
37+
import yaml
3638

3739
from SCons.Script import *
3840
from utils import _make_path_relative
@@ -44,6 +46,78 @@
4446
Rtt_Root = ''
4547
Env = None
4648

49+
# SCons AttachConfig Command Function
50+
def GenAttachConfigProject(program = None):
51+
Rtt_Root = os.getcwd()
52+
config_file = os.path.join(os.getcwd(), 'rtt_root', Rtt_Root, '.config')
53+
config_bacakup = config_file+'.origin'
54+
rtconfig_file = os.path.join(os.getcwd(), 'rtt_root', Rtt_Root, 'rtconfig.h')
55+
rtconfig__bacakup = rtconfig_file+'.origin'
56+
if GetOption('attach') == '?':
57+
attachconfig=[]
58+
GetAttachConfig("get",attachconfig,0)
59+
print("\033[32m✅ AttachConfig has: \033[0m"+','.join(attachconfig))
60+
elif GetOption('attach') == 'default':
61+
shutil.copyfile(config_bacakup, config_file)
62+
shutil.copyfile(rtconfig__bacakup, rtconfig_file)
63+
if os.path.exists(config_bacakup):
64+
os.remove(config_bacakup)
65+
if os.path.exists(rtconfig__bacakup):
66+
os.remove(rtconfig__bacakup)
67+
print("\033[32m✅ Default .config and rtconfig.h recovery success!\033[0m")
68+
else:
69+
attachconfig=GetOption('attach')
70+
attachconfig_result=[]
71+
GetAttachConfig("search",attachconfig,attachconfig_result)
72+
if attachconfig_result==[]:
73+
print("❌\033[31m Without this AttachConfig:"+attachconfig+"\033[0m")
74+
return
75+
if os.path.exists(config_bacakup)==False:
76+
shutil.copyfile(config_file, config_bacakup)
77+
if os.path.exists(rtconfig__bacakup)==False:
78+
shutil.copyfile(rtconfig_file, rtconfig__bacakup)
79+
with open(config_file, 'a') as destination:
80+
for line in attachconfig_result:
81+
destination.write(line + '\n')
82+
from env_utility import defconfig
83+
defconfig(Rtt_Root)
84+
print("\033[32m✅ AttachConfig add success!\033[0m")
85+
86+
def GetAttachConfig(action,attachconfig,attachconfig_result):
87+
rtt_root = os.getcwd()
88+
yml_files_content = []
89+
directory = os.path.join(rtt_root, 'rtt_root', rtt_root, '.ci/attachconfig')
90+
if os.path.exists(directory):
91+
for root, dirs, files in os.walk(directory):
92+
for filename in files:
93+
if filename.endswith('attachconfig.yml'):
94+
file_path = os.path.join(root, filename)
95+
if os.path.exists(file_path):
96+
try:
97+
with open(file_path, 'r') as file:
98+
content = yaml.safe_load(file)
99+
if content is None:
100+
continue
101+
yml_files_content.append(content)
102+
except yaml.YAMLError as e:
103+
print(f"::error::Error parsing YAML file: {e}")
104+
continue
105+
except Exception as e:
106+
print(f"::error::Error reading file: {e}")
107+
continue
108+
for projects in yml_files_content:
109+
for name, details in projects.items():
110+
if details.get("kconfig") is None:
111+
continue
112+
if(projects.get(name) is not None):
113+
if action == "get":
114+
attachconfig.append(name)
115+
if action == "search" and name == attachconfig:
116+
from ci.bsp_buildings import get_details_and_dependencies
117+
detail_list=get_details_and_dependencies([name],projects)
118+
for line in detail_list:
119+
attachconfig_result.append(line)
120+
47121
# SCons PreProcessor patch
48122
def start_handling_includes(self, t=None):
49123
"""
@@ -336,6 +410,10 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
336410
else:
337411
print('--global-macros arguments are illegal!')
338412

413+
if GetOption('attach'):
414+
GenAttachConfigProject()
415+
exit(0)
416+
339417
if GetOption('genconfig'):
340418
from env_utility import genconfig
341419
genconfig()

tools/options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,7 @@ def AddOptions():
141141
action = 'store_true',
142142
default = False,
143143
help = 'make compile_commands.json')
144+
AddOption('--attach',
145+
dest = 'attach',
146+
type = 'string',
147+
help = 'View attachconfig or add attach to.config')

0 commit comments

Comments
 (0)