Ultimaker-Cura.spec.jinja 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. # -*- mode: python ; coding: utf-8 -*-
  2. import os
  3. from PyInstaller.utils.hooks import collect_all
  4. datas = {{ datas }}
  5. binaries = {{ binaries }}
  6. hiddenimports = {{ hiddenimports }}
  7. {% for value in collect_all %}tmp_ret = collect_all('{{ value }}')
  8. datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
  9. {% endfor %}
  10. block_cipher = None
  11. a = Analysis(
  12. [{{ entrypoint }}],
  13. pathex=[],
  14. binaries=binaries,
  15. datas=datas,
  16. hiddenimports=hiddenimports,
  17. hookspath=[],
  18. hooksconfig={},
  19. runtime_hooks=[],
  20. excludes=[],
  21. win_no_prefer_redirects=False,
  22. win_private_assemblies=False,
  23. cipher=block_cipher,
  24. noarchive=False
  25. )
  26. pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
  27. exe = EXE(
  28. pyz,
  29. a.scripts,
  30. [],
  31. exclude_binaries=True,
  32. name=r'{{ name }}',
  33. debug=False,
  34. bootloader_ignore_signals=False,
  35. strip={{ strip }},
  36. upx={{ upx }},
  37. console=False,
  38. disable_windowed_traceback=False,
  39. argv_emulation=False,
  40. target_arch={{ target_arch }},
  41. codesign_identity=os.getenv('CODESIGN_IDENTITY', None),
  42. entitlements_file={{ entitlements_file }},
  43. icon={{ icon }}
  44. )
  45. coll = COLLECT(
  46. exe,
  47. a.binaries,
  48. a.zipfiles,
  49. a.datas,
  50. strip=False,
  51. upx=True,
  52. upx_exclude=[],
  53. name=r'{{ name }}'
  54. )
  55. {% if macos == true %}
  56. # PyInstaller seems to copy everything in the resource folder for the MacOS, this causes issues with codesigning and notarizing
  57. # The folder structure should adhere to the one specified in Table 2-5
  58. # https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1
  59. # The class below is basically ducktyping the BUNDLE class of PyInstaller and using our own `assemble` method for more fine-grain and specific
  60. # control. Some code of the method below is copied from:
  61. # https://github.com/pyinstaller/pyinstaller/blob/22d1d2a5378228744cc95f14904dae1664df32c4/PyInstaller/building/osx.py#L115
  62. #-----------------------------------------------------------------------------
  63. # Copyright (c) 2005-2022, PyInstaller Development Team.
  64. #
  65. # Distributed under the terms of the GNU General Public License (version 2
  66. # or later) with exception for distributing the bootloader.
  67. #
  68. # The full license is in the file COPYING.txt, distributed with this software.
  69. #
  70. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  71. #-----------------------------------------------------------------------------
  72. import plistlib
  73. import shutil
  74. import PyInstaller.utils.osx as osxutils
  75. from pathlib import Path
  76. from PyInstaller.building.osx import BUNDLE
  77. from PyInstaller.building.utils import (_check_path_overlap, _rmtree, add_suffix_to_extension, checkCache)
  78. from PyInstaller.building.datastruct import logger
  79. from PyInstaller.building.icon import normalize_icon_type
  80. class UMBUNDLE(BUNDLE):
  81. def assemble(self):
  82. from PyInstaller.config import CONF
  83. if _check_path_overlap(self.name) and os.path.isdir(self.name):
  84. _rmtree(self.name)
  85. logger.info("Building BUNDLE %s", self.tocbasename)
  86. # Create a minimal Mac bundle structure.
  87. macos_path = Path(self.name, "Contents", "MacOS")
  88. resources_path = Path(self.name, "Contents", "Resources")
  89. frameworks_path = Path(self.name, "Contents", "Frameworks")
  90. os.makedirs(macos_path)
  91. os.makedirs(resources_path)
  92. os.makedirs(frameworks_path)
  93. # Makes sure the icon exists and attempts to convert to the proper format if applicable
  94. self.icon = normalize_icon_type(self.icon, ("icns",), "icns", CONF["workpath"])
  95. # Ensure icon path is absolute
  96. self.icon = os.path.abspath(self.icon)
  97. # Copy icns icon to Resources directory.
  98. shutil.copy(self.icon, os.path.join(self.name, 'Contents', 'Resources'))
  99. # Key/values for a minimal Info.plist file
  100. info_plist_dict = {
  101. "CFBundleDisplayName": self.appname,
  102. "CFBundleName": self.appname,
  103. # Required by 'codesign' utility.
  104. # The value for CFBundleIdentifier is used as the default unique name of your program for Code Signing
  105. # purposes. It even identifies the APP for access to restricted OS X areas like Keychain.
  106. #
  107. # The identifier used for signing must be globally unique. The usual form for this identifier is a
  108. # hierarchical name in reverse DNS notation, starting with the toplevel domain, followed by the company
  109. # name, followed by the department within the company, and ending with the product name. Usually in the
  110. # form: com.mycompany.department.appname
  111. # CLI option --osx-bundle-identifier sets this value.
  112. "CFBundleIdentifier": self.bundle_identifier,
  113. "CFBundleExecutable": os.path.basename(self.exename),
  114. "CFBundleIconFile": os.path.basename(self.icon),
  115. "CFBundleInfoDictionaryVersion": "6.0",
  116. "CFBundlePackageType": "APPL",
  117. "CFBundleShortVersionString": self.version,
  118. }
  119. # Set some default values. But they still can be overwritten by the user.
  120. if self.console:
  121. # Setting EXE console=True implies LSBackgroundOnly=True.
  122. info_plist_dict['LSBackgroundOnly'] = True
  123. else:
  124. # Let's use high resolution by default.
  125. info_plist_dict['NSHighResolutionCapable'] = True
  126. # Merge info_plist settings from spec file
  127. if isinstance(self.info_plist, dict) and self.info_plist:
  128. info_plist_dict.update(self.info_plist)
  129. plist_filename = os.path.join(self.name, "Contents", "Info.plist")
  130. with open(plist_filename, "wb") as plist_fh:
  131. plistlib.dump(info_plist_dict, plist_fh)
  132. links = []
  133. _QT_BASE_PATH = {'PySide2', 'PySide6', 'PyQt5', 'PyQt6', 'PySide6'}
  134. for inm, fnm, typ in self.toc:
  135. # Adjust name for extensions, if applicable
  136. inm, fnm, typ = add_suffix_to_extension(inm, fnm, typ)
  137. inm = Path(inm)
  138. fnm = Path(fnm)
  139. # Copy files from cache. This ensures that are used files with relative paths to dynamic library
  140. # dependencies (@executable_path)
  141. if typ in ('EXTENSION', 'BINARY') or (typ == 'DATA' and inm.suffix == '.so'):
  142. if any(['.' in p for p in inm.parent.parts]):
  143. inm = Path(inm.name)
  144. fnm = Path(checkCache(
  145. str(fnm),
  146. strip = self.strip,
  147. upx = self.upx,
  148. upx_exclude = self.upx_exclude,
  149. dist_nm = str(inm),
  150. target_arch = self.target_arch,
  151. codesign_identity = self.codesign_identity,
  152. entitlements_file = self.entitlements_file,
  153. strict_arch_validation = (typ == 'EXTENSION'),
  154. ))
  155. frame_dst = frameworks_path.joinpath(inm)
  156. if not frame_dst.exists():
  157. if frame_dst.is_dir():
  158. os.makedirs(frame_dst, exist_ok = True)
  159. else:
  160. os.makedirs(frame_dst.parent, exist_ok = True)
  161. shutil.copy(fnm, frame_dst, follow_symlinks = True)
  162. macos_dst = macos_path.joinpath(inm)
  163. if not macos_dst.exists():
  164. if macos_dst.is_dir():
  165. os.makedirs(macos_dst, exist_ok = True)
  166. else:
  167. os.makedirs(macos_dst.parent, exist_ok = True)
  168. # Create relative symlink to the framework
  169. symlink_to = Path(*[".." for p in macos_dst.relative_to(macos_path).parts], "Frameworks").joinpath(
  170. frame_dst.relative_to(frameworks_path))
  171. try:
  172. macos_dst.symlink_to(symlink_to)
  173. except FileExistsError:
  174. pass
  175. else:
  176. if typ == 'DATA':
  177. if any(['.' in p for p in inm.parent.parts]) or inm.suffix == '.so':
  178. # Skip info dist egg and some not needed folders in tcl and tk, since they all contain dots in their files
  179. logger.warning(f"Skipping DATA file {inm}")
  180. continue
  181. res_dst = resources_path.joinpath(inm)
  182. if not res_dst.exists():
  183. if res_dst.is_dir():
  184. os.makedirs(res_dst, exist_ok = True)
  185. else:
  186. os.makedirs(res_dst.parent, exist_ok = True)
  187. shutil.copy(fnm, res_dst, follow_symlinks = True)
  188. macos_dst = macos_path.joinpath(inm)
  189. if not macos_dst.exists():
  190. if macos_dst.is_dir():
  191. os.makedirs(macos_dst, exist_ok = True)
  192. else:
  193. os.makedirs(macos_dst.parent, exist_ok = True)
  194. # Create relative symlink to the resource
  195. symlink_to = Path(*[".." for p in macos_dst.relative_to(macos_path).parts], "Resources").joinpath(
  196. res_dst.relative_to(resources_path))
  197. try:
  198. macos_dst.symlink_to(symlink_to)
  199. except FileExistsError:
  200. pass
  201. else:
  202. macos_dst = macos_path.joinpath(inm)
  203. if not macos_dst.exists():
  204. if macos_dst.is_dir():
  205. os.makedirs(macos_dst, exist_ok = True)
  206. else:
  207. os.makedirs(macos_dst.parent, exist_ok = True)
  208. shutil.copy(fnm, macos_dst, follow_symlinks = True)
  209. # Sign the bundle
  210. logger.info('Signing the BUNDLE...')
  211. try:
  212. osxutils.sign_binary(self.name, self.codesign_identity, self.entitlements_file, deep = True)
  213. except Exception as e:
  214. logger.warning(f"Error while signing the bundle: {e}")
  215. logger.warning("You will need to sign the bundle manually!")
  216. logger.info(f"Building BUNDLE {self.tocbasename} completed successfully.")
  217. app = UMBUNDLE(
  218. coll,
  219. name='{{ name }}.app',
  220. icon={{ icon }},
  221. bundle_identifier={{ osx_bundle_identifier }},
  222. version={{ version }},
  223. info_plist={
  224. 'CFBundleDisplayName': '{{ display_name }}',
  225. 'NSPrincipalClass': 'NSApplication',
  226. 'CFBundleDevelopmentRegion': 'English',
  227. 'CFBundleExecutable': '{{ name }}',
  228. 'CFBundleInfoDictionaryVersion': '6.0',
  229. 'CFBundlePackageType': 'APPL',
  230. 'CFBundleShortVersionString': {{ short_version }},
  231. 'CFBundleDocumentTypes': [{
  232. 'CFBundleTypeRole': 'Viewer',
  233. 'CFBundleTypeExtensions': ['*'],
  234. 'CFBundleTypeName': 'Model Files',
  235. }]
  236. },
  237. ){% endif %}