summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-11-01 19:07:49 +0100
committerEugen Wissner <belka@caraus.de>2023-11-01 19:07:49 +0100
commit24e62c343946e0413648f14a1d17fb2007b91a86 (patch)
tree7198c137fcfdfd33dcbac2da6012534d605e6aac
parent64233c4c635f23b2aca4d69971869a795029f3de (diff)
downloadslackbuilder-24e62c343946e0413648f14a1d17fb2007b91a86.tar.gz
Update additional download versions in slackbuild
-rw-r--r--app/Main.hs4
-rw-r--r--app/SlackBuilder/CommandLine.hs5
-rw-r--r--lib/SlackBuilder/Download.hs21
3 files changed, 16 insertions, 14 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 1793657..0337fba 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -385,7 +385,7 @@ updatePackage package@Package{..} info version = do
, checksums = getField @"md5sum" <$> allDownloads
}
liftIO $ Text.IO.writeFile infoFilePath $ generate package'
- updateSlackBuildVersion packagePath version
+ updateSlackBuildVersion packagePath version $ snd <$> moreDownloads
commit packagePath version
@@ -416,8 +416,6 @@ main = do
categories <- liftIO $ findCategory repository'
liftIO $ print $ splitFileName . makeRelative repository' <$> categories
pure Nothing
- SlackBuildCommand packagePath version ->
- updateSlackBuildVersion packagePath version >> pure Nothing
CommitCommand packagePath version ->
commit packagePath version >> pure Nothing
ExistsCommand urlPath -> pure . Text.pack . show
diff --git a/app/SlackBuilder/CommandLine.hs b/app/SlackBuilder/CommandLine.hs
index 4890567..1b51b89 100644
--- a/app/SlackBuilder/CommandLine.hs
+++ b/app/SlackBuilder/CommandLine.hs
@@ -21,7 +21,6 @@ import Options.Applicative
data SlackBuilderCommand
= CategoryCommand Text
- | SlackBuildCommand Text Text
| CommitCommand Text Text
| ExistsCommand Text
| ArchiveCommand Text Text String Text
@@ -52,7 +51,6 @@ slackBuilderParser = info slackBuilderCommand fullDesc
slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser
$ command "category" (info categoryCommand mempty)
- <> command "slackbuild" (info slackBuildCommand mempty)
<> command "commit" (info commitCommand mempty)
<> command "exists" (info existsCommand mempty)
<> command "archive" (info archiveCommand mempty)
@@ -63,9 +61,6 @@ slackBuilderCommand = subparser
where
categoryCommand = CategoryCommand
<$> argument str (metavar "PKGNAM")
- slackBuildCommand = SlackBuildCommand
- <$> argument str (metavar "PATH")
- <*> argument str (metavar "VERSION")
commitCommand = CommitCommand
<$> argument str (metavar "PATH")
<*> argument str (metavar "VERSION")
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