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 )
0 commit comments