Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building: ensure that onefile builds on Windows have manifest embedded #5625

Merged
merged 2 commits into from Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions PyInstaller/building/api.py
Expand Up @@ -531,8 +531,7 @@ def assemble(self):
if not os.path.exists(exe):
raise SystemExit(_MISSING_BOOTLOADER_ERRORMSG)

if is_win and (self.icon != "NONE" or self.versrsrc or self.resources
or self.uac_admin or self.uac_uiaccess or not is_64bits):
if is_win:
fd, tmpnm = tempfile.mkstemp(prefix=os.path.basename(exe) + ".",
dir=CONF['workpath'])
# need to close the file, otherwise copying resources will fail
Expand Down Expand Up @@ -598,7 +597,7 @@ def assemble(self):
logger.error("Error while updating resource %s %s in %s"
" from data file %s",
restype, resname, tmpnm, resfile, exc_info=1)
if is_win and self.manifest and not self.exclude_binaries:
if self.manifest and not self.exclude_binaries:
self.manifest.update_resources(tmpnm, [1])
trash.append(tmpnm)
exe = tmpnm
Expand Down
2 changes: 2 additions & 0 deletions news/5625.bugfix.rst
@@ -0,0 +1,2 @@
(Windows) Fix ``onefile`` builds not having manifest embedded when icon is
disabled via ``--icon NONE``.
36 changes: 36 additions & 0 deletions tests/functional/test_basic.py
Expand Up @@ -676,3 +676,39 @@ def test_onefile_longpath(pyi_builder, tmpdir):
assert secret == r'{secret}'
""".format(data_file=dst_filename, secret=_SECRET),
['--add-data', str(add_data_name)])


@pytest.mark.win32
@pytest.mark.parametrize("icon", ["icon_default", "icon_none", "icon_given"])
def test_onefile_has_manifest(pyi_builder, icon):
"""
Verify that onefile builds on Windows end up having manifest
embedded. See issue #5624.
"""
from PyInstaller.utils.win32 import winmanifest
from PyInstaller import PACKAGEPATH

# The test is relevant only for onefile builds
if pyi_builder._mode != 'onefile':
pytest.skip('The test is relevant only to onefile builds.')
# Icon type
if icon == 'icon_default':
# Default; no --icon argument
extra_args = []
elif icon == 'icon_none':
# Disable icon completely; --icon NONE
extra_args = ['--icon', 'NONE']
elif icon == 'icon_given':
# Locate pyinstaller's default icon, and explicitly give it
# via --icon argument
icon_path = os.path.join(PACKAGEPATH, 'bootloader', 'images',
'icon-console.ico')
extra_args = ['--icon', icon_path]
# Build the executable...
pyi_builder.test_source("""print('Hello world!')""", extra_args)
# ... and ensure that it contains manifest
exes = pyi_builder._find_executables('test_source')
assert exes
for exe in exes:
res = winmanifest.GetManifestResources(exe)
assert res, "No manifest resources found!"