diff --git a/app/Foliage/CmdBuild.hs b/app/Foliage/CmdBuild.hs index 067895a..e627898 100644 --- a/app/Foliage/CmdBuild.hs +++ b/app/Foliage/CmdBuild.hs @@ -6,7 +6,7 @@ module Foliage.CmdBuild (cmdBuild) where import Codec.Archive.Tar qualified as Tar import Codec.Archive.Tar.Entry qualified as Tar import Codec.Compression.GZip qualified as GZip -import Control.Monad (unless, void, when) +import Control.Monad (forM_, unless, void, when) import Data.Aeson qualified as Aeson import Data.ByteString qualified as BS import Data.ByteString.Lazy qualified as BL @@ -92,8 +92,10 @@ buildAction makeIndexPage outputDir + makePreferedVersionsFiles outputDir packageVersions + -- TODO: mention depreciated versions on the package page ... makeAllPackagesPage currentTime outputDir packageVersions - + -- ... and on the version page. makeAllPackageVersionsPage currentTime outputDir packageVersions when doWritePackageMeta $ @@ -133,6 +135,7 @@ buildAction (IndexPkgMetadata pkgId) (fromMaybe currentTime pkgTimestamp) + -- TODO: add `/preferred-versions` to `01-index.tar`?! let tarContents = Tar.write $ sortOn Tar.entryTime (cabalEntries ++ metadataEntries) traced "Writing index" $ do BL.writeFile (anchorPath outputDirRoot repoLayoutIndexTar) tarContents @@ -312,3 +315,20 @@ mkTarEntry contents indexFile timestamp = anchorPath :: Path Absolute -> (RepoLayout -> RepoPath) -> FilePath anchorPath outputDirRoot p = toFilePath $ anchorRepoPathLocally outputDirRoot $ p hackageRepoLayout + +makePreferedVersionsFiles :: FilePath -> [PreparedPackageVersion] -> Action () +makePreferedVersionsFiles outputDir packages = traced "writing prefered versions" $ do + forM_ packages $ \package -> do + -- TODO: Some logic is missing here ... I want first to have for each + -- distinct `pkgName` the list of `pkgVersion` for which + -- `pkgVersionDepreciated == False` + let PreparedPackageVersion {pkgId} = package + let PackageIdentifier {pkgName} = pkgId + createDirectoryIfMissing True (outputDir "index" prettyShow pkgName) + Aeson.encodeFile + (outputDir "index" prettyShow pkgName "preferred-versions") + (generateCabalConstrainsts package) + +-- TODO: This function should take a list of package versions as argument?! +generateCabalConstrainsts :: a -> String +generateCabalConstrainsts _ = "FIXME ..." diff --git a/app/Foliage/PreparePackageVersion.hs b/app/Foliage/PreparePackageVersion.hs index 854bdda..f20baee 100644 --- a/app/Foliage/PreparePackageVersion.hs +++ b/app/Foliage/PreparePackageVersion.hs @@ -39,6 +39,7 @@ data PreparedPackageVersion = PreparedPackageVersion pkgTimestamp :: Maybe UTCTime, pkgVersionSource :: PackageVersionSource, pkgVersionForce :: Bool, + pkgVersionDepreciated :: Bool, pkgDesc :: GenericPackageDescription, sdistPath :: FilePath, cabalFilePath :: FilePath, @@ -124,6 +125,7 @@ preparePackageVersion inputDir metaFile = do pkgTimestamp = packageVersionTimestamp pkgSpec, pkgVersionSource = packageVersionSource pkgSpec, pkgVersionForce = packageVersionForce pkgSpec, + pkgVersionDepreciated = False, -- TODO: should parse `[deprecated]` sections in `meta.toml` pkgDesc, sdistPath, cabalFilePath,