Skip to content

Commit e17c926

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

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

tools/attachconfig.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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"+','.join(attachconfig))
19+
elif GetOption('attach') == 'default':
20+
if os.path.exists(config_bacakup):
21+
shutil.copyfile(config_bacakup, config_file)
22+
os.remove(config_bacakup)
23+
if os.path.exists(rtconfig__bacakup):
24+
shutil.copyfile(rtconfig__bacakup, rtconfig_file)
25+
os.remove(rtconfig__bacakup)
26+
print("\033[32m✅ Default .config and rtconfig.h recovery success!\033[0m")
27+
else:
28+
attachconfig=GetOption('attach')
29+
attachconfig_result=[]
30+
GetAttachConfig("search",attachconfig,attachconfig_result)
31+
if attachconfig_result==[]:
32+
print("❌\033[31m Without this AttachConfig:"+attachconfig+"\033[0m")
33+
return
34+
if os.path.exists(config_bacakup)==False:
35+
shutil.copyfile(config_file, config_bacakup)
36+
if os.path.exists(rtconfig__bacakup)==False:
37+
shutil.copyfile(rtconfig_file, rtconfig__bacakup)
38+
with open(config_file, 'a') as destination:
39+
for line in attachconfig_result:
40+
destination.write(line + '\n')
41+
from env_utility import defconfig
42+
defconfig(Rtt_Root)
43+
print("\033[32m✅ AttachConfig add success!\033[0m")
44+
45+
def GetAttachConfig(action,attachconfig,attachconfig_result):
46+
rtt_root = os.getcwd()
47+
yml_files_content = []
48+
directory = os.path.join(rtt_root, 'rtt_root', rtt_root, '.ci/attachconfig')
49+
if os.path.exists(directory):
50+
for root, dirs, files in os.walk(directory):
51+
for filename in files:
52+
if filename.endswith('attachconfig.yml'):
53+
file_path = os.path.join(root, filename)
54+
if os.path.exists(file_path):
55+
try:
56+
with open(file_path, 'r') as file:
57+
content = yaml.safe_load(file)
58+
if content is None:
59+
continue
60+
yml_files_content.append(content)
61+
except yaml.YAMLError as e:
62+
print(f"::error::Error parsing YAML file: {e}")
63+
continue
64+
except Exception as e:
65+
print(f"::error::Error reading file: {e}")
66+
continue
67+
for projects in yml_files_content:
68+
for name, details in projects.items():
69+
if details.get("kconfig") is None:
70+
continue
71+
if(projects.get(name) is not None):
72+
if action == "get":
73+
attachconfig.append(name)
74+
if action == "search" and name == attachconfig:
75+
from ci.bsp_buildings import get_details_and_dependencies
76+
detail_list=get_details_and_dependencies([name],projects)
77+
for line in detail_list:
78+
attachconfig_result.append(line)

tools/building.py

Lines changed: 5 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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)