diff --git a/app/Commands/Extra/Package.hs b/app/Commands/Extra/Package.hs index b74a756a80..a6d5ca4556 100644 --- a/app/Commands/Extra/Package.hs +++ b/app/Commands/Extra/Package.hs @@ -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 diff --git a/src/Juvix/Compiler/Pipeline/Package.hs b/src/Juvix/Compiler/Pipeline/Package.hs index 0af265269f..2fef5e53d1 100644 --- a/src/Juvix/Compiler/Pipeline/Package.hs +++ b/src/Juvix/Compiler/Pipeline/Package.hs @@ -7,6 +7,7 @@ module Juvix.Compiler.Pipeline.Package readGlobalPackage, loadPackageFileIO, packageBasePackage, + ensureGlobalPackage, ) where @@ -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 = diff --git a/src/Juvix/Compiler/Pipeline/Package/Loader/Versions.hs b/src/Juvix/Compiler/Pipeline/Package/Loader/Versions.hs index f574d7e203..2fe2c8fde7 100644 --- a/src/Juvix/Compiler/Pipeline/Package/Loader/Versions.hs +++ b/src/Juvix/Compiler/Pipeline/Package/Loader/Versions.hs @@ -12,6 +12,10 @@ import Juvix.Compiler.Pipeline.Package.Loader.Error import Juvix.Extra.Paths import Juvix.Prelude + +currentPackageVersion :: PackageVersion +currentPackageVersion = PackageVersion2 + data PackageVersion = PackageVersion1 | PackageVersion2 diff --git a/src/Juvix/Compiler/Pipeline/Root.hs b/src/Juvix/Compiler/Pipeline/Root.hs index 28a618ddcb..eab7e8a77b 100644 --- a/src/Juvix/Compiler/Pipeline/Root.hs +++ b/src/Juvix/Compiler/Pipeline/Root.hs @@ -10,16 +10,18 @@ import Juvix.Compiler.Pipeline.Package import Juvix.Compiler.Pipeline.Root.Base import Juvix.Extra.Paths qualified as Paths import Juvix.Prelude +import Juvix.Data.Effect.TaggedLock 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"