10
10
import json
11
11
import logging
12
12
import os
13
- from pathlib import Path
13
+ from pathlib import Path , PurePath
14
14
import platform
15
15
import re
16
16
import subprocess
31
31
from west .manifest import Manifest
32
32
from west .manifest import ManifestProject
33
33
34
+ try :
35
+ from yaml import CSafeLoader as SafeLoader
36
+ except ImportError :
37
+ from yaml import SafeLoader
38
+
34
39
sys .path .insert (0 , str (Path (__file__ ).resolve ().parents [1 ]))
35
40
from get_maintainer import Maintainers , MaintainersError
36
41
import list_boards
@@ -751,6 +756,23 @@ def get_logging_syms(self, kconf):
751
756
752
757
return set (kconf_syms )
753
758
759
+ def module_disallowed_check (self , module_path , type , folder , meta , regex ):
760
+ # Returns a list with lines from git grep which includes Kconfigs from defconfig files
761
+ entry = type + '_root'
762
+ git_folder = ":" + folder
763
+
764
+ if entry in meta ['build' ]['settings' ]:
765
+ tmp_path = module_path .joinpath (meta ['build' ]['settings' ][entry ])
766
+
767
+ if Path (tmp_path .joinpath (folder )).is_dir ():
768
+ tmp_output = git ("grep" , "--line-number" , "-I" , "--null" ,
769
+ "--perl-regexp" , regex , "--" , git_folder ,
770
+ cwd = tmp_path , ignore_non_zero = True )
771
+
772
+ if len (tmp_output ) > 0 :
773
+ return tmp_output .splitlines ()
774
+ return []
775
+
754
776
def check_disallowed_defconfigs (self , kconf ):
755
777
"""
756
778
Checks that there are no disallowed Kconfigs used in board/SoC defconfig files
@@ -799,14 +821,41 @@ def check_disallowed_defconfigs(self, kconf):
799
821
800
822
grep_stdout_boards = git ("grep" , "--line-number" , "-I" , "--null" ,
801
823
"--perl-regexp" , regex_boards , "--" , ":boards" ,
802
- cwd = ZEPHYR_BASE )
824
+ cwd = ZEPHYR_BASE ). splitlines ()
803
825
grep_stdout_socs = git ("grep" , "--line-number" , "-I" , "--null" ,
804
826
"--perl-regexp" , regex_socs , "--" , ":soc" ,
805
- cwd = ZEPHYR_BASE )
827
+ cwd = ZEPHYR_BASE ).splitlines ()
828
+
829
+ manifest = Manifest .from_file ()
830
+ for project in manifest .get_projects ([]):
831
+ if not manifest .is_active (project ):
832
+ continue
833
+
834
+ if not project .is_cloned ():
835
+ continue
836
+
837
+ module_path = PurePath (project .abspath )
838
+ module_yml = module_path .joinpath ('zephyr/module.yml' )
839
+
840
+ if not Path (module_yml ).is_file ():
841
+ module_yml = module_path .joinpath ('zephyr/module.yaml' )
842
+
843
+ if Path (module_yml ).is_file ():
844
+ with Path (module_yml ).open ('r' , encoding = 'utf-8' ) as f :
845
+ meta = yaml .load (f .read (), Loader = SafeLoader )
846
+
847
+ if 'build' in meta and 'settings' in meta ['build' ]:
848
+ grep_stdout_boards .extend (self .module_disallowed_check (module_path ,
849
+ 'board' ,
850
+ 'boards' , meta ,
851
+ regex_boards ))
852
+ grep_stdout_socs .extend (self .module_disallowed_check (module_path , 'soc' ,
853
+ 'soc' , meta ,
854
+ regex_socs ))
806
855
807
856
# Board processing
808
857
# splitlines() supports various line terminators
809
- for grep_line in grep_stdout_boards . splitlines () :
858
+ for grep_line in grep_stdout_boards :
810
859
path , lineno , line = grep_line .split ("\0 " )
811
860
812
861
# Extract symbol references (might be more than one) within the line
@@ -823,7 +872,7 @@ def check_disallowed_defconfigs(self, kconf):
823
872
824
873
# SoCs processing
825
874
# splitlines() supports various line terminators
826
- for grep_line in grep_stdout_socs . splitlines () :
875
+ for grep_line in grep_stdout_socs :
827
876
path , lineno , line = grep_line .split ("\0 " )
828
877
829
878
# Extract symbol references (might be more than one) within the line
0 commit comments