Skip to content

Commit

Permalink
Add support for pre-uninstall scripts
Browse files Browse the repository at this point in the history
This is analoguous to post-install scripts.

Defines a new recipe attribute PRE_UNINSTALL_SCRIPTS and new directory
variables $preUninstallDir and $relativePreUninstallDir.

Fixes haikuports#306.
  • Loading branch information
jmairboeck committed Dec 29, 2024
1 parent cd87dc3 commit e48baad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
3 changes: 3 additions & 0 deletions HaikuPorter/Package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 11 additions & 10 deletions HaikuPorter/Policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions HaikuPorter/Port.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down
7 changes: 7 additions & 0 deletions HaikuPorter/RecipeAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e48baad

Please sign in to comment.