Changeset View
Changeset View
Standalone View
Standalone View
bin/Packager/CollectionPackagerBase.py
Show First 20 Lines • Show All 200 Lines • ▼ Show 20 Line(s) | 200 | if self.buildType() == "Debug": | |||
---|---|---|---|---|---|
201 | out = rt is not [] | 201 | out = rt is not [] | ||
202 | else: | 202 | else: | ||
203 | out = not rt | 203 | out = not rt | ||
204 | if not out: | 204 | if not out: | ||
205 | CraftCore.log.debug(f"Skipp {filename} as it has the wrong build type: {rt}") | 205 | CraftCore.log.debug(f"Skipp {filename} as it has the wrong build type: {rt}") | ||
206 | return out | 206 | return out | ||
207 | return True | 207 | return True | ||
208 | 208 | | |||
209 | def isDebugSymbolFile(self, fileName): | ||||
210 | _, ext = os.path.splitext(fileName) | ||||
211 | if ext in {".pdb"}: | ||||
212 | return True | ||||
213 | return False | ||||
214 | | ||||
215 | def isBinary(self, fileName): | ||||
216 | if os.path.islink(fileName): | ||||
217 | return False | ||||
218 | _, ext = os.path.splitext(fileName) | ||||
219 | if CraftCore.compiler.isWindows: | ||||
220 | if ext in {".dll", ".exe"}: | ||||
221 | return True | ||||
222 | else: | ||||
223 | if ext in {".so", ".dylib"} or os.access(entry_target, os.X_OK): | ||||
224 | return True | ||||
225 | return False | ||||
226 | | ||||
227 | | ||||
228 | | ||||
209 | def traverse(self, directory, whitelist=lambda f: True, blacklist=lambda g: False): | 229 | def traverse(self, directory, whitelist=lambda f: True, blacklist=lambda g: False): | ||
210 | """ | 230 | """ | ||
211 | Traverse through a directory tree and return every | 231 | Traverse through a directory tree and return every | ||
212 | filename that the function whitelist returns as true and | 232 | filename that the function whitelist returns as true and | ||
213 | which do not match blacklist entries | 233 | which do not match blacklist entries | ||
214 | """ | 234 | """ | ||
215 | directory = OsUtils.toUnixPath(directory) | 235 | directory = OsUtils.toUnixPath(directory) | ||
216 | if blacklist(directory): | 236 | if blacklist(directory): | ||
Show All 12 Lines | 248 | if os.path.isdir(f) and not os.path.islink(f): | |||
229 | dirs.append(f) | 249 | dirs.append(f) | ||
230 | elif os.path.isdir(f) and os.path.islink(f): | 250 | elif os.path.isdir(f) and os.path.islink(f): | ||
231 | if whitelist(z): | 251 | if whitelist(z): | ||
232 | yield f | 252 | yield f | ||
233 | elif os.path.isfile(f) and whitelist(z): | 253 | elif os.path.isfile(f) and whitelist(z): | ||
234 | if self._filterQtBuildType(f): | 254 | if self._filterQtBuildType(f): | ||
235 | yield f | 255 | yield f | ||
236 | 256 | | |||
237 | def copyFiles(self, srcDir, destDir, dontStrip) -> bool: | 257 | def copyFiles(self, srcDir, destDir, dontStrip, symbolFiles : [str]=None) -> bool: | ||
238 | """ | 258 | """ | ||
239 | Copy the binaries for the Package from srcDir to the imageDir | 259 | Copy the binaries for the Package from srcDir to the imageDir | ||
240 | directory | 260 | directory | ||
241 | """ | 261 | """ | ||
242 | srcDir = OsUtils.toUnixPath(srcDir) | 262 | srcDir = OsUtils.toUnixPath(srcDir) | ||
243 | destDir = OsUtils.toUnixPath(destDir) | 263 | destDir = OsUtils.toUnixPath(destDir) | ||
244 | if not destDir.endswith("/"): | 264 | if not destDir.endswith("/"): | ||
245 | destDir += "/" | 265 | destDir += "/" | ||
246 | CraftCore.log.debug("Copying %s -> %s" % (srcDir, destDir)) | 266 | CraftCore.log.debug("Copying %s -> %s" % (srcDir, destDir)) | ||
247 | 267 | | |||
268 | doSign = CraftCore.compiler.isWindows and CraftCore.settings.getboolean("CodeSigning", "Enabled", False) | ||||
269 | | ||||
248 | for entry in self.traverse(srcDir, self.whitelisted, self.blacklisted): | 270 | for entry in self.traverse(srcDir, self.whitelisted, self.blacklisted): | ||
249 | entry_target = OsUtils.toNativePath(entry.replace(srcDir, destDir)) | 271 | entry_target = OsUtils.toNativePath(entry.replace(srcDir, destDir)) | ||
250 | if not utils.copyFile(entry, entry_target, linkOnly=False): | 272 | if not utils.copyFile(entry, entry_target, linkOnly=False): | ||
251 | return False | 273 | return False | ||
252 | if not dontStrip: | 274 | if self.isBinary(entry_target): | ||
253 | if OsUtils.isWin(): | 275 | if dontStrip: | ||
254 | if entry_target.endswith((".dll", ".exe")): | 276 | self.strip(entry_target) | ||
255 | self.strip(entry_target) | 277 | if doSign: | ||
256 | elif OsUtils.isUnix(): | 278 | utils.sign(files) | ||
257 | if not os.path.islink(entry_target) and ".so" in entry_target or os.access(entry_target, os.X_OK): | 279 | elif symbolFiles is not None and self.isDebugSymbolFile(entry_target): | ||
258 | self.strip(entry_target) | 280 | symbolFiles.append(entry_target) | ||
259 | return True | 281 | return True | ||
260 | 282 | | |||
261 | def internalCreatePackage(self) -> bool: | 283 | def internalCreatePackage(self, packageSymbolFile=False) -> bool: | ||
262 | """ create a package """ | 284 | """ create a package """ | ||
263 | 285 | | |||
264 | archiveDir = self.archiveDir() | 286 | archiveDir = self.archiveDir() | ||
265 | 287 | | |||
266 | CraftCore.log.debug("cleaning package dir: %s" % archiveDir) | 288 | CraftCore.log.debug("cleaning package dir: %s" % archiveDir) | ||
267 | utils.cleanDirectory(archiveDir) | 289 | utils.cleanDirectory(archiveDir) | ||
290 | | ||||
291 | if packageSymbolFile: | ||||
292 | symbolFiles = [] | ||||
293 | else: | ||||
294 | self.blacklist.append(re.compile(r".*\.pdb")) | ||||
295 | symbolFiles = None | ||||
296 | | ||||
268 | for directory, strip in self.__getImageDirectories(): | 297 | for directory, strip in self.__getImageDirectories(): | ||
269 | imageDir = archiveDir | | |||
270 | if os.path.exists(directory): | 298 | if os.path.exists(directory): | ||
271 | if not self.copyFiles(directory, imageDir, strip): | 299 | if not self.copyFiles(directory, archiveDir, strip, symbolFiles=symbolFiles): | ||
272 | return False | 300 | return False | ||
273 | else: | 301 | else: | ||
274 | CraftCore.log.critical("image directory %s does not exist!" % directory) | 302 | CraftCore.log.critical("image directory %s does not exist!" % directory) | ||
275 | return False | 303 | return False | ||
276 | 304 | | |||
277 | if not utils.createDir(archiveDir): | 305 | if symbolFiles: | ||
278 | return False | 306 | dbgDir = f"{archiveDir}-dbg" | ||
307 | utils.cleanDirectory(dbgDir) | ||||
308 | | ||||
309 | for f in symbolFiles: | ||||
310 | dest = os.path.join(dbgDir, os.path.relpath(f, archiveDir)) | ||||
311 | utils.createDir(os.path.dirname(dest)) | ||||
312 | utils.moveFile(f, dest) | ||||
279 | 313 | | |||
280 | if self.subinfo.options.package.movePluginsToBin: | 314 | if self.subinfo.options.package.movePluginsToBin: | ||
281 | # Qt expects plugins and qml files below bin, on the target sytsem | 315 | # Qt expects plugins and qml files below bin, on the target sytsem | ||
282 | binPath = os.path.join(archiveDir, "bin") | 316 | binPath = os.path.join(archiveDir, "bin") | ||
283 | for path in [os.path.join(archiveDir, "plugins"), os.path.join(archiveDir, "qml")]: | 317 | for path in [os.path.join(archiveDir, "plugins"), os.path.join(archiveDir, "qml")]: | ||
284 | if os.path.isdir(path): | 318 | if os.path.isdir(path): | ||
285 | if not utils.mergeTree(path, binPath): | 319 | if not utils.mergeTree(path, binPath): | ||
286 | return False | 320 | return False | ||
287 | 321 | | |||
288 | if not self.preArchive(): | 322 | if not self.preArchive(): | ||
289 | return False | 323 | return False | ||
290 | | ||||
291 | if CraftCore.settings.getboolean("CodeSigning", "Enabled", False): | | |||
292 | files = [] | | |||
293 | if CraftCore.compiler.isWindows: | | |||
294 | for pattern in ["**/*.dll", "**/*.exe"]: | | |||
295 | files.extend(glob.glob(os.path.join(archiveDir, pattern), recursive=True)) | | |||
296 | if not utils.sign(files): | | |||
297 | return False | | |||
298 | return True | 324 | return True | ||
299 | 325 | | |||
300 | def preArchive(self): | 326 | def preArchive(self): | ||
301 | return True | 327 | return True |