Skip to content

Commit

Permalink
ensure global package when finding the root
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Dec 6, 2023
1 parent 1386286 commit 5b9f514
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 0 additions & 3 deletions app/Commands/Extra/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import Juvix.Compiler.Pipeline.Package.Loader
import Juvix.Extra.Paths
import Juvix.Prelude

currentPackageVersion :: PackageVersion
currentPackageVersion = PackageVersion2

renderPackage :: Package -> Text
renderPackage = renderPackageVersion currentPackageVersion

Expand Down
12 changes: 9 additions & 3 deletions src/Juvix/Compiler/Pipeline/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Juvix.Compiler.Pipeline.Package
readGlobalPackage,
loadPackageFileIO,
packageBasePackage,
ensureGlobalPackage,
)
where

Expand Down Expand Up @@ -155,17 +156,22 @@ readGlobalPackageIO =
. runEvalFileEffIO
$ readGlobalPackage

readGlobalPackage :: (Members '[TaggedLock, Error JuvixError, EvalFileEff, Files] r) => Sem r Package
readGlobalPackage = do
ensureGlobalPackage :: (Members '[TaggedLock, Files] r) => Sem r (Path Abs File)
ensureGlobalPackage = do
packagePath <- globalPackageJuvix
withTaggedLockDir (parent packagePath) (unlessM (fileExists' packagePath) writeGlobalPackage)
return packagePath

readGlobalPackage :: (Members '[TaggedLock, Error JuvixError, EvalFileEff, Files] r) => Sem r Package
readGlobalPackage = do
packagePath <- ensureGlobalPackage
readPackage (parent packagePath) DefaultBuildDir

writeGlobalPackage :: (Members '[Files] r) => Sem r ()
writeGlobalPackage = do
packagePath <- globalPackageJuvix
ensureDir' (parent packagePath)
writeFile' packagePath (renderPackageVersion PackageVersion1 (globalPackage packagePath))
writeFile' packagePath (renderPackageVersion currentPackageVersion (globalPackage packagePath))

packageBasePackage :: Package
packageBasePackage =
Expand Down
3 changes: 3 additions & 0 deletions src/Juvix/Compiler/Pipeline/Package/Loader/Versions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import Juvix.Compiler.Pipeline.Package.Loader.Error
import Juvix.Extra.Paths
import Juvix.Prelude

currentPackageVersion :: PackageVersion
currentPackageVersion = PackageVersion2

data PackageVersion
= PackageVersion1
| PackageVersion2
Expand Down
4 changes: 3 additions & 1 deletion src/Juvix/Compiler/Pipeline/Root.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import Control.Exception (SomeException)
import Control.Exception qualified as IO
import Juvix.Compiler.Pipeline.Package
import Juvix.Compiler.Pipeline.Root.Base
import Juvix.Data.Effect.TaggedLock
import Juvix.Extra.Paths qualified as Paths
import Juvix.Prelude

findRootAndChangeDir ::
forall r.
(Members '[Embed IO, Final IO] r) =>
(Members '[TaggedLock, Embed IO, Final IO] r) =>
Maybe (Path Abs Dir) ->
Maybe (Path Abs Dir) ->
Path Abs Dir ->
Sem r Root
findRootAndChangeDir minputFileDir mbuildDir _rootInvokeDir = do
r <- runError (fromExceptionSem @SomeException go)
runFilesIO ensureGlobalPackage
case r of
Left (err :: IO.SomeException) -> liftIO $ do
putStrLn "Something went wrong when looking for the root of the project"
Expand Down

0 comments on commit 5b9f514

Please sign in to comment.