Combine info file structures

This commit is contained in:
Eugen Wissner 2023-10-05 19:24:42 +02:00
parent 7b5598a02e
commit f3beee3e19
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
4 changed files with 38 additions and 107 deletions

View File

@ -83,36 +83,7 @@ task 'rdiff-backup', [:version] do |_, arguments|
commit 'system/rdiff-backup', arguments[:version]
end
module SlackBuilder
class Updater
include Rake::FileUtilsExt
def update(version)
raise NotImplementedError
end
end
class PHP < Updater
def update(version)
package = Package.new 'development/php82',
version: version,
homepage: 'https://www.php.net/',
requires: ['postgresql']
uri = "https://www.php.net/distributions/php-#{version}.tar.xz"
tarball = "slackbuilds/development/php82/php-#{version}.tar.xz"
checksum = SlackBuilder.download URI(uri), tarball
write_info package, downloads: [Download.new(uri, checksum)]
update_slackbuild_version 'development/php82', version
commit 'development/php82', version
end
end
end
AUTO_UPDATABLE = {
'php82' => [SlackBuilder::GitHub.new('php', 'php-src', 'php'), SlackBuilder::PHP.new],
'rdiff-backup' => [SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup', 'rdiff-backup')],
'librsync' => [SlackBuilder::GitHub.new('librsync', 'librsync')],
'dmd' => [SlackBuilder::LatestText.new('https://downloads.dlang.org/releases/LATEST')]

View File

@ -15,28 +15,20 @@ import qualified Toml
import qualified Data.ByteString as ByteString
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text.Encoding
import qualified Data.Text.IO as Text.IO
import Control.Monad.Trans.Reader (ReaderT(..), asks)
import SlackBuilder.Download
import SlackBuilder.Package (Package(..))
import qualified SlackBuilder.Package as Package
import Text.URI (mkURI, URI)
import Text.URI (mkURI)
import Text.URI.QQ (uri)
import Data.Foldable (for_)
import qualified Text.URI as URI
import GHC.Records (HasField(..))
import System.FilePath ((</>), (<.>))
import SlackBuilder.Info
import Text.Megaparsec (parse, errorBundlePretty)
data Package = Package
{ latest :: Package.Updater
, category :: Text
, name :: Text
, homepage :: Maybe URI
, requires :: [Text]
, reupload :: Bool
}
autoUpdatable :: [Package]
autoUpdatable =
[ Package
@ -55,7 +47,7 @@ autoUpdatable =
in Package.Updater latest' template
, category = "development"
, name = "universal-ctags"
, homepage = Just [uri|https://ctags.io/|]
, homepage = [uri|https://ctags.io/|]
, requires = pure "%README%"
, reupload = True
}
@ -69,7 +61,7 @@ autoUpdatable =
in Package.Updater latest' template
, category = "development"
, name = "composer"
, homepage = Just [uri|https://getcomposer.org/|]
, homepage = [uri|https://getcomposer.org/|]
, requires = mempty
, reupload = False
}
@ -88,7 +80,7 @@ autoUpdatable =
in Package.Updater latest' template
, category = "network"
, name = "jitsi-meet-desktop"
, homepage = Just [uri|https://jitsi.org/|]
, homepage = [uri|https://jitsi.org/|]
, requires = mempty
, reupload = False
}
@ -110,7 +102,7 @@ autoUpdatable =
in Package.Updater latest' template
, category = "development"
, name = "php82"
, homepage = Just [uri|https://www.php.net/|]
, homepage = [uri|https://www.php.net/|]
, requires = ["postgresql"]
, reupload = False
}
@ -131,23 +123,12 @@ updatePackageIfRequired package@Package{..} version = do
infoContents <- liftIO $ ByteString.readFile $ repository' </> packagePath
case parse parseInfoFile packagePath infoContents of
Right _parsedInfoFile -> updatePackage package version
Right parsedInfoFile -> updatePackage package parsedInfoFile version
Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
updatePackage :: Package -> Text -> SlackBuilderT ()
updatePackage Package{..} version = do
maintainer' <- SlackBuilderT $ asks $ getField @"maintainer"
updatePackage :: Package -> PackageInfo -> Text -> SlackBuilderT ()
updatePackage Package{..} info version = do
let packagePath = category <> "/" <> name
package' = Package.PackageInfo
{ version = version
, requires = requires
, path = Text.unpack packagePath
, homepage = maybe "" URI.render homepage
, maintainer = Package.Maintainer
{ name = getField @"name" maintainer'
, email = getField @"email" maintainer'
}
}
Package.Updater _ downloadTemplate = latest
repository' <- SlackBuilderT $ asks repository
@ -162,9 +143,15 @@ updatePackage Package{..} version = do
download' <- handleReupload uri' relativeTarball downloadFileName
let infoFilePath = repository' </> Text.unpack packagePath
</> (Text.unpack name <.> "info")
package' = info
{ version = version
, requires = Text.Encoding.encodeUtf8 <$> requires
, homepage = URI.render homepage
, downloads = [download']
, checksums = [checksum]
}
liftIO $ Text.IO.writeFile infoFilePath
$ Package.infoTemplate package' [Package.Download download' checksum False]
liftIO $ Text.IO.writeFile infoFilePath $ generate package'
updateSlackBuildVersion packagePath version
commit packagePath version
@ -176,7 +163,6 @@ updatePackage Package{..} version = do
>> liftIO (mkURI $ "https://download.dlackware.com/hosted-sources/" <> name <> "/" <> downloadFileName)
| otherwise = pure uri'
main :: IO ()
main = do
programCommand <- execParser slackBuilderParser

View File

@ -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

View File

@ -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)