kumquat-buildroot/utils/checkpackagelib
Ricardo Martincoski 5bbedea9c2 utils/checkpackagelib/lib_mk.py: fix check for overridden variable
Currently this .mk snippet results in unexpected behavior from
check-package:
|VAR_1 = VALUE1
|ifeq (condition)
|VAR_1 := $(VAR_1), VALUE2
|endif

Fix commit "163f160a8e utils/{check-package, checkpackagelib}:
consistently use raw strings for re.compile" that ended up doing this:
-    CONCATENATING = re.compile("^([A-Z0-9_]+)\s*(\+|:|)=\s*\$\(\\1\)")
+    CONCATENATING = re.compile(r"^([A-Z0-9_]+)\s*(\+|:|)=\s*\$\(\\1\)")

But raw strings do not expect escaping when referencing \1 and the
pattern ends up searching for a raw '\\1' instead of an occurrence of
the first pattern inside parenthesis.

|$ python3
|Python 3.8.10 (default, Sep 28 2021, 16:10:42)
|[GCC 9.3.0] on linux
|Type "help", "copyright", "credits" or "license" for more information.
|>>> import re
|>>> p1 = re.compile('(foo)bar\\1')
|>>> p2 = re.compile(r'(foo)bar\\1')
|>>> p3 = re.compile(r'(foo)bar\1')
|>>> s1 = 'foobarfoo'
|>>> s2 = 'foobar\\1'
|>>> print(p1.search(s1))
|<re.Match object; span=(0, 9), match='foobarfoo'>
|>>> print(p2.search(s1))
|None
|>>> print(p3.search(s1))
|<re.Match object; span=(0, 9), match='foobarfoo'>
|>>> print(p1.search(s2))
|None
|>>> print(p2.search(s2))
|<re.Match object; span=(0, 8), match='foobar\\1'>
|>>> print(p3.search(s2))
|None
|>>>

So use '\1' instead of '\\1' in the raw string.

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Titouan Christophe <titouan.christophe@railnova.eu>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2021-12-10 20:01:40 +01:00
..
__init__.py
base.py utils/check-package: allow to disable warning for a line 2019-01-29 16:37:47 +01:00
lib_config.py utils/{check-package, checkpackagelib}: consistently use raw strings for re.compile 2020-08-14 21:55:59 +02:00
lib_hash.py check-package: fix Python3 support 2019-01-16 23:14:25 +01:00
lib_mk.py utils/checkpackagelib/lib_mk.py: fix check for overridden variable 2021-12-10 20:01:40 +01:00
lib_patch.py utils/{check-package, checkpackagelib}: consistently use raw strings for re.compile 2020-08-14 21:55:59 +02:00
lib.py utils/check-package: fix flake8 warning 2019-05-20 10:20:38 +02:00
readme.txt

How the scripts are structured:
- check-package is the main engine, called by the user.
  For each input file, this script decides which parser should be used and it
  collects all classes declared in the library file and instantiates them.
  The main engine opens the input files and it serves each raw line (including
  newline!) to the method check_line() of every check object.
  Two special methods before() and after() are used to call the initialization
  of variables (for the case it needs to keep data across calls) and the
  equivalent finalization (e.g. for the case a warning must be issued if some
  pattern is not in the input file).
- base.py contains the base class for all check functions.
- lib.py contains the classes for common check functions.
  Each check function is explicitly included in a given type-parsing library.
  Do not include every single check function in this file, a class that will
  only parse hash files should be implemented in the hash-parsing library.
  When a warning must be issued, the check function returns an array of strings.
  Each string is a warning message and is displayed if the corresponding verbose
  level is active. When the script is called without --verbose only the first
  warning in the returned array is printed; when called with --verbose both
  first and second warnings are printed; when called with -vv until the third
  warning is printed; an so on.
  Helper functions can be defined and will not be called by the main script.
- lib_type.py contains check functions specific to files of this type.

Some hints when changing this code:
- prefer O(n) algorithms, where n is the total number of lines in the files
  processed.
- when there is no other reason for ordering, use alphabetical order (e.g. keep
  the check functions in alphabetical order, keep the imports in alphabetical
  order, and so on).
- keep in mind that for every class the method before() will be called before
  any line is served to be checked by the method check_line(). A class that
  checks the filename should only implement the method before(). A function that
  needs to keep data across calls (e.g. keep the last line before the one being
  processed) should initialize all variables using this method.
- keep in mind that for every class the method after() will be called after all
  lines were served to be checked by the method check_line(). A class that
  checks the absence of a pattern in the file will need to use this method.
- try to avoid false warnings. It's better to not issue a warning message to a
  corner case than have too many false warnings. The second can make users stop
  using the script.
- do not check spacing in the input line in every single function. Trailing
  whitespace and wrong indentation should be checked by separate functions.
- avoid duplicate tests. Try to test only one thing in each function.
- in the warning message, include the url to a section from the manual, when
  applicable. It potentially will make more people know the manual.
- use short sentences in the warning messages. A complete explanation can be
  added to show when --verbose is used.
- when testing, verify the error message is displayed when the error pattern is
  found, but also verify the error message is not displayed for few
  well-formatted packages... there are many of these, just pick your favorite
  as golden package that should not trigger any warning message.
- check the url displayed by the warning message works.

Usage examples:
- to get a list of check functions that would be called without actually
  calling them you can use the --dry-run option:
$ utils/check-package --dry-run package/yourfavorite/*

- when you just added a new check function, e.g. Something, check how it behaves
  for all current packages:
$ utils/check-package --include-only Something $(find package -type f)

- the effective processing time (when the .pyc were already generated and all
  files to be processed are cached in the RAM) should stay in the order of few
  seconds:
$ utils/check-package $(find package -type f) >/dev/null ; \
  time utils/check-package $(find package -type f) >/dev/null

- vim users can navigate the warnings (most editors probably have similar
  function) since warnings are generated in the form 'path/file:line: warning':
$ find package/ -name 'Config.*' > filelist && vim -c \
  'set makeprg=utils/check-package\ $(cat\ filelist)' -c make -c copen