@@ -366,18 +366,14 @@ def check_no_undef_outside_kconfig(self, kconf):
366
366
#
367
367
# - *, meant for comments like '#endif /* CONFIG_FOO_* */
368
368
#
369
- # We skip the samples/ and tests/ directories for now. They often
370
- # contain Kconfig files that are not part of the main Kconfig tree,
371
- # which will trigger false positives until we do something fancier.
372
- #
373
- # We also skip doc/releases, which often references removed symbols.
369
+ # We skip doc/releases, which often references removed symbols.
374
370
375
371
# Warning: Needs to work with both --perl-regexp and the 're' module
376
372
regex = r"\bCONFIG_[A-Z0-9_]+\b(?!\s*##|[$@{*])"
377
373
378
374
grep_cmd = ["git" , "grep" , "--line-number" , "-I" , "--null" ,
379
375
"--perl-regexp" , regex ,
380
- "--" , ":!samples" , ":!tests" , ":! doc/releases" ]
376
+ "--" , ":!doc/releases" ]
381
377
382
378
grep_process = subprocess .Popen (grep_cmd ,
383
379
stdout = subprocess .PIPE ,
@@ -393,7 +389,7 @@ def check_no_undef_outside_kconfig(self, kconf):
393
389
.format (" " .join (grep_cmd ), grep_process .returncode ,
394
390
grep_stdout , grep_stderr ))
395
391
396
- defined_syms = set ( sym . name for sym in kconf . unique_defined_syms )
392
+ defined_syms = get_defined_syms ( kconf )
397
393
undef_to_locs = collections .defaultdict (list )
398
394
399
395
# splitlines() supports various line terminators
@@ -436,6 +432,41 @@ def check_no_undef_outside_kconfig(self, kconf):
436
432
{}""" .format (os .path .basename (__file__ ), undef_desc ))
437
433
438
434
435
+ def get_defined_syms (kconf ):
436
+ # Returns all defined Kconfig symbols. This is complicated by samples and
437
+ # tests defining their own Kconfig trees. For those, just grep for
438
+ # 'config FOO' to find definitions. Doing it "properly" with Kconfiglib is
439
+ # still useful for the main tree, because some symbols are defined using
440
+ # preprocessor macros.
441
+
442
+ # Warning: Needs to work with both --extended-regexp and the 're' module
443
+ regex = "^\s*(menu)?config\s*([A-Z0-9_]+)\s*(#|$)"
444
+
445
+ grep_cmd = ["git" , "grep" , "-I" , "-h" , "--extended-regexp" , regex ,
446
+ "--" , ":samples" , ":tests" ]
447
+
448
+ grep_process = subprocess .Popen (grep_cmd ,
449
+ stdout = subprocess .PIPE ,
450
+ stderr = subprocess .PIPE ,
451
+ cwd = ZEPHYR_BASE )
452
+
453
+ grep_stdout , grep_stderr = grep_process .communicate ()
454
+ # Fail if there's anything on stderr too, so that it doesn't get missed
455
+ if grep_process .returncode or grep_stderr :
456
+ self .error ("'{}' failed with exit code {} (while searching for "
457
+ "Kconfig symbol definitions)\n \n stdout:\n {}\n \n "
458
+ "stderr:\n {}"
459
+ .format (" " .join (grep_cmd ), grep_process .returncode ,
460
+ grep_stdout , grep_stderr ))
461
+
462
+ res = set (sym .name for sym in kconf .unique_defined_syms )
463
+
464
+ for def_line in grep_stdout .decode ("utf-8" ).splitlines ():
465
+ res .add (re .match (regex , def_line ).group (2 ))
466
+
467
+ return res
468
+
469
+
439
470
# Many of these are symbols used as examples. Note that the list is sorted
440
471
# alphabetically, and skips the CONFIG_ prefix.
441
472
UNDEF_KCONFIG_WHITELIST = {
@@ -444,6 +475,7 @@ def check_no_undef_outside_kconfig(self, kconf):
444
475
"CDC_ACM_PORT_NAME_" ,
445
476
"CLOCK_STM32_SYSCLK_SRC_" ,
446
477
"CMU" ,
478
+ "BT_6LOWPAN" , # Defined in Linux, mentioned in docs
447
479
"COUNTER_RTC_STM32_CLOCK_SRC" ,
448
480
"CRC" , # Used in TI CC13x2 / CC26x2 SDK comment
449
481
"DEEP_SLEEP" , # #defined by RV32M1 in ext/
@@ -469,13 +501,15 @@ def check_no_undef_outside_kconfig(self, kconf):
469
501
"PEDO_THS_MIN" ,
470
502
"REG1" ,
471
503
"REG2" ,
504
+ "SAMPLE_MODULE_LOG_LEVEL" , # Used as an example in samples/subsys/logging
472
505
"SEL" ,
473
506
"SHIFT" ,
474
507
"SOC_WATCH" , # Issue 13749
475
508
"SOME_BOOL" ,
476
509
"SOME_INT" ,
477
510
"SOME_OTHER_BOOL" ,
478
511
"SOME_STRING" ,
512
+ "SRAM2" , # Referenced in a comment in samples/application_development
479
513
"STACK_SIZE" , # Used as an example in the Kconfig docs
480
514
"STD_CPP" , # Referenced in CMake comment
481
515
"TEST1" ,
0 commit comments