Repository: pyinstaller/pyinstaller

Issue:
Failure to correctly parse `ldconfig` output
## Description of the issue
Failure to correctly parse `ldconfig` output. Started happening after latest `Arch` upgrade. I guess the `ldconfig` people changed their output a little bit.

## Context information (for bug reports)

* Output of `pyinstaller --version`: ```4.2```
* Version of Python:  ```3.9```
* Platform: ```Arch```

### Stacktrace / full error message

```
Traceback (most recent call last):
  File "/somewhere_on_my_system/venv/bin/pyinstaller", line 8, in <module>
    sys.exit(run())
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 725, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 672, in build
    exec(code, spec_namespace)
  File "/somewhere_on_my_system/web_ui.spec", line 11, in <module>
    a = Analysis(
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 242, in __init__
    self.__postinit__()
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/building/datastruct.py", line 160, in __postinit__
    self.assemble()
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 438, in assemble
    ctypes_binaries = scan_code_for_ctypes(co)
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/depend/utils.py", line 145, in scan_code_for_ctypes
    binaries = _resolveCtypesImports(binaries)
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/depend/utils.py", line 319, in _resolveCtypesImports
    load_ldconfig_cache()
  File "/somewhere_on_my_system/venv/lib/python3.9/site-packages/PyInstaller/depend/utils.py", line 402, in load_ldconfig_cache
    path = m.groups()[-1]
AttributeError: 'NoneType' object has no attribute 'groups'
```

It fails on the last line of this:
```
	ld-linux.so.2 (ELF) => /usr/lib32/ld-linux.so.2
	ld-linux.so.2 (ELF) => /usr/lib/ld-linux.so.2
	ld-linux-x86-64.so.2 (libc6,x86-64) => /usr/lib/ld-linux-x86-64.so.2
Cache generated by: ldconfig (GNU libc) release release version 2.33
```

In `depend/utils.py` on line 402 no match check is being performed and the exception above is being thrown:
```   LDCONFIG_CACHE = {}                                                                                                                                                                                                                  
  399     for line in text:                                                                               
  400         # :fixme: this assumes libary names do not contain whitespace                               
  401         m = pattern.match(line)                                                                                                    
  402         path = m.groups()[-1]   

```


Discussion:
Yes, I guess it just needs a:
```python
if m is None:
    continue
```
That would however have the effect of silently ignoring lines in unrecognised syntax which could be a very subtle bug in future.
Indeed. We could also print a warning for non-matched lines - but only for those that do not start with "Cache generated by: ", to avoid spam on known "problematic" lines.

This change in output seems to come from introduction of an [extension mechanism to ld.so.cache](https://github.com/bminor/glibc/commit/dfb3f101c5ef23adf60d389058a2b33e23303d04), so we'll probably need to expand the ignore list in the future. But this way, we can explicitly ignore the lines we know are harmless, and still catch new ones that could introduce bugs elsewhere...

Resolving patch:
diff --git a/PyInstaller/depend/utils.py b/PyInstaller/depend/utils.py
--- a/PyInstaller/depend/utils.py
+++ b/PyInstaller/depend/utils.py
@@ -399,6 +399,18 @@ def load_ldconfig_cache():
     for line in text:
         # :fixme: this assumes libary names do not contain whitespace
         m = pattern.match(line)
+
+        # Sanitize away any abnormal lines of output.
+        if m is None:
+            # Warn about it then skip the rest of this iteration.
+            if re.search("Cache generated by:", line):
+                # See #5540. This particular line is harmless.
+                pass
+            else:
+                logger.warning(
+                    "Unrecognised line of output %r from ldconfig", line)
+            continue
+
         path = m.groups()[-1]
         if is_freebsd or is_openbsd:
             # Insert `.so` at the end of the lib's basename. soname


Test patch: