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
@@ -781,6 +786,23 @@ def get_logging_syms(self, kconf):
781
786
782
787
return set (kconf_syms )
783
788
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
+
784
806
def check_disallowed_defconfigs (self , kconf ):
785
807
"""
786
808
Checks that there are no disallowed Kconfigs used in board/SoC defconfig files
@@ -823,14 +845,41 @@ def check_disallowed_defconfigs(self, kconf):
823
845
824
846
grep_stdout_boards = git ("grep" , "--line-number" , "-I" , "--null" ,
825
847
"--perl-regexp" , regex_boards , "--" , ":boards" ,
826
- cwd = ZEPHYR_BASE )
848
+ cwd = ZEPHYR_BASE ). splitlines ()
827
849
grep_stdout_socs = git ("grep" , "--line-number" , "-I" , "--null" ,
828
850
"--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 ))
830
879
831
880
# Board processing
832
881
# splitlines() supports various line terminators
833
- for grep_line in grep_stdout_boards . splitlines () :
882
+ for grep_line in grep_stdout_boards :
834
883
path , lineno , line = grep_line .split ("\0 " )
835
884
836
885
# Extract symbol references (might be more than one) within the line
@@ -847,7 +896,7 @@ def check_disallowed_defconfigs(self, kconf):
847
896
848
897
# SoCs processing
849
898
# splitlines() supports various line terminators
850
- for grep_line in grep_stdout_socs . splitlines () :
899
+ for grep_line in grep_stdout_socs :
851
900
path , lineno , line = grep_line .split ("\0 " )
852
901
853
902
# Extract symbol references (might be more than one) within the line
0 commit comments