diff --git a/bin/BuildSystem/BuildSystemBase.py b/bin/BuildSystem/BuildSystemBase.py --- a/bin/BuildSystem/BuildSystemBase.py +++ b/bin/BuildSystem/BuildSystemBase.py @@ -170,18 +170,17 @@ if not super().internalPostInstall(): return False # a post install routine to fix the prefix (make things relocatable) - pkgconfigPath = os.path.join(self.imageDir(), "lib", "pkgconfig") newPrefix = OsUtils.toUnixPath(CraftCore.standardDirs.craftRoot()) oldPrefixes = [self.subinfo.buildPrefix] if CraftCore.compiler.isWindows: oldPrefixes += [OsUtils.toUnixPath(self.subinfo.buildPrefix), OsUtils.toMSysPath(self.subinfo.buildPrefix)] - if os.path.exists(pkgconfigPath): - for pcFile in os.listdir(pkgconfigPath): - if pcFile.endswith(".pc"): - path = os.path.join(pkgconfigPath, pcFile) - if not self.patchInstallPrefix([path], oldPrefixes, newPrefix): - return False + pattern = [re.compile("^.*(pc|pri|cmake)$")] + files = utils.filterDirectoryContent(self.installDir(), whitelist=lambda x, root: utils.regexFileFilter(x, root, pattern), + blacklist=lambda x, root: True) + + if not self.patchInstallPrefix(files, oldPrefixes, newPrefix): + return False if (CraftCore.compiler.isMacOS and os.path.isdir(self.installDir())): diff --git a/bin/Packager/CollectionPackagerBase.py b/bin/Packager/CollectionPackagerBase.py --- a/bin/Packager/CollectionPackagerBase.py +++ b/bin/Packager/CollectionPackagerBase.py @@ -185,12 +185,8 @@ """ return False if file is not blacklisted, and True if it is blacklisted """ if blackList is None: blackList = self.blacklist - relFilePath = os.path.relpath(filename.path, root) - for pattern in blackList: - if pattern.search(relFilePath): - CraftCore.log.debug(f"{relFilePath} is {message}: {pattern.pattern}") - return True - return False + CraftCore.log.debug(f"Start filtering: {message}") + return utils.regexFileFilter(filename, root, blackList) def _filterQtBuildType(self, filename): if not self.__deployQtSdk: diff --git a/bin/Packager/MacDMGPackager.py b/bin/Packager/MacDMGPackager.py --- a/bin/Packager/MacDMGPackager.py +++ b/bin/Packager/MacDMGPackager.py @@ -79,9 +79,9 @@ # macdeployqt might just have added some explicitly blacklisted files blackList = Path(self.packageDir(), "mac_blacklist.txt") if blackList.exists(): - blackList = [self.read_blacklist(str(blackList))] + pattern = [self.read_blacklist(str(blackList))] # use it as whitelist as we want only matches, ignore all others - matches = utils.filterDirectoryContent(appPath, whitelist=lambda x, root:self.blacklisted(x, blackList), blacklist=lambda x, root:True) + matches = utils.filterDirectoryContent(appPath, whitelist=lambda x, root: utils.regexFileFilter(x, root, pattern), blacklist=lambda x, root:True) for f in matches: CraftCore.log.info(f"Remove blacklisted file: {f}") utils.deleteFile(f) diff --git a/bin/utils.py b/bin/utils.py --- a/bin/utils.py +++ b/bin/utils.py @@ -850,6 +850,15 @@ return deps +def regexFileFilter(filename : os.DirEntry, root : str, pattern : [re]=None) -> bool: + """ return False if file does not match pattern""" + relFilePath = os.path.relpath(filename.path, root) + for pattern in pattern: + if pattern.search(relFilePath): + CraftCore.log.debug(f"regExDirFilter: {relFilePath} matches: {pattern.pattern}") + return True + return False + def filterDirectoryContent(root, whitelist=lambda f, root: True, blacklist=lambda g, root: False): """ Traverse through a directory tree and return every