问题很简单,但我没有看到任何样本。
我需要比较PyInstaller生成的两个可执行文件,并确定哪个更新(但不是简单的时间戳)。时间戳可能更新,但内容保持不变。只有当两个时间戳都更新且内容不同时,才需要替换旧文件。
任何示例解决方案例如PyInstaller中的简单版本标签(奇怪但无法找到很多信息,在手册中仅说明使用Windows版本文件)
更新:
filecmp
- 它返回False
,即使生成2次相同的构建(使用shallow=False
标志)。就我的观点而言,最佳选择是比较内容和时间戳。如果时间戳更新且内容不同=>表示新版本。
运行pyinstaller
时,必须确保执行可重现的构建。即可用于在可执行文件之间执行比特比较的一个。根据docs:
Python使用随机散列来生成dicts和其他散列类型,这会影响已编译的字节码以及PyInstaller内部数据结构。因此,即使应用程序包的所有组件都相同且两个应用程序以相同的方式执行,两个构建也可能不会产生逐位相同的结果。
为此,只需在运行PYTHONHASHSEED
之前将pyinstaller
环境变量设置为常数:
PYTHONHASHSEED=1
export PYTHONHASHSEED
pyinstaller --onefile test.py
unset PYTHONHASHSEED
然后你可以使用你想要比较可执行文件的任何工具/模块,比如filecmp
,BeyondCompare等,甚至只是linux中的一个简单校验和:
cksum dist/test
编辑:关于时间戳或标记二进制文件 - 您可以执行以下操作以在构建后为Linux二进制文件添加其他注释:
# Create a file with the notes or comments to add to the binary.
# I am adding the current date for versioning info
date > version
# Add notes to the binary
objcopy --add-section .pyversion=version --set-section-flags .pyversion=noload,readonly dist/test dist/test-with-version
# Check the version/notes on the new binary
objdump -sj .pyversion dist/test-with-version
你应该得到类似的东西:
dist/test-with-version: file format elf64-x86-64
Contents of section .pyversion:
0000 46726920 53657020 31342031 343a3339 Fri Sep 14 14:39
0010 3a333620 41455354 20323031 380a :36 AEST 2018.