@@ -99,7 +99,8 @@ class Problem(abc.ABC): # pylint: disable=too-few-public-methods
9999 # Class variable to control the quietness of all problems
100100 quiet = False
101101 def __init__ (self ):
102- self .textwrapper = textwrap .TextWrapper ()
102+ self .textwrapper = textwrap .TextWrapper (break_on_hyphens = False ,
103+ break_long_words = False )
103104 self .textwrapper .width = 80
104105 self .textwrapper .initial_indent = " > "
105106 self .textwrapper .subsequent_indent = " "
@@ -288,7 +289,16 @@ def get_all_files(self, include_wildcards, exclude_wildcards):
288289
289290 Args:
290291 * include_wildcards: a List of shell-style wildcards to match filepaths.
292+ - "*" does not match a directory separator, e.g. "*/a.h"
293+ matches "somedir/a.h" but not "somedir/subdir/a.h".
294+ - "**" matches zero or more directory levels, e.g. "**/a.h"
295+ matches "a.h", "somedir/a.h", "somedir/subdir/a.h", etc.
296+ - The matching is case-insensitive.
291297 * exclude_wildcards: a List of shell-style wildcards to exclude.
298+ - "*" matches every character including separators, e.g. "*/a.h"
299+ matches "somedir/a.h" and "somedir/subdir/a.h" but not "a.h".
300+ - "**" is equivalent to "*".
301+ - The matching is case-sensitive.
292302
293303 Returns:
294304 * inc_files: A List of relative filepaths for included files.
@@ -297,7 +307,7 @@ def get_all_files(self, include_wildcards, exclude_wildcards):
297307 accumulator = set ()
298308 all_wildcards = include_wildcards + (exclude_wildcards or [])
299309 for wildcard in all_wildcards :
300- accumulator = accumulator .union (glob .iglob (wildcard ))
310+ accumulator = accumulator .union (glob .iglob (wildcard , recursive = True ))
301311
302312 inc_files = []
303313 exc_files = []
@@ -306,7 +316,7 @@ def get_all_files(self, include_wildcards, exclude_wildcards):
306316 exc_files .append (path )
307317 else :
308318 inc_files .append (path )
309- return (inc_files , exc_files )
319+ return (sorted ( inc_files ), sorted ( exc_files ) )
310320
311321 def get_included_files (self , include_wildcards , exclude_wildcards ):
312322 """
@@ -324,10 +334,11 @@ def get_included_files(self, include_wildcards, exclude_wildcards):
324334 accumulator = set ()
325335
326336 for include_wildcard in include_wildcards :
327- accumulator = accumulator .union (glob .iglob (include_wildcard ))
337+ accumulator = accumulator .union (glob .iglob (include_wildcard ,
338+ recursive = True ))
328339
329- return list (path for path in accumulator
330- if not self .is_file_excluded (path , exclude_wildcards ))
340+ return sorted (path for path in accumulator
341+ if not self .is_file_excluded (path , exclude_wildcards ))
331342
332343 def parse_macros (self , include , exclude = None ):
333344 """
@@ -349,6 +360,7 @@ def parse_macros(self, include, exclude=None):
349360
350361 macros = []
351362 for header_file in files :
363+ self .log .debug ("Parsing macros in " + header_file )
352364 with open (header_file , "r" , encoding = "utf-8" ) as header :
353365 for line_no , line in enumerate (header ):
354366 for macro in macro_regex .finditer (line ):
@@ -387,6 +399,7 @@ def parse_mbed_psa_words(self, include, exclude=None):
387399
388400 mbed_psa_words = []
389401 for filename in files :
402+ self .log .debug ("Parsing words in " + filename )
390403 with open (filename , "r" , encoding = "utf-8" ) as fp :
391404 for line_no , line in enumerate (fp ):
392405 if exclusions .search (line ):
@@ -423,6 +436,7 @@ def parse_enum_consts(self, include, exclude=None):
423436 enum_consts = []
424437 for header_file in files :
425438 state = states .OUTSIDE_KEYWORD
439+ self .log .debug ("Parsing enums in " + header_file )
426440 with open (header_file , "r" , encoding = "utf-8" ) as header :
427441 for line_no , line in enumerate (header ):
428442 # Match typedefs and brackets only when they are at the
@@ -539,6 +553,7 @@ def parse_identifiers_in_file(self, header_file, identifiers):
539553 Append found matches to the list ``identifiers``.
540554 """
541555
556+ self .log .debug ("Parsing identifier declarations in " + header_file )
542557 with open (header_file , "r" , encoding = "utf-8" ) as header :
543558 in_block_comment = False
544559 # The previous line variable is used for concatenating lines
@@ -614,11 +629,13 @@ def parse_identifiers(self, include, exclude=None):
614629
615630 self .log .debug ("Looking for included identifiers in {} files" .format \
616631 (len (included_files )))
617-
618632 included_identifiers = []
619- excluded_identifiers = []
620633 for header_file in included_files :
621634 self .parse_identifiers_in_file (header_file , included_identifiers )
635+
636+ self .log .debug ("Looking for excluded identifiers in {} files" .format \
637+ (len (excluded_files )))
638+ excluded_identifiers = []
622639 for header_file in excluded_files :
623640 self .parse_identifiers_in_file (header_file , excluded_identifiers )
624641
@@ -690,6 +707,31 @@ def __init__(self, log):
690707 if not build_tree .looks_like_tf_psa_crypto_root (os .getcwd ()):
691708 raise Exception ("This script must be run from TF-PSA-Crypto root." )
692709
710+ H_PUBLIC = [
711+ "include/**/*.h" ,
712+ "drivers/*/include/**/*.h" ,
713+ ]
714+ H_PUBLIC_EXCLUDE = [
715+ 'drivers/everest/include/tf-psa-crypto/private/everest/[HhKk]*.h' ,
716+ 'drivers/everest/include/tf-psa-crypto/private/everest/k*/*.h' ,
717+ 'drivers/everest/include/tf-psa-crypto/private/everest/vs*/*.h' ,
718+ ]
719+
720+ H_INTERNAL = [
721+ "core/*.h" ,
722+ "drivers/*/src/*.h" ,
723+ ]
724+
725+ H_TEST_DRIVERS = [
726+ "framework/tests/include/test/drivers/*.h" ,
727+ ]
728+
729+ C_INTERNAL = [
730+ "core/*.c" ,
731+ "drivers/*/library/*.c" ,
732+ "drivers/*/src/*.c" ,
733+ ]
734+
693735 def comprehensive_parse (self ):
694736 """
695737 Comprehensive ("default") function to call each parsing function and
@@ -698,75 +740,20 @@ def comprehensive_parse(self):
698740 Returns a dict of parsed item key to the corresponding List of Matches.
699741 """
700742 all_macros = {"public" : [], "internal" : [], "private" :[]}
701- all_macros ["public" ] = self .parse_macros ([
702- "include/psa/*.h" ,
703- "include/tf-psa-crypto/*.h" ,
704- "include/mbedtls/*.h" ,
705- "drivers/builtin/include/mbedtls/*.h" ,
706- "include/mbedtls/private/*.h" ,
707- "drivers/builtin/include/mbedtls/private/*.h" ,
708- "drivers/everest/include/everest/everest.h" ,
709- "drivers/everest/include/everest/x25519.h" ,
710- "drivers/everest/include/tf-psa-crypto/private/everest/everest.h" ,
711- "drivers/everest/include/tf-psa-crypto/private/everest/x25519.h"
712- ])
713- all_macros ["internal" ] = self .parse_macros ([
714- "core/*.h" ,
715- "drivers/builtin/src/*.h" ,
716- "framework/tests/include/test/drivers/*.h" ,
717- ])
718- all_macros ["private" ] = self .parse_macros ([
719- "core/*.c" ,
720- "drivers/builtin/src/*.c" ,
721- ])
722- enum_consts = self .parse_enum_consts ([
723- "include/psa/*.h" ,
724- "include/tf-psa-crypto/*.h" ,
725- "include/mbedtls/*.h" ,
726- "drivers/builtin/include/mbedtls/*.h" ,
727- "include/mbedtls/private/*.h" ,
728- "drivers/builtin/include/mbedtls/private/*.h" ,
729- "core/*.h" ,
730- "drivers/builtin/src/*.h" ,
731- "core/*.c" ,
732- "drivers/builtin/src/*.c" ,
733- "drivers/everest/include/everest/everest.h" ,
734- "drivers/everest/include/everest/x25519.h" ,
735- "drivers/everest/include/tf-psa-crypto/private/everest/everest.h" ,
736- "drivers/everest/include/tf-psa-crypto/private/everest/x25519.h"
737- ])
738- identifiers , excluded_identifiers = self .parse_identifiers ([
739- "include/psa/*.h" ,
740- "include/tf-psa-crypto/*.h" ,
741- "include/mbedtls/*.h" ,
742- "drivers/builtin/include/mbedtls/*.h" ,
743- "include/mbedtls/private/*.h" ,
744- "drivers/builtin/include/mbedtls/private/*.h" ,
745- "core/*.h" ,
746- "drivers/builtin/src/*.h" ,
747- "drivers/everest/include/everest/everest.h" ,
748- "drivers/everest/include/everest/x25519.h" ,
749- "drivers/everest/include/tf-psa-crypto/private/everest/everest.h" ,
750- "drivers/everest/include/tf-psa-crypto/private/everest/x25519.h"
751- ], ["drivers/p256-m/p256-m/p256-m.h" ])
752- mbed_psa_words = self .parse_mbed_psa_words ([
753- "include/psa/*.h" ,
754- "include/tf-psa-crypto/*.h" ,
755- "include/mbedtls/*.h" ,
756- "drivers/builtin/include/mbedtls/*.h" ,
757- "include/mbedtls/private/*.h" ,
758- "drivers/builtin/include/mbedtls/private/*.h" ,
759- "core/*.h" ,
760- "drivers/builtin/src/*.h" ,
761- "drivers/everest/include/everest/everest.h" ,
762- "drivers/everest/include/everest/x25519.h" ,
763- "drivers/everest/include/tf-psa-crypto/private/everest/everest.h" ,
764- "drivers/everest/include/tf-psa-crypto/private/everest/x25519.h" ,
765- "core/*.c" ,
766- "drivers/builtin/src/*.c" ,
767- "drivers/everest/library/everest.c" ,
768- "drivers/everest/library/x25519.c"
769- ], ["core/psa_crypto_driver_wrappers.h" ])
743+ all_macros ["public" ] = self .parse_macros (self .H_PUBLIC ,
744+ self .H_PUBLIC_EXCLUDE )
745+ all_macros ["internal" ] = self .parse_macros (self .H_INTERNAL +
746+ self .H_TEST_DRIVERS )
747+ all_macros ["private" ] = self .parse_macros (self .C_INTERNAL )
748+ enum_consts = self .parse_enum_consts (
749+ self .H_PUBLIC + self .H_INTERNAL + self .C_INTERNAL ,
750+ self .H_PUBLIC_EXCLUDE )
751+ identifiers , excluded_identifiers = self .parse_identifiers (
752+ self .H_PUBLIC + self .H_INTERNAL ,
753+ self .H_PUBLIC_EXCLUDE + ["drivers/p256-m/p256-m/p256-m.h" ])
754+ mbed_psa_words = self .parse_mbed_psa_words (
755+ self .H_PUBLIC + self .H_INTERNAL + self .C_INTERNAL ,
756+ self .H_PUBLIC_EXCLUDE + ["core/psa_crypto_driver_wrappers.h" ])
770757 symbols = self .parse_symbols ()
771758
772759 return self ._parse (all_macros , enum_consts , identifiers ,
0 commit comments