Repository: pyinstaller/pyinstaller

Issue:
AppImage builds are broken since version 3.6
## Description of the issue

Since the commit 392aba1817b696e3fedd92bfd05dc5266126f018, the resulting frozen directory was missing `_struct` and `zlib` folders. The binary was working, but when packaged into an `AppImage`, the followig error was shown:
```bash
[NNN...] Cannot open self file-x86_64.AppImage or archive file-x86_64.AppImage.pkg
```

## Context information (for bug reports)

* Output of `pyinstaller --version`: 392aba1817b696e3fedd92bfd05dc5266126f018
* Version of Python: 3.7.4
* Platform: GNU/Linux (Debian) and CentOS
* Did you also try this on another platform? Does it work there? Not revelant.

### Make sure [everything is packaged correctly](https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs#make-sure-everything-is-packaged-correctly)

  * [x] start with clean installation
  * [x] use the latest development version
  * [x] Run your frozen program **from a command window (shell)** — instead of double-clicking on it
  * [x] Package your program in **--onedir mode**
  * [x] Package **without UPX**, say: use the option `--noupx` or set `upx=False` in your .spec-file
  * [x] Repackage you application in **verbose/debug mode**. For this, pass the option `--debug` to `pyi-makespec` or `pyinstaller` or use `EXE(..., debug=1, ...)` in your .spec file.

### A minimal example program which shows the error

There is no real example, I think any app will do.

### Stacktrace / full error message

```bash
▶ ./app-x86_64.AppImage
[7614] PyInstaller Bootloader 3.x
[7614] LOADER: Cannot get fullpath for /home/tiger-222/app-x86_64.AppImage
[7614] LOADER: homepath is /home/tiger-222
[7614] LOADER: _MEIPASS2 is NULL
[7614] LOADER: archivename is /home/tiger-222/app-x86_64.AppImage
[7614] Loader: Cannot find cookie[7614] LOADER: archivename is /home/tiger-222/app-x86_64.AppImage.pkg
[7614] LOADER: Cannot open archive: /home/tiger-222/app-x86_64.AppImage.pkg
[7614] Cannot open self /home/tiger-222/app-x86_64.AppImage or archive /home/tiger-222/app-x86_64.AppImage.pkg
```

### Other

I made a tree diff of the same application with PyInstaller 3.5 and PyInstaller 3.6 and this shows:
```diff
@@ -1,4 +1,4 @@
-app-3.5
+app-3.6
 ├── app
 ├── array.cpython-37m-x86_64-linux-gnu.so
 ├── base_library.zip
@@ -2325,9 +2325,6 @@ AppRun-3.5
 ├── _socket.cpython-37m-x86_64-linux-gnu.so
 ├── _sqlite3.cpython-37m-x86_64-linux-gnu.so
 ├── _ssl.cpython-37m-x86_64-linux-gnu.so
-├── _struct
-│   └── cpython-37m-x86_64-linux-gnu
-│       └── sotruct.cpython-37m-x86_64-linux-gnu.so
 ├── _struct.cpython-37m-x86_64-linux-gnu.so
 ├── syslog.cpython-37m-x86_64-linux-gnu.so
 ├── termios.cpython-37m-x86_64-linux-gnu.so
@@ -2341,9 +2338,6 @@ AppRun-3.5
 ├── _uuid.cpython-37m-x86_64-linux-gnu.so
 ├── xattr
 │   └── _lib.abi3.so
-├── zlib
-│   └── cpython-37m-x86_64-linux-gnu
-│       └── soib.cpython-37m-x86_64-linux-gnu.so
 └── zlib.cpython-37m-x86_64-linux-gnu.so
 
-585 directories, 1761 files
+581 directories, 1759 files
```
### Fix

I fixed the issue by adding `_struct` and `zlib` to `hiddenimports` of the `.spec` file.
So my questions are:

- Is it the good workaround?
- Is that change of the contents of the frozen directory expected?


Discussion:
Hm the fix works on my local machine but not from a docker container :thinking: 
So the real fix, for now, is to go with the parent commit: 41237b1.
@BoboTiG if you could submit a PR that'd be great. 
@Legorooj I would love to do that, but what is the fix? :D

I do not think reverting the commit 392aba1 is the good move :thinking: 
@BoboTiG revert the commit on a new local branch, and try reapplying different versions of it until it works. Then submit a PR 

Resolving patch:
diff --git a/PyInstaller/building/api.py b/PyInstaller/building/api.py
--- a/PyInstaller/building/api.py
+++ b/PyInstaller/building/api.py
@@ -233,7 +233,9 @@ def assemble(self):
                 # file is contained within python egg, it is added with the egg
                 continue
             if typ in ('BINARY', 'EXTENSION', 'DEPENDENCY'):
-                if not self.exclude_binaries or typ == 'DEPENDENCY':
+                if self.exclude_binaries and typ == 'EXTENSION':
+                    self.dependencies.append((inm, fnm, typ))
+                elif not self.exclude_binaries or typ == 'DEPENDENCY':
                     if typ == 'BINARY':
                         # Avoid importing the same binary extension twice. This might
                         # happen if they come from different sources (eg. once from


Test patch: