Skip to content

Commit

Permalink
[WIP] Fix input-output-hk#18: add support for deprecated-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Apr 2, 2023
1 parent 586b692 commit 9a86e4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app/Foliage/CmdBuild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $
Expand Down Expand Up @@ -133,6 +135,7 @@ buildAction
(IndexPkgMetadata pkgId)
(fromMaybe currentTime pkgTimestamp)

-- TODO: add `<package>/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
Expand Down Expand Up @@ -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 ..."
2 changes: 2 additions & 0 deletions app/Foliage/PreparePackageVersion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data PreparedPackageVersion = PreparedPackageVersion
pkgTimestamp :: Maybe UTCTime,
pkgVersionSource :: PackageVersionSource,
pkgVersionForce :: Bool,
pkgVersionDepreciated :: Bool,
pkgDesc :: GenericPackageDescription,
sdistPath :: FilePath,
cabalFilePath :: FilePath,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9a86e4c

Please sign in to comment.