Skip to content

Commit 5886e26

Browse files
hydevcodemysterywolf
authored andcommitted
[scons] ci.attachconfig.yml is used in combination with scons
1 parent 0800db1 commit 5886e26

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

tools/attachconfig.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import os
2+
import sys
3+
import shutil
4+
import yaml
5+
6+
from SCons.Script import *
7+
8+
# SCons AttachConfig Command Function
9+
def GenAttachConfigProject(program = None):
10+
Rtt_Root = os.getcwd()
11+
config_file = os.path.join(os.getcwd(), 'rtt_root', Rtt_Root, '.config')
12+
config_bacakup = config_file+'.origin'
13+
rtconfig_file = os.path.join(os.getcwd(), 'rtt_root', Rtt_Root, 'rtconfig.h')
14+
rtconfig__bacakup = rtconfig_file+'.origin'
15+
if GetOption('attach') == '?':
16+
attachconfig=[]
17+
GetAttachConfig("get",attachconfig,0)
18+
print("\033[32m✅ AttachConfig has: \033[0m")
19+
prefix=attachconfig[0]
20+
for line in attachconfig:
21+
temp_prefix=line.split(".", 1)
22+
if prefix!=temp_prefix[0]:
23+
print("\033[42m \033[30m------"+temp_prefix[0]+"------\033[0m")
24+
prefix=temp_prefix[0]
25+
print(line)
26+
27+
28+
elif GetOption('attach') == 'default':
29+
if os.path.exists(config_bacakup):
30+
shutil.copyfile(config_bacakup, config_file)
31+
os.remove(config_bacakup)
32+
if os.path.exists(rtconfig__bacakup):
33+
shutil.copyfile(rtconfig__bacakup, rtconfig_file)
34+
os.remove(rtconfig__bacakup)
35+
print("\033[32m✅ Default .config and rtconfig.h recovery success!\033[0m")
36+
else:
37+
attachconfig=GetOption('attach')
38+
attachconfig_result=[]
39+
GetAttachConfig("search",attachconfig,attachconfig_result)
40+
if attachconfig_result==[]:
41+
print("❌\033[31m Without this AttachConfig:"+attachconfig+"\033[0m")
42+
return
43+
if os.path.exists(config_bacakup)==False:
44+
shutil.copyfile(config_file, config_bacakup)
45+
if os.path.exists(rtconfig__bacakup)==False:
46+
shutil.copyfile(rtconfig_file, rtconfig__bacakup)
47+
with open(config_file, 'a') as destination:
48+
for line in attachconfig_result:
49+
destination.write(line + '\n')
50+
from env_utility import defconfig
51+
defconfig(Rtt_Root)
52+
print("\033[32m✅ AttachConfig add success!\033[0m")
53+
54+
def GetAttachConfig(action,attachconfig,attachconfig_result):
55+
rtt_root = os.getcwd()
56+
yml_files_content = []
57+
directory = os.path.join(rtt_root, 'rtt_root', rtt_root, '.ci/attachconfig')
58+
if os.path.exists(directory):
59+
for root, dirs, files in os.walk(directory):
60+
for filename in files:
61+
if filename.endswith('attachconfig.yml'):
62+
file_path = os.path.join(root, filename)
63+
if os.path.exists(file_path):
64+
try:
65+
with open(file_path, 'r') as file:
66+
content = yaml.safe_load(file)
67+
if content is None:
68+
continue
69+
yml_files_content.append(content)
70+
except yaml.YAMLError as e:
71+
print(f"::error::Error parsing YAML file: {e}")
72+
continue
73+
except Exception as e:
74+
print(f"::error::Error reading file: {e}")
75+
continue
76+
for projects in yml_files_content:
77+
for name, details in projects.items():
78+
if details.get("kconfig") is None:
79+
continue
80+
if(projects.get(name) is not None):
81+
if action == "get":
82+
attachconfig.append(name)
83+
if action == "search" and name == attachconfig:
84+
from ci.bsp_buildings import get_details_and_dependencies
85+
detail_list=get_details_and_dependencies([name],projects)
86+
for line in detail_list:
87+
attachconfig_result.append(line)

tools/building.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import rtconfig
3434
import platform
3535
import logging
36-
3736
from SCons.Script import *
3837
from utils import _make_path_relative
3938
from mkdist import do_copy_file
@@ -336,6 +335,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
336335
else:
337336
print('--global-macros arguments are illegal!')
338337

338+
if GetOption('attach'):
339+
from attachconfig import GenAttachConfigProject
340+
GenAttachConfigProject()
341+
exit(0)
342+
339343
if GetOption('genconfig'):
340344
from env_utility import genconfig
341345
genconfig()

tools/options.py

+7
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,10 @@ 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.'+\
148+
'e.g. scons --attach=? View all attachconfig for the current bsp.'+\
149+
' or scons --attach=component.cherryusb_cdc Set option component.cherryusb_cdc inside attachconfig to.config.'+\
150+
' or scons --attach=default Restore.config and rtconfig to before attch was set.')

0 commit comments

Comments
 (0)