1010import  json 
1111import  logging 
1212import  os 
13- from  pathlib  import  Path 
13+ from  pathlib  import  Path ,  PurePath 
1414import  platform 
1515import  re 
1616import  subprocess 
3131from  west .manifest  import  Manifest 
3232from  west .manifest  import  ManifestProject 
3333
34+ try :
35+     from  yaml  import  CSafeLoader  as  SafeLoader 
36+ except  ImportError :
37+     from  yaml  import  SafeLoader 
38+ 
3439sys .path .insert (0 , str (Path (__file__ ).resolve ().parents [1 ]))
3540from  get_maintainer  import  Maintainers , MaintainersError 
3641import  list_boards 
@@ -781,6 +786,23 @@ def get_logging_syms(self, kconf):
781786
782787        return  set (kconf_syms )
783788
789+     def  module_disallowed_check (self , module_path , type , folder , meta , regex ):
790+         # Returns a list with lines from git grep which includes Kconfigs from defconfig files 
791+         entry  =  type  +  '_root' 
792+         git_folder  =  ":"  +  folder 
793+ 
794+         if  entry  in  meta ['build' ]['settings' ]:
795+             tmp_path  =  module_path .joinpath (meta ['build' ]['settings' ][entry ])
796+ 
797+             if  Path (tmp_path .joinpath (folder )).is_dir ():
798+                 tmp_output  =  git ("grep" , "--line-number" , "-I" , "--null" ,
799+                                  "--perl-regexp" , regex , "--" , git_folder ,
800+                                  cwd = tmp_path , ignore_non_zero = True )
801+ 
802+                 if  len (tmp_output ) >  0 :
803+                     return  tmp_output .splitlines ()
804+         return  []
805+ 
784806    def  check_disallowed_defconfigs (self , kconf ):
785807        """ 
786808        Checks that there are no disallowed Kconfigs used in board/SoC defconfig files 
@@ -823,14 +845,41 @@ def check_disallowed_defconfigs(self, kconf):
823845
824846        grep_stdout_boards  =  git ("grep" , "--line-number" , "-I" , "--null" ,
825847                                 "--perl-regexp" , regex_boards , "--" , ":boards" ,
826-                                  cwd = ZEPHYR_BASE )
848+                                  cwd = ZEPHYR_BASE ). splitlines () 
827849        grep_stdout_socs  =  git ("grep" , "--line-number" , "-I" , "--null" ,
828850                               "--perl-regexp" , regex_socs , "--" , ":soc" ,
829-                                cwd = ZEPHYR_BASE )
851+                                cwd = ZEPHYR_BASE ).splitlines ()
852+ 
853+         manifest  =  Manifest .from_file ()
854+         for  project  in  manifest .get_projects ([]):
855+             if  not  manifest .is_active (project ):
856+                 continue 
857+ 
858+             if  not  project .is_cloned ():
859+                 continue 
860+ 
861+             module_path  =  PurePath (project .abspath )
862+             module_yml  =  module_path .joinpath ('zephyr/module.yml' )
863+ 
864+             if  not  Path (module_yml ).is_file ():
865+                 module_yml  =  module_path .joinpath ('zephyr/module.yaml' )
866+ 
867+             if  Path (module_yml ).is_file ():
868+                 with  Path (module_yml ).open ('r' , encoding = 'utf-8' ) as  f :
869+                     meta  =  yaml .load (f .read (), Loader = SafeLoader )
870+ 
871+                     if  'build'  in  meta  and  'settings'  in  meta ['build' ]:
872+                         grep_stdout_boards .extend (self .module_disallowed_check (module_path ,
873+                                                                                'board' ,
874+                                                                                'boards' , meta ,
875+                                                                                regex_boards ))
876+                         grep_stdout_socs .extend (self .module_disallowed_check (module_path , 'soc' ,
877+                                                                              'soc' , meta ,
878+                                                                              regex_socs ))
830879
831880        # Board processing 
832881        # splitlines() supports various line terminators 
833-         for  grep_line  in  grep_stdout_boards . splitlines () :
882+         for  grep_line  in  grep_stdout_boards :
834883            path , lineno , line  =  grep_line .split ("\0 " )
835884
836885            # Extract symbol references (might be more than one) within the line 
@@ -847,7 +896,7 @@ def check_disallowed_defconfigs(self, kconf):
847896
848897        # SoCs processing 
849898        # splitlines() supports various line terminators 
850-         for  grep_line  in  grep_stdout_socs . splitlines () :
899+         for  grep_line  in  grep_stdout_socs :
851900            path , lineno , line  =  grep_line .split ("\0 " )
852901
853902            # Extract symbol references (might be more than one) within the line 
0 commit comments