diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-10-05 19:24:42 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-10-05 19:24:42 +0200 |
| commit | f3beee3e19e2d64c8700cf67eb6cefc345efcf41 (patch) | |
| tree | 0c623d8000656894cc0831a35642836057f8ea7d /lib/SlackBuilder | |
| parent | 7b5598a02e0faff590d94391a8b323e6fe74a4fe (diff) | |
| download | slackbuilder-f3beee3e19e2d64c8700cf67eb6cefc345efcf41.tar.gz | |
Combine info file structures
Diffstat (limited to 'lib/SlackBuilder')
| -rw-r--r-- | lib/SlackBuilder/Info.hs | 11 | ||||
| -rw-r--r-- | lib/SlackBuilder/Package.hs | 55 |
2 files changed, 20 insertions, 46 deletions
diff --git a/lib/SlackBuilder/Info.hs b/lib/SlackBuilder/Info.hs index ed5957c..f1631d9 100644 --- a/lib/SlackBuilder/Info.hs +++ b/lib/SlackBuilder/Info.hs @@ -79,7 +79,7 @@ packageChecksums variableName = string (variableName <> "=\"") packageRequires :: GenParser [ByteString] packageRequires = string "REQUIRES=\"" - *> sepBy packageName space + *> sepBy (packageName <|> string "%README%") space <* string "\"\n" packageName :: GenParser ByteString @@ -169,11 +169,18 @@ generate pkg = Lazy.Text.toStrict $ Text.Builder.toLazyText builder hexAppender x acc | x > 15 = showHex x acc | otherwise = '0' : showHex x acc - builder = "PKGNAM=\"" <> Text.Builder.fromString (pkgname pkg) <> "\"\n" + builder = "PRGNAM=\"" <> Text.Builder.fromString (pkgname pkg) <> "\"\n" <> "VERSION=\"" <> Text.Builder.fromText (version pkg) <> "\"\n" <> "HOMEPAGE=\"" <> Text.Builder.fromText (homepage pkg) <> "\"\n" <> generateMultiEntry "DOWNLOAD" (render <$> downloads pkg) <> generateMultiEntry "MD5SUM" (digestToText <$> checksums pkg) + <> generateMultiEntry "DOWNLOAD_x86_64" (render <$> downloads pkg) + <> generateMultiEntry "MD5SUM_x86_64" (digestToText <$> checksums pkg) + <> "REQUIRES=\"" <> fromByteStringWords (requires pkg) <> "\"\n" + <> "MAINTAINER=\"" <> Text.Builder.fromText (maintainer pkg) <> "\"\n" + <> "EMAIL=\"" <> Text.Builder.fromText (email pkg) <> "\"\n" + fromByteStringWords = Text.Builder.fromText + . Text.unwords . fmap Text.decodeUtf8 generateMultiEntry :: Text -> [Text] -> Text.Builder generateMultiEntry name entries = Text.Builder.fromText name diff --git a/lib/SlackBuilder/Package.hs b/lib/SlackBuilder/Package.hs index bd53447..4371040 100644 --- a/lib/SlackBuilder/Package.hs +++ b/lib/SlackBuilder/Package.hs @@ -2,10 +2,10 @@ module SlackBuilder.Package ( DownloadPlaceholder(..) , Download(..) , DownloadTemplate(..) + , Package(..) , PackageInfo(..) , Maintainer(..) , Updater(..) - , infoTemplate , renderDownloadWithVersion ) where @@ -15,12 +15,19 @@ import qualified Data.Text as Text import Text.URI (URI(..)) import qualified Text.URI as URI import Crypto.Hash (Digest, MD5) -import GHC.Records (HasField(..)) -import System.FilePath (takeBaseName) -import Data.List (partition) import SlackBuilder.Trans import Control.Monad.Catch (MonadThrow) +-- | Contains information how a package can be updated. +data Package = Package + { latest :: Updater + , category :: Text + , name :: Text + , homepage :: URI + , requires :: [Text] + , reupload :: Bool + } + -- | Download URI with the MD5 checksum of the target. data Download = Download { download :: URI @@ -73,43 +80,3 @@ renderDownloadWithVersion (DownloadTemplate components) version = -- | Function used to get the latest version of a source. data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate - -packageName :: PackageInfo -> Text -packageName PackageInfo{ path } = Text.pack $ takeBaseName path - -infoTemplate :: PackageInfo -> [Download] -> Text -infoTemplate package downloads = - let (downloads64, downloads32) = partition (getField @"is64") downloads - (download32, md5sum32, download64, md5sum64) = downloadEntries downloads64 downloads32 - - in Text.unlines - [ "PRGNAM=\"" <> packageName package <> "\"" - , "VERSION=\"" <> getField @"version" package <> "\"" - , "HOMEPAGE=\"" <> getField @"homepage" package <> "\"" - , "DOWNLOAD=\"" <> download32 <> "\"" - , "MD5SUM=\"" <> md5sum32 <> "\"" - , "DOWNLOAD_x86_64=\"" <> download64 <> "\"" - , "MD5SUM_x86_64=\"" <> md5sum64 <> "\"" - , "REQUIRES=\"" <> Text.unwords (getField @"requires" package) <> "\"" - , "MAINTAINER=\"" <> getField @"name" (getField @"maintainer" package) <> "\"" - , "EMAIL=\"" <> getField @"email" (getField @"maintainer" package) <> "\"" - ] - -downloadEntries :: [Download] -> [Download] -> (Text, Text, Text, Text) -downloadEntries downloads64 downloads32 = - let download32 = - if null downloads32 && not (null downloads64) - then - "UNSUPPORTED" - else - Text.intercalate " \\\n " - $ URI.render . getField @"download" <$> downloads32 - - md5sum32 = Text.intercalate " \\\n " - $ Text.pack . show . getField @"md5sum" <$> downloads32 - download64 = Text.intercalate " \\\n " - $ URI.render . getField @"download" <$> downloads64 - md5sum64 = Text.intercalate " \\\n " - $ Text.pack . show . getField @"md5sum" <$> downloads64 - - in (download32, md5sum32, download64, md5sum64) |
