From 24e62c343946e0413648f14a1d17fb2007b91a86 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Wed, 1 Nov 2023 19:07:49 +0100 Subject: Update additional download versions in slackbuild --- lib/SlackBuilder/Download.hs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'lib/SlackBuilder/Download.hs') diff --git a/lib/SlackBuilder/Download.hs b/lib/SlackBuilder/Download.hs index 011def7..4003afd 100644 --- a/lib/SlackBuilder/Download.hs +++ b/lib/SlackBuilder/Download.hs @@ -12,6 +12,8 @@ module SlackBuilder.Download import Data.ByteString (ByteString) import qualified Data.ByteString as ByteString +import Data.Map.Strict (Map) +import qualified Data.Map.Strict as Map import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.IO as Text.IO @@ -59,19 +61,26 @@ import Conduit import Crypto.Hash (Digest, MD5, hashInit, hashFinalize, hashUpdate) import Data.Void (Void) -updateSlackBuildVersion :: Text -> Text -> SlackBuilderT () -updateSlackBuildVersion packagePath version = do +updateSlackBuildVersion :: Text -> Text -> Map Text Text -> SlackBuilderT () +updateSlackBuildVersion packagePath version additionalDownloads = do repository' <- SlackBuilderT $ asks repository let name = Text.unpack $ snd $ Text.breakOnEnd "/" packagePath slackbuildFilename = repository' Text.unpack packagePath (name <.> "SlackBuild") slackbuildContents <- liftIO $ Text.IO.readFile slackbuildFilename - let (contentsHead, contentsTail) = Text.dropWhile (/= '\n') - <$> Text.breakOn "VERSION=${VERSION:-" slackbuildContents + let slackbuildLines = replaceLine . updateLineVariable "VERSION" version + <$> Text.lines slackbuildContents - liftIO $ Text.IO.writeFile slackbuildFilename - $ contentsHead <> "VERSION=${VERSION:-" <> version <> "}" <> contentsTail + liftIO $ Text.IO.writeFile slackbuildFilename $ Text.unlines slackbuildLines + where + replaceLine line = Map.foldrWithKey updateLineDependencyVersion line additionalDownloads + updateLineDependencyVersion dependencyName = updateLineVariable + $ dependencyName <> "_VERSION" + updateLineVariable variableName variableValue line + | Text.isSuffixOf (variableName <> "=") line = + variableName <> "=${" <> variableName <> ":-" <> variableValue <> "}" + | otherwise = line commit :: Text -> Text -> SlackBuilderT () commit packagePath version = do -- cgit v1.2.3