From e48baad7307c4683298fbbefa84b5de9d883a698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Mairb=C3=B6ck?= Date: Sun, 29 Dec 2024 21:36:19 +0100 Subject: [PATCH 1/2] Add support for pre-uninstall scripts This is analoguous to post-install scripts. Defines a new recipe attribute PRE_UNINSTALL_SCRIPTS and new directory variables $preUninstallDir and $relativePreUninstallDir. Fixes #306. --- HaikuPorter/Package.py | 3 +++ HaikuPorter/Policy.py | 21 +++++++++++---------- HaikuPorter/Port.py | 1 + HaikuPorter/RecipeAttributes.py | 7 +++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/HaikuPorter/Package.py b/HaikuPorter/Package.py index d80571df..4812a0dc 100644 --- a/HaikuPorter/Package.py +++ b/HaikuPorter/Package.py @@ -400,6 +400,9 @@ def _generatePackageInfo(self, packageInfoPath, requiresToUse, quiet, self._writePackageInfoListQuotePaths(infoFile, self.recipeKeys['POST_INSTALL_SCRIPTS'], 'post-install-scripts') + self._writePackageInfoListQuotePaths(infoFile, + self.recipeKeys['PRE_UNINSTALL_SCRIPTS'], + 'pre-uninstall-scripts') # Generate SourceURL lines for all ports, regardless of license. # Re-use the download URLs, as specified in the recipe. diff --git a/HaikuPorter/Policy.py b/HaikuPorter/Policy.py index 81fcf811..6727aa6b 100644 --- a/HaikuPorter/Policy.py +++ b/HaikuPorter/Policy.py @@ -82,7 +82,8 @@ def checkPackage(self, package, packageFile): self._checkMisplacedDevelopLibraries() self._checkGlobalWritableFiles() self._checkUserSettingsFiles() - self._checkPostInstallScripts() + self._checkPostInstallAndPreUninstallScripts('POST_INSTALL_SCRIPTS', 'post-install') + self._checkPostInstallAndPreUninstallScripts('PRE_UNINSTALL_SCRIPTS', 'pre-uninstall') if self.strict and self.violationEncountered: sysExit("packaging policy violation(s) in strict mode") @@ -465,10 +466,10 @@ def _checkUserSettingsFiles(self): '"%s" for user settings file "%s" as included' % (components[2], components[0])) - def _checkPostInstallScripts(self): + def _checkPostInstallAndPreUninstallScripts(self, recipeKey, scriptType): # check whether declared scripts exist declaredFiles = set() - for script in self.package.recipeKeys['POST_INSTALL_SCRIPTS']: + for script in self.package.recipeKeys[recipeKey]: if script.lstrip().startswith('#'): continue @@ -480,18 +481,18 @@ def _checkPostInstallScripts(self): absScript = os.path.join(self.package.packagingDir, script) if not os.path.exists(absScript): - self._violation('Package declares non-existent post-install ' - 'script "%s"' % script) + self._violation('Package declares non-existent %s ' + 'script "%s"' % (scriptType, script)) # check whether existing scripts are declared - postInstallDir = 'boot/post-install' - dir = os.path.join(self.package.packagingDir, postInstallDir) + relativeDir = 'boot/' + scriptType + dir = os.path.join(self.package.packagingDir, relativeDir) if os.path.exists(dir): for script in os.listdir(dir): - path = postInstallDir + '/' + script + path = relativeDir + '/' + script if path not in declaredFiles: - self._violation('script "%s" not declared as post-install ' - 'script' % path) + self._violation('script "%s" not declared as %s ' + 'script' % (path, scriptType)) def _violation(self, message): self.violationEncountered = True diff --git a/HaikuPorter/Port.py b/HaikuPorter/Port.py index 599e1891..c9370610 100644 --- a/HaikuPorter/Port.py +++ b/HaikuPorter/Port.py @@ -1212,6 +1212,7 @@ def _updateShellVariables(self, forParsing): 'documentationDir': 'documentation', 'fontsDir': 'data/fonts', 'postInstallDir': 'boot/post-install', + 'preUninstallDir': 'boot/pre-uninstall', 'preferencesDir': 'preferences', 'settingsDir': 'settings', } diff --git a/HaikuPorter/RecipeAttributes.py b/HaikuPorter/RecipeAttributes.py index 216c3882..24fad831 100644 --- a/HaikuPorter/RecipeAttributes.py +++ b/HaikuPorter/RecipeAttributes.py @@ -205,6 +205,13 @@ def getRecipeFormatVersion(): 'extendable': Extendable.DEFAULT, 'indexable': False, }, + 'PRE_UNINSTALL_SCRIPTS': { + 'type': list, + 'required': False, + 'default': [], + 'extendable': Extendable.DEFAULT, + 'indexable': False, + }, 'PROVIDES': { 'type': ProvidesList, 'required': True, From 1c85cc3b0095b4070e2245874e246ae9895f8aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Mairb=C3=B6ck?= Date: Mon, 30 Dec 2024 16:40:58 +0100 Subject: [PATCH 2/2] RecipeAttributes: correctly sort alphabetically POST_INSTALL_SCRIPTS comes before PROVIDES. --- HaikuPorter/RecipeAttributes.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/HaikuPorter/RecipeAttributes.py b/HaikuPorter/RecipeAttributes.py index 24fad831..a1ccf162 100644 --- a/HaikuPorter/RecipeAttributes.py +++ b/HaikuPorter/RecipeAttributes.py @@ -205,6 +205,13 @@ def getRecipeFormatVersion(): 'extendable': Extendable.DEFAULT, 'indexable': False, }, + 'POST_INSTALL_SCRIPTS': { + 'type': list, + 'required': False, + 'default': [], + 'extendable': Extendable.DEFAULT, + 'indexable': False, + }, 'PRE_UNINSTALL_SCRIPTS': { 'type': list, 'required': False, @@ -219,13 +226,6 @@ def getRecipeFormatVersion(): 'extendable': Extendable.DEFAULT, 'indexable': False, }, - 'POST_INSTALL_SCRIPTS': { - 'type': list, - 'required': False, - 'default': [], - 'extendable': Extendable.DEFAULT, - 'indexable': False, - }, 'REPLACES': { 'type': list, 'required': False,