Repository: conda/conda-build

Issue:
Overlinking check crashes with `TypeError`
### What happened?

When trying to build `pyinstaller 5.13.2` on `linux-s390x`, the overlinking check crashes with a `TypeError`.

To reproduce, use the following recipe: https://github.com/AnacondaRecipes/pyinstaller-feedstock/pull/7

And remove the `overlinking_ignore_patterns` field.

Traceback

```
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.9/site-packages/conda/exception_handler.py", line 17, in __call__
        return func(*args, **kwargs)
      File "/opt/conda/lib/python3.9/site-packages/conda/cli/main.py", line 83, in main_subshell
        exit_code = do_call(args, parser)
      File "/opt/conda/lib/python3.9/site-packages/conda/cli/conda_argparse.py", line 170, in do_call
        result = plugin_subcommand.action(getattr(args, "_args", args))
      File "/opt/conda/lib/python3.9/site-packages/conda_build/plugin.py", line 10, in build
        execute(*args, **kwargs)
      File "/opt/conda/lib/python3.9/site-packages/conda_build/cli/main_build.py", line 572, in execute
        outputs = api.build(
      File "/opt/conda/lib/python3.9/site-packages/conda_build/api.py", line 254, in build
        return build_tree(
      File "/opt/conda/lib/python3.9/site-packages/conda_build/build.py", line 3789, in build_tree
        packages_from_this = build(
      File "/opt/conda/lib/python3.9/site-packages/conda_build/build.py", line 2877, in build
        newly_built_packages = bundlers[pkg_type](output_d, m, env, stats)
      File "/opt/conda/lib/python3.9/site-packages/conda_build/build.py", line 2004, in bundle_conda
        files = post_process_files(metadata, initial_files)
      File "/opt/conda/lib/python3.9/site-packages/conda_build/build.py", line 1815, in post_process_files
        post_build(m, new_files, build_python=python)
      File "/opt/conda/lib/python3.9/site-packages/conda_build/post.py", line 1819, in post_build
        check_overlinking(m, files, host_prefix)
      File "/opt/conda/lib/python3.9/site-packages/conda_build/post.py", line 1644, in check_overlinking
        return check_overlinking_impl(
      File "/opt/conda/lib/python3.9/site-packages/conda_build/post.py", line 1500, in check_overlinking_impl
        all_needed_dsos, needed_dsos_for_file = _collect_needed_dsos(
      File "/opt/conda/lib/python3.9/site-packages/conda_build/post.py", line 908, in _collect_needed_dsos
        needed = get_linkages_memoized(
      File "/opt/conda/lib/python3.9/site-packages/conda_build/os_utils/liefldd.py", line 1212, in __call__
        value = self.func(*args, **kw)
      File "/opt/conda/lib/python3.9/site-packages/conda_build/os_utils/liefldd.py", line 1241, in get_linkages_memoized
        return get_linkages(
      File "/opt/conda/lib/python3.9/site-packages/conda_build/os_utils/liefldd.py", line 649, in get_linkages
        result_lief = inspect_linkages_lief(
      File "/opt/conda/lib/python3.9/site-packages/conda_build/os_utils/liefldd.py", line 528, in inspect_linkages_lief
        uniqueness_key = get_uniqueness_key(binary)
      File "/opt/conda/lib/python3.9/site-packages/conda_build/os_utils/liefldd.py", line 376, in get_uniqueness_key
        binary = ensure_binary(file)
      File "/opt/conda/lib/python3.9/site-packages/conda_build/os_utils/liefldd.py", line 49, in ensure_binary
        elif not Path(file).exists():
      File "/opt/conda/lib/python3.9/pathlib.py", line 1082, in __new__
        self = cls._from_parts(args, init=False)
      File "/opt/conda/lib/python3.9/pathlib.py", line 707, in _from_parts
        drv, root, parts = self._parse_args(args)
      File "/opt/conda/lib/python3.9/pathlib.py", line 691, in _parse_args
        a = os.fspath(a)
    TypeError: expected str, bytes or os.PathLike object, not NoneType
```

### Conda Details

<details>
<summary><code>conda info</code></summary>

```shell
active environment : None                                                                                                
       user config file : /root/.condarc                                                                                      
 populated config files : /opt/conda/.condarc                                                                                 
          conda version : 23.11.0                                                                                             
    conda-build version : 3.28.2                                                                                              
         python version : 3.9.18.final.0                                                                                      
                 solver : libmamba (default)                                                                                  
       virtual packages : __archspec=1=s390x                                                                                  
                          __conda=23.11.0=0                                                                                   
                          __glibc=2.17=0                                                                                      
                          __linux=5.10.124=0                                                                                  
                          __unix=0=0                                                                                          
       base environment : /opt/conda  (writable)                                                                              
      conda av data dir : /opt/conda/etc/conda                                                                                
  conda av metadata url : None                                                                                                
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-s390x                                                     
                          https://repo.anaconda.com/pkgs/main/noarch                                                          
                          https://repo.anaconda.com/pkgs/r/linux-s390x                                                        
                          https://repo.anaconda.com/pkgs/r/noarch                                                             
          package cache : /opt/conda/pkgs                                                                                     
                          /root/.conda/pkgs                                                                                   
       envs directories : /opt/conda/envs                                                                                     
                          /root/.conda/envs                                                                                   
               platform : linux-s390x                                                                                         
             user-agent : conda/23.11.0 requests/2.31.0 CPython/3.9.18 Linux/5.10.124-linuxkit centos/7.7.1908 glibc/2.17 solver/libmamba conda-libmamba-solver/23.12.0 libmambapy/1.5.3                                                                    
                UID:GID : 0:0                                                                                                 
             netrc file : None                                                                                                
           offline mode : False
```

</details>

<details>
<summary><code>conda config</code></summary>

```shell
==> /opt/conda/.condarc <==                                                                                                   
add_pip_as_python_dependency: False                                                                                           
show_channel_urls: True
```

</details>

<details>
<summary><code>conda list</code></summary>

```shell
# packages in environment at /opt/conda:                                                                                      
#                                                                                                                             
# Name                    Version                   Build  Channel                                                            
_libgcc_mutex             0.1                        main    defaults                                                         
_openmp_mutex             5.1                       1_gnu    defaults                                                         
archspec                  0.2.1              pyhd3eb1b0_0    defaults                                                         
attrs                     23.1.0           py39ha847dfd_0    defaults                                                         
beautifulsoup4            4.12.2           py39ha847dfd_0    defaults                                                         
boltons                   23.0.0           py39ha847dfd_0    defaults                                                         
brotli-python             1.0.9            py39hb314cc7_7    defaults                                                         
bzip2                     1.0.8                h2a837d6_0    defaults                                                         
c-ares                    1.19.1               hc33a586_0    defaults                                                         
ca-certificates           2023.12.12           ha847dfd_0    defaults                                                         
certifi                   2023.11.17       py39ha847dfd_0    defaults
cffi                      1.16.0           py39hc33a586_0    defaults
chardet                   4.0.0           py39ha847dfd_1003    defaults
charset-normalizer        2.0.4              pyhd3eb1b0_0    defaults
click                     8.1.7            py39ha847dfd_0    defaults
conda                     23.11.0          py39ha847dfd_0    defaults
conda-build               3.28.2           py39ha847dfd_0    defaults
conda-content-trust       0.1.3            py39ha847dfd_0    defaults
conda-index               0.3.0            py39ha847dfd_0    defaults
conda-libmamba-solver     23.12.0            pyhd3eb1b0_1    defaults
conda-package-handling    2.2.0            py39ha847dfd_0    defaults
conda-package-streaming   0.9.0            py39ha847dfd_0    defaults
cryptography              41.0.7           py39h0f35eb8_0    defaults
distro                    1.8.0            py39ha847dfd_0    defaults
filelock                  3.13.1           py39ha847dfd_0    defaults
fmt                       9.1.0                h36a787c_0    defaults
icu                       73.1                 hb314cc7_0    defaults
idna                      3.3                pyhd3eb1b0_0    defaults
jinja2                    3.1.2            py39ha847dfd_0    defaults
jsonpatch                 1.32               pyhd3eb1b0_0    defaults
jsonpointer               2.1                pyhd3eb1b0_0    defaults
jsonschema                4.19.2           py39ha847dfd_0    defaults
jsonschema-specifications 2023.7.1         py39ha847dfd_0    defaults
krb5                      1.20.1               hb8112af_1    defaults
ld_impl_linux-s390x       2.38                 h2beb32a_1    defaults
libarchive                3.6.2                h9384daa_2    defaults
libcurl                   8.4.0                hf098187_1    defaults
libedit                   3.1.20230828         hc33a586_0    defaults
libev                     4.33                 h2a837d6_1    defaults
libffi                    3.4.2                hb314cc7_6    defaults
libgcc-ng                 11.2.0               h1234567_1    defaults
libgomp                   11.2.0               h1234567_1    defaults
liblief                   0.12.3               hb314cc7_0    defaults
libmamba                  1.5.3                h2a17aea_0    defaults
libmambapy                1.5.3            py39ha78da6f_0    defaults
libnghttp2                1.57.0               hadef098_0    defaults
libsolv                   0.7.24               h92bb072_0    defaults
libssh2                   1.10.0               h2f79a9f_2    defaults
libstdcxx-ng              11.2.0               h1234567_1    defaults
libxml2                   2.10.4               h2b138d1_1    defaults
lz4-c                     1.9.4                hb314cc7_0    defaults
markupsafe                2.1.1            py39h2a837d6_0    defaults
menuinst                  2.0.1            py39ha847dfd_1    defaults
more-itertools            10.1.0           py39ha847dfd_0    defaults
ncurses                   6.4                  hb314cc7_0    defaults
openssl                   3.0.12               h2a837d6_0    defaults
packaging                 23.1             py39ha847dfd_0    defaults
patch                     2.7.6             h2a837d6_1001    defaults
patchelf                  0.17.2               hb314cc7_0    defaults
pcre2                     10.42                h51f2fbf_0    defaults
pip                       23.0.1           py39ha847dfd_0    defaults
pkginfo                   1.9.6            py39ha847dfd_0    defaults
platformdirs              3.10.0           py39ha847dfd_0    defaults
pluggy                    1.0.0            py39ha847dfd_1    defaults
psutil                    5.9.0            py39hc33a586_0    defaults
py-lief                   0.12.3           py39hb314cc7_0    defaults
pybind11-abi              4                    hd3eb1b0_1    defaults
pycosat                   0.6.6            py39hc33a586_0    defaults
pycparser                 2.21               pyhd3eb1b0_0    defaults
pyopenssl                 23.2.0           py39ha847dfd_0    defaults
pysocks                   1.7.1            py39ha847dfd_0    defaults
python                    3.9.18               hb93da09_0    defaults
python-libarchive-c       2.9                pyhd3eb1b0_1    defaults
pytz                      2023.3.post1     py39ha847dfd_0    defaults
pyyaml                    6.0.1            py39hc33a586_0    defaults
readline                  8.2                  hc33a586_0    defaults
referencing               0.30.2           py39ha847dfd_0    defaults
reproc                    14.2.4               hd8db5ea_1    defaults
reproc-cpp                14.2.4               hd8db5ea_1    defaults
requests                  2.31.0           py39ha847dfd_0    defaults
rpds-py                   0.10.6           py39h01014ec_0    defaults
ruamel.yaml               0.17.21          py39hc33a586_0    defaults
ruamel.yaml.clib          0.2.6            py39hc33a586_1    defaults
setuptools                65.6.3           py39ha847dfd_0    defaults
six                       1.16.0             pyhd3eb1b0_1    defaults
soupsieve                 2.5              py39ha847dfd_0    defaults
sqlite                    3.41.2               hc33a586_0    defaults
tk                        8.6.12               h2795051_0    defaults
tomli                     2.0.1            py39ha847dfd_0    defaults
tqdm                      4.65.0           py39heb6ab9f_0    defaults
tzdata                    2023c                h04d1e81_0    defaults
urllib3                   1.26.18          py39ha847dfd_0    defaults
wheel                     0.38.4           py39ha847dfd_0    defaults
xz                        5.4.5                hc33a586_0    defaults
yaml                      0.2.5                h2a837d6_0    defaults
yaml-cpp                  0.8.0                hb314cc7_0    defaults
zlib                      1.2.13               hc33a586_0    defaults
zstandard                 0.19.0           py39hc33a586_0    defaults
zstd                      1.5.5                h99a12f6_0    defaults
```

</details>


Discussion:

Resolving patch:
diff --git a/conda_build/os_utils/liefldd.py b/conda_build/os_utils/liefldd.py
--- a/conda_build/os_utils/liefldd.py
+++ b/conda_build/os_utils/liefldd.py
@@ -43,10 +43,12 @@ def is_string(s):
 # these are to be avoided, or if not avoided they
 # should be passed a binary when possible as that
 # will prevent having to parse it multiple times.
-def ensure_binary(file: str | os.PathLike | Path | lief.Binary) -> lief.Binary | None:
+def ensure_binary(
+    file: str | os.PathLike | Path | lief.Binary | None,
+) -> lief.Binary | None:
     if isinstance(file, lief.Binary):
         return file
-    elif not Path(file).exists():
+    elif not file or not Path(file).exists():
         return None
     try:
         return lief.parse(str(file))
@@ -525,9 +527,9 @@ def inspect_linkages_lief(
             todo.pop(0)
             filename2 = element[0]
             binary = element[1]
-            uniqueness_key = get_uniqueness_key(binary)
             if not binary:
                 continue
+            uniqueness_key = get_uniqueness_key(binary)
             if uniqueness_key not in already_seen:
                 parent_exe_dirname = None
                 if binary.format == lief.EXE_FORMATS.PE:


Test patch: