Skip to content

Commit a15e82e

Browse files
authored
Add support for pre-uninstall scripts (#309)
* 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. * RecipeAttributes: correctly sort alphabetically POST_INSTALL_SCRIPTS comes before PROVIDES.
1 parent aa5e2fd commit a15e82e

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

HaikuPorter/Package.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ def _generatePackageInfo(self, packageInfoPath, requiresToUse, quiet,
400400
self._writePackageInfoListQuotePaths(infoFile,
401401
self.recipeKeys['POST_INSTALL_SCRIPTS'],
402402
'post-install-scripts')
403+
self._writePackageInfoListQuotePaths(infoFile,
404+
self.recipeKeys['PRE_UNINSTALL_SCRIPTS'],
405+
'pre-uninstall-scripts')
403406

404407
# Generate SourceURL lines for all ports, regardless of license.
405408
# Re-use the download URLs, as specified in the recipe.

HaikuPorter/Policy.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def checkPackage(self, package, packageFile):
8282
self._checkMisplacedDevelopLibraries()
8383
self._checkGlobalWritableFiles()
8484
self._checkUserSettingsFiles()
85-
self._checkPostInstallScripts()
85+
self._checkPostInstallAndPreUninstallScripts('POST_INSTALL_SCRIPTS', 'post-install')
86+
self._checkPostInstallAndPreUninstallScripts('PRE_UNINSTALL_SCRIPTS', 'pre-uninstall')
8687

8788
if self.strict and self.violationEncountered:
8889
sysExit("packaging policy violation(s) in strict mode")
@@ -465,10 +466,10 @@ def _checkUserSettingsFiles(self):
465466
'"%s" for user settings file "%s" as included'
466467
% (components[2], components[0]))
467468

468-
def _checkPostInstallScripts(self):
469+
def _checkPostInstallAndPreUninstallScripts(self, recipeKey, scriptType):
469470
# check whether declared scripts exist
470471
declaredFiles = set()
471-
for script in self.package.recipeKeys['POST_INSTALL_SCRIPTS']:
472+
for script in self.package.recipeKeys[recipeKey]:
472473
if script.lstrip().startswith('#'):
473474
continue
474475

@@ -480,18 +481,18 @@ def _checkPostInstallScripts(self):
480481

481482
absScript = os.path.join(self.package.packagingDir, script)
482483
if not os.path.exists(absScript):
483-
self._violation('Package declares non-existent post-install '
484-
'script "%s"' % script)
484+
self._violation('Package declares non-existent %s '
485+
'script "%s"' % (scriptType, script))
485486

486487
# check whether existing scripts are declared
487-
postInstallDir = 'boot/post-install'
488-
dir = os.path.join(self.package.packagingDir, postInstallDir)
488+
relativeDir = 'boot/' + scriptType
489+
dir = os.path.join(self.package.packagingDir, relativeDir)
489490
if os.path.exists(dir):
490491
for script in os.listdir(dir):
491-
path = postInstallDir + '/' + script
492+
path = relativeDir + '/' + script
492493
if path not in declaredFiles:
493-
self._violation('script "%s" not declared as post-install '
494-
'script' % path)
494+
self._violation('script "%s" not declared as %s '
495+
'script' % (path, scriptType))
495496

496497
def _violation(self, message):
497498
self.violationEncountered = True

HaikuPorter/Port.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ def _updateShellVariables(self, forParsing):
12121212
'documentationDir': 'documentation',
12131213
'fontsDir': 'data/fonts',
12141214
'postInstallDir': 'boot/post-install',
1215+
'preUninstallDir': 'boot/pre-uninstall',
12151216
'preferencesDir': 'preferences',
12161217
'settingsDir': 'settings',
12171218
}

HaikuPorter/RecipeAttributes.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,27 @@ def getRecipeFormatVersion():
205205
'extendable': Extendable.DEFAULT,
206206
'indexable': False,
207207
},
208-
'PROVIDES': {
209-
'type': ProvidesList,
210-
'required': True,
211-
'default': None,
208+
'POST_INSTALL_SCRIPTS': {
209+
'type': list,
210+
'required': False,
211+
'default': [],
212212
'extendable': Extendable.DEFAULT,
213213
'indexable': False,
214214
},
215-
'POST_INSTALL_SCRIPTS': {
215+
'PRE_UNINSTALL_SCRIPTS': {
216216
'type': list,
217217
'required': False,
218218
'default': [],
219219
'extendable': Extendable.DEFAULT,
220220
'indexable': False,
221221
},
222+
'PROVIDES': {
223+
'type': ProvidesList,
224+
'required': True,
225+
'default': None,
226+
'extendable': Extendable.DEFAULT,
227+
'indexable': False,
228+
},
222229
'REPLACES': {
223230
'type': list,
224231
'required': False,

0 commit comments

Comments
 (0)