Skip to content

Commit

Permalink
append hash including Package.juvix
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Dec 4, 2024
1 parent 3076c8d commit a7ec169
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Juvix/Compiler/Pipeline/Loader/PathResolver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ where

import Data.HashMap.Strict qualified as HashMap
import Data.HashSet qualified as HashSet
import Data.List.NonEmpty.Extra qualified as NonEmpty
import Data.Versions qualified as Ver
import Juvix.Compiler.Concrete.Data.Name
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping.Error
Expand Down Expand Up @@ -76,16 +77,21 @@ findPackageJuvixFiles pkgRoot = map (fromJust . stripProperPrefix pkgRoot) <$> w
newJuvixFiles :: [Path Abs File]
newJuvixFiles = [cd <//> f | f <- files, isJuvixOrJuvixMdFile f, not (isPackageFile f)]

-- | If the file has a pre-release tag we keep it as it is. Otherwise we hash
-- all juvix files in the package.
-- | Append the hash of all files in the project to the pre-release
mkPackageInfoPackageId :: (Members '[Files] r) => Path Abs Dir -> [Path Rel File] -> PackageLike -> Sem r PackageId
mkPackageInfoPackageId root pkgRelFiles pkgLike = do
let pkgDotJuvix = mkPackageFilePath root
pkgDotJuvixExists <- fileExists' pkgDotJuvix
let pkgJuvixFiles = [root <//> rFile | rFile <- pkgRelFiles]
let baseVersion = packageLikeVersion pkgLike
version <- case Ver._svPreRel baseVersion of
Nothing -> do
filesHash <- SHA256.digestFiles [root <//> rFile | rFile <- pkgRelFiles]
return baseVersion {_svPreRel = Just (Ver.Release (pure (Ver.Alphanum filesHash)))}
Just {} -> return baseVersion
allFiles
| pkgDotJuvixExists = pkgDotJuvix : pkgJuvixFiles
| otherwise = pkgJuvixFiles
filesHash <- SHA256.digestFiles allFiles
let version = case Ver._svPreRel baseVersion of
Nothing ->
baseVersion {_svPreRel = Just (Ver.Release (pure (Ver.Alphanum filesHash)))}
Just (Ver.Release r) -> baseVersion {_svPreRel = Just (Ver.Release (NonEmpty.snoc r (Ver.Alphanum filesHash)))}
return
PackageId
{ _packageIdName = pkgLike ^. packageLikeName,
Expand Down

0 comments on commit a7ec169

Please sign in to comment.