1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-25 08:34:10 +03:00

Migrate all Juvix projects from juvix.yaml to Package.juvix in the repository (#2503)

This PR:

* Modifies entry point `_entryPointBuildDir` to use the `BuildDir` type
instead of `SomeBase Dir`. This allows delayed resolution of the default
build directory which was useful for the Package -> Concrete translation
point below.
* Modifies `juvix dev root` to render the current package as a
Package.juvix file.
* Modifies the Package -> Concrete translation to recognise default
arguments. So, for example, an empty `juvix.yaml` file will be
translated into the following (instead of the `name`, `version`, and
`dependencies` arguments being populated).

        
        module Package;

        import Stdlib.Prelude open;
        import PackageDescription.V1 open;

        package : Package := defaultPackage;
        
* Adds a temporary command (removed when juvix.yaml support is removed)
`juvix dev migrate-juvix-yaml` that translates `juvix.yaml` into an
equivalent `Package.juvix` in the current project.
* Adds a temporary script `migrate-juvix-yaml.sh` (removed when
juvix.yaml support is removed) which can be run in the project to
translate all Juvix projects in the repository.
* Actually translate all of the `juvix.yaml` files to `Package.juvix`
using the script.

* Part of https://github.com/anoma/juvix/issues/2487
This commit is contained in:
Paul Cadman 2023-11-07 18:11:02 +00:00 committed by GitHub
parent 473ed259a5
commit 68d4314c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
177 changed files with 641 additions and 159 deletions

View File

@ -63,7 +63,7 @@ runAppIO args@RunAppIOArgs {..} =
AskRoot -> return _runAppIOArgsRoot AskRoot -> return _runAppIOArgsRoot
AskInvokeDir -> return invDir AskInvokeDir -> return invDir
AskPkgDir -> return (_runAppIOArgsRoot ^. rootRootDir) AskPkgDir -> return (_runAppIOArgsRoot ^. rootRootDir)
AskBuildDir -> return (_runAppIOArgsRoot ^. rootBuildDir) AskBuildDir -> return (resolveAbsBuildDir (_runAppIOArgsRoot ^. rootRootDir) (_runAppIOArgsRoot ^. rootBuildDir))
RunCorePipelineEither input -> do RunCorePipelineEither input -> do
entry <- embed (getEntryPoint' args input) entry <- embed (getEntryPoint' args input)
embed (corePipelineIOEither entry) embed (corePipelineIOEither entry)

View File

@ -11,6 +11,7 @@ import Commands.Dev.DisplayRoot qualified as DisplayRoot
import Commands.Dev.Geb qualified as Geb import Commands.Dev.Geb qualified as Geb
import Commands.Dev.Highlight qualified as Highlight import Commands.Dev.Highlight qualified as Highlight
import Commands.Dev.Internal qualified as Internal import Commands.Dev.Internal qualified as Internal
import Commands.Dev.MigrateJuvixYaml qualified as MigrateJuvixYaml
import Commands.Dev.Options import Commands.Dev.Options
import Commands.Dev.Parse qualified as Parse import Commands.Dev.Parse qualified as Parse
import Commands.Dev.Runtime qualified as Runtime import Commands.Dev.Runtime qualified as Runtime
@ -31,3 +32,4 @@ runCommand = \case
Runtime opts -> Runtime.runCommand opts Runtime opts -> Runtime.runCommand opts
DisplayRoot opts -> DisplayRoot.runCommand opts DisplayRoot opts -> DisplayRoot.runCommand opts
JuvixDevRepl opts -> Repl.runCommand opts JuvixDevRepl opts -> Repl.runCommand opts
MigrateJuvixYaml opts -> runFilesIO $ MigrateJuvixYaml.runCommand opts

View File

@ -2,7 +2,7 @@ module Commands.Dev.DisplayRoot where
import Commands.Base import Commands.Base
import Commands.Dev.DisplayRoot.Options import Commands.Dev.DisplayRoot.Options
import Data.Yaml import Commands.Extra.Package
runCommand :: forall r. (Members '[Embed IO, App] r) => RootOptions -> Sem r () runCommand :: forall r. (Members '[Embed IO, App] r) => RootOptions -> Sem r ()
runCommand RootOptions {..} = do runCommand RootOptions {..} = do
@ -12,4 +12,4 @@ runCommand RootOptions {..} = do
printPackage :: Sem r () printPackage :: Sem r ()
printPackage = do printPackage = do
say "+----------------------------+" say "+----------------------------+"
askPackage >>= say . decodeUtf8 . encode . rawPackage askPackage >>= say . renderPackage

View File

@ -15,7 +15,7 @@ parseRoot = do
_rootPrintPackage <- _rootPrintPackage <-
switch switch
( long "print-package" ( long "print-package"
<> help "print the juvix.yaml file as parsed" <> help "print the Package.juvix file as parsed"
) )
_rootMainFile <- optional (parseInputFile FileExtJuvix) _rootMainFile <- optional (parseInputFile FileExtJuvix)

View File

@ -0,0 +1,20 @@
module Commands.Dev.MigrateJuvixYaml where
import Commands.Base
import Commands.Dev.MigrateJuvixYaml.Options
import Commands.Extra.Package
import Juvix.Extra.Paths
runCommand :: forall r. (Members '[Embed IO, Files, App] r) => MigrateJuvixYamlOptions -> Sem r ()
runCommand MigrateJuvixYamlOptions {..} = do
pkgDir <- askPkgDir
isGlobalPackage <- askPackageGlobal
let pkgFilePath = pkgDir <//> packageFilePath
pkgFileExists <- fileExists' pkgFilePath
pkg <- askPackage
if
| isGlobalPackage -> exitMsg (ExitFailure 1) "No Package file found"
| not pkgFileExists || _migrateJuvixYamlOptionsForce -> do
writePackageFile pkgDir pkg
removeFile' (pkgDir <//> juvixYamlFile)
| otherwise -> exitMsg (ExitFailure 1) (show pkgFilePath <> " already exists.")

View File

@ -0,0 +1,20 @@
module Commands.Dev.MigrateJuvixYaml.Options where
import CommonOptions
newtype MigrateJuvixYamlOptions = MigrateJuvixYamlOptions
{ _migrateJuvixYamlOptionsForce :: Bool
}
deriving stock (Data)
makeLenses ''MigrateJuvixYamlOptions
parseMigrateJuvixYaml :: Parser MigrateJuvixYamlOptions
parseMigrateJuvixYaml = do
_migrateJuvixYamlOptionsForce <-
switch
( long "force"
<> short 'f'
<> help "Overwrite existing Package.juvix"
)
pure MigrateJuvixYamlOptions {..}

View File

@ -18,6 +18,7 @@ import Commands.Dev.DisplayRoot.Options
import Commands.Dev.Geb.Options import Commands.Dev.Geb.Options
import Commands.Dev.Highlight.Options import Commands.Dev.Highlight.Options
import Commands.Dev.Internal.Options import Commands.Dev.Internal.Options
import Commands.Dev.MigrateJuvixYaml.Options
import Commands.Dev.Parse.Options import Commands.Dev.Parse.Options
import Commands.Dev.Repl.Options import Commands.Dev.Repl.Options
import Commands.Dev.Runtime.Options import Commands.Dev.Runtime.Options
@ -38,6 +39,7 @@ data DevCommand
| Scope ScopeOptions | Scope ScopeOptions
| Termination TerminationCommand | Termination TerminationCommand
| JuvixDevRepl ReplOptions | JuvixDevRepl ReplOptions
| MigrateJuvixYaml MigrateJuvixYamlOptions
deriving stock (Data) deriving stock (Data)
parseDevCommand :: Parser DevCommand parseDevCommand :: Parser DevCommand
@ -54,7 +56,8 @@ parseDevCommand =
commandScope, commandScope,
commandShowRoot, commandShowRoot,
commandTermination, commandTermination,
commandJuvixDevRepl commandJuvixDevRepl,
commandMigrateJuvixYaml
] ]
) )
@ -136,3 +139,10 @@ commandJuvixDevRepl =
(JuvixDevRepl <$> parseDevRepl) (JuvixDevRepl <$> parseDevRepl)
(progDesc "Run the Juvix dev REPL") (progDesc "Run the Juvix dev REPL")
) )
commandMigrateJuvixYaml :: Mod CommandFields DevCommand
commandMigrateJuvixYaml =
command "migrate-juvix-yaml" $
info
(MigrateJuvixYaml <$> parseMigrateJuvixYaml)
(progDesc "Migrate juvix.yaml to Package.juvix in the current project")

View File

@ -0,0 +1,18 @@
module Commands.Extra.Package where
import Data.Text.IO.Utf8 qualified as Utf8
import Juvix.Compiler.Pipeline.Package.Base
import Juvix.Compiler.Pipeline.Package.Loader
import Juvix.Extra.Paths
import Juvix.Prelude
renderPackage :: Package -> Text
renderPackage = renderPackageVersion PackageVersion1
writePackageFile :: (Member (Embed IO) r) => Path Abs Dir -> Package -> Sem r ()
writePackageFile root pkg =
embed
( Utf8.writeFile @IO
(toFilePath (root <//> packageFilePath))
(renderPackage pkg)
)

View File

@ -1,11 +1,10 @@
module Commands.Init where module Commands.Init where
import Commands.Extra.Package
import Commands.Init.Options import Commands.Init.Options
import Data.Text qualified as Text import Data.Text qualified as Text
import Data.Text.IO.Utf8 qualified as Utf8
import Data.Versions import Data.Versions
import Juvix.Compiler.Pipeline.Package import Juvix.Compiler.Pipeline.Package
import Juvix.Compiler.Pipeline.Package.Loader
import Juvix.Data.Effect.Fail.Extra qualified as Fail import Juvix.Data.Effect.Fail.Extra qualified as Fail
import Juvix.Extra.Paths import Juvix.Extra.Paths
import Juvix.Prelude import Juvix.Prelude
@ -39,13 +38,11 @@ init opts = do
Nothing -> emptyPkg Nothing -> emptyPkg
Just n -> emptyPkg {_packageName = n} Just n -> emptyPkg {_packageName = n}
when isInteractive (say ("creating " <> pack (toFilePath packageFilePath))) when isInteractive (say ("creating " <> pack (toFilePath packageFilePath)))
writePackage pkg cwd <- getCurrentDir
writePackageFile cwd pkg
checkPackage checkPackage
when isInteractive (say "you are all set") when isInteractive (say "you are all set")
where where
writePackage :: Package -> Sem r ()
writePackage pkg = embed (Utf8.writeFile @IO (toFilePath packageFilePath) (renderPackageVersion PackageVersion1 pkg))
isInteractive :: Bool isInteractive :: Bool
isInteractive = not (opts ^. initOptionsNonInteractive) isInteractive = not (opts ^. initOptionsNonInteractive)

View File

@ -535,8 +535,8 @@ runCommand opts = do
defaultPreludeEntryPoint :: Repl (Maybe EntryPoint) defaultPreludeEntryPoint :: Repl (Maybe EntryPoint)
defaultPreludeEntryPoint = do defaultPreludeEntryPoint = do
root <- State.gets (^. replStateRoot) root <- State.gets (^. replStateRoot)
let buildDir = root ^. rootBuildDir let buildRoot = root ^. rootRootDir
buildRoot = root ^. rootRootDir buildDir = resolveAbsBuildDir buildRoot (root ^. rootBuildDir)
pkg = root ^. rootPackage pkg = root ^. rootPackage
mstdlibPath <- liftIO (runM (runFilesIO (packageStdlib buildRoot buildDir (pkg ^. packageDependencies)))) mstdlibPath <- liftIO (runM (runFilesIO (packageStdlib buildRoot buildDir (pkg ^. packageDependencies))))
case mstdlibPath of case mstdlibPath of

View File

@ -157,7 +157,7 @@ entryPointFromGlobalOptions root mainFile opts = do
_entryPointNoStdlib = opts ^. globalNoStdlib, _entryPointNoStdlib = opts ^. globalNoStdlib,
_entryPointUnrollLimit = opts ^. globalUnrollLimit, _entryPointUnrollLimit = opts ^. globalUnrollLimit,
_entryPointGenericOptions = project opts, _entryPointGenericOptions = project opts,
_entryPointBuildDir = maybe (def ^. entryPointBuildDir) Abs mabsBuildDir, _entryPointBuildDir = maybe (def ^. entryPointBuildDir) (CustomBuildDir . Abs) mabsBuildDir,
_entryPointOffline = opts ^. globalOffline _entryPointOffline = opts ^. globalOffline
} }
where where
@ -178,7 +178,7 @@ entryPointFromGlobalOptionsNoFile root opts = do
_entryPointNoStdlib = opts ^. globalNoStdlib, _entryPointNoStdlib = opts ^. globalNoStdlib,
_entryPointUnrollLimit = opts ^. globalUnrollLimit, _entryPointUnrollLimit = opts ^. globalUnrollLimit,
_entryPointGenericOptions = project opts, _entryPointGenericOptions = project opts,
_entryPointBuildDir = maybe (def ^. entryPointBuildDir) Abs mabsBuildDir, _entryPointBuildDir = maybe (def ^. entryPointBuildDir) (CustomBuildDir . Abs) mabsBuildDir,
_entryPointOffline = opts ^. globalOffline _entryPointOffline = opts ^. globalOffline
} }
where where

View File

@ -0,0 +1,7 @@
module Package;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "Demo"; version := mkVersion 0 1 0};

View File

@ -1,2 +0,0 @@
name: Demo
version: 0.1.0

View File

@ -0,0 +1,7 @@
module Package;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "midsquare"; version := mkVersion 0 1 0};

View File

@ -1,2 +0,0 @@
name: midsquare
version: 0.1.0

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage {name := "bank"};

View File

@ -1,4 +0,0 @@
dependencies:
- .juvix-build/stdlib/
name: bank
version: 0.0.0

View File

@ -0,0 +1,10 @@
module Package;
import Stdlib.Prelude open;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "Collatz";
version := mkVersion 0 1 0;
main := just "Collatz.juvix"};

View File

@ -1,3 +0,0 @@
name: Collatz
main: Collatz.juvix
version: 0.1.0

View File

@ -0,0 +1,10 @@
module Package;
import Stdlib.Prelude open;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "Fibonacci";
version := mkVersion 0 1 0;
main := just "Fibonacci.juvix"};

View File

@ -1,3 +0,0 @@
name: Fibonacci
main: Fibonacci.juvix
version: 0.1.0

View File

@ -0,0 +1,10 @@
module Package;
import Stdlib.Prelude open;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "Hanoi";
version := mkVersion 0 1 0;
main := just "Hanoi.juvix"};

View File

@ -1,3 +0,0 @@
name: Hanoi
main: Hanoi.juvix
version: 0.1.0

View File

@ -0,0 +1,10 @@
module Package;
import Stdlib.Prelude open;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "HelloWorld";
version := mkVersion 0 1 0;
main := just "HelloWorld.juvix"};

View File

@ -1,3 +0,0 @@
name: HelloWorld
main: HelloWorld.juvix
version: 0.1.0

View File

@ -0,0 +1,10 @@
module Package;
import Stdlib.Prelude open;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "PascalsTriangle";
version := mkVersion 0 1 0;
main := just "PascalsTriangle.juvix"};

View File

@ -1,3 +0,0 @@
name: PascalsTriangle
main: PascalsTriangle.juvix
version: 0.1.0

View File

@ -0,0 +1,10 @@
module Package;
import Stdlib.Prelude open;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "TicTacToe";
version := mkVersion 0 1 0;
main := just "CLI/TicTacToe.juvix"};

View File

@ -1,3 +0,0 @@
name: TicTacToe
main: CLI/TicTacToe.juvix
version: 0.1.0

View File

@ -0,0 +1,7 @@
module Package;
import PackageDescription.V1 open;
package : Package :=
defaultPackage
{name := "Tutorial"; version := mkVersion 0 1 0};

View File

@ -1,2 +0,0 @@
name: Tutorial
version: 0.1.0

9
migrate-juvix-yaml.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Projects must be migrated depth-first because Package.juvix is searched before juvix.yaml
# (so Package.juvix in parent directories are used before juvix.yaml in the current directory)
find . -type f -name "juvix.yaml" | awk -F'/' '{print NF-1 " " $0}' | sort -nr | cut -d' ' -f2- | while IFS= read -r file; do
dir=$(dirname "$file")
echo "migrating: $dir"
(cd "$dir" && juvix dev migrate-juvix-yaml)
done

View File

@ -36,10 +36,9 @@ mkPackage ::
Path Abs Dir -> Path Abs Dir ->
Sem r Package Sem r Package
mkPackage mpackageEntry _packageRoot = do mkPackage mpackageEntry _packageRoot = do
let buildDir :: Path Abs Dir = maybe (rootBuildDir _packageRoot) (someBaseToAbs _packageRoot . (^. entryPointBuildDir)) mpackageEntry let buildDirDep = case mpackageEntry of
buildDirDep :: BuildDir Just packageEntry -> rootedBuildDir _packageRoot (packageEntry ^. entryPointBuildDir)
| isJust mpackageEntry = CustomBuildDir (Abs buildDir) Nothing -> DefaultBuildDir
| otherwise = DefaultBuildDir
maybe (readPackage _packageRoot buildDirDep) (return . (^. entryPointPackage)) mpackageEntry maybe (readPackage _packageRoot buildDirDep) (return . (^. entryPointPackage)) mpackageEntry
mkPackageInfo :: mkPackageInfo ::
@ -50,7 +49,7 @@ mkPackageInfo ::
Package -> Package ->
Sem r PackageInfo Sem r PackageInfo
mkPackageInfo mpackageEntry _packageRoot pkg = do mkPackageInfo mpackageEntry _packageRoot pkg = do
let buildDir :: Path Abs Dir = maybe (rootBuildDir _packageRoot) (someBaseToAbs _packageRoot . (^. entryPointBuildDir)) mpackageEntry let buildDir :: Path Abs Dir = maybe (rootBuildDir _packageRoot) (someBaseToAbs _packageRoot . resolveBuildDir . (^. entryPointBuildDir)) mpackageEntry
deps <- getDependencies deps <- getDependencies
let _packagePackage = set packageDependencies deps pkg let _packagePackage = set packageDependencies deps pkg
depsPaths <- mapM (fmap (^. resolvedDependencyPath) . resolveDependency . mkPackageDependencyInfo pkgFile) deps depsPaths <- mapM (fmap (^. resolvedDependencyPath) . resolveDependency . mkPackageDependencyInfo pkgFile) deps

View File

@ -7,7 +7,6 @@ where
import Juvix.Compiler.Backend import Juvix.Compiler.Backend
import Juvix.Compiler.Pipeline.Package.Base import Juvix.Compiler.Pipeline.Package.Base
import Juvix.Compiler.Pipeline.Root.Base import Juvix.Compiler.Pipeline.Root.Base
import Juvix.Extra.Paths
import Juvix.Prelude import Juvix.Prelude
-- | An option specifiying how symbols should be pruned in the Internal to Core translation -- | An option specifiying how symbols should be pruned in the Internal to Core translation
@ -22,7 +21,7 @@ data EntryPoint = EntryPoint
-- | initial root for the path resolver. Usually it should be equal to -- | initial root for the path resolver. Usually it should be equal to
-- _entryPointRoot. It only differs for `juvix repl`. -- _entryPointRoot. It only differs for `juvix repl`.
_entryPointResolverRoot :: Path Abs Dir, _entryPointResolverRoot :: Path Abs Dir,
_entryPointBuildDir :: SomeBase Dir, _entryPointBuildDir :: BuildDir,
_entryPointNoTermination :: Bool, _entryPointNoTermination :: Bool,
_entryPointNoPositivity :: Bool, _entryPointNoPositivity :: Bool,
_entryPointNoCoverage :: Bool, _entryPointNoCoverage :: Bool,
@ -56,7 +55,7 @@ defaultEntryPointNoFile root =
EntryPoint EntryPoint
{ _entryPointRoot = root ^. rootRootDir, { _entryPointRoot = root ^. rootRootDir,
_entryPointResolverRoot = root ^. rootRootDir, _entryPointResolverRoot = root ^. rootRootDir,
_entryPointBuildDir = Rel relBuildDir, _entryPointBuildDir = DefaultBuildDir,
_entryPointNoTermination = False, _entryPointNoTermination = False,
_entryPointNoPositivity = False, _entryPointNoPositivity = False,
_entryPointNoCoverage = False, _entryPointNoCoverage = False,

View File

@ -17,6 +17,7 @@ import Lens.Micro.Platform qualified as Lens
data BuildDir data BuildDir
= DefaultBuildDir = DefaultBuildDir
| CustomBuildDir (SomeBase Dir) | CustomBuildDir (SomeBase Dir)
deriving stock (Eq, Show)
type NameType :: IsProcessed -> GHC.Type type NameType :: IsProcessed -> GHC.Type
type family NameType s = res | res -> s where type family NameType s = res | res -> s where
@ -99,6 +100,17 @@ resolveBuildDir = \case
DefaultBuildDir -> Rel (relBuildDir) DefaultBuildDir -> Rel (relBuildDir)
CustomBuildDir d -> d CustomBuildDir d -> d
resolveAbsBuildDir :: Path Abs Dir -> BuildDir -> Path Abs Dir
resolveAbsBuildDir root = someBaseToAbs root . resolveBuildDir
mapCustomBuildDir :: (SomeBase Dir -> SomeBase Dir) -> BuildDir -> BuildDir
mapCustomBuildDir f = \case
DefaultBuildDir -> DefaultBuildDir
CustomBuildDir d -> CustomBuildDir (f d)
rootedBuildDir :: Path Abs Dir -> BuildDir -> BuildDir
rootedBuildDir root = mapCustomBuildDir (Abs . someBaseToAbs root)
-- | This is used when juvix.yaml exists but it is empty -- | This is used when juvix.yaml exists but it is empty
emptyPackage :: BuildDir -> Path Abs File -> Package emptyPackage :: BuildDir -> Path Abs File -> Package
emptyPackage buildDir yamlPath = emptyPackage buildDir yamlPath =

View File

@ -18,7 +18,6 @@ import Juvix.Compiler.Pipeline.Package.Loader.EvalEff
import Juvix.Compiler.Pipeline.Package.Loader.PathResolver import Juvix.Compiler.Pipeline.Package.Loader.PathResolver
import Juvix.Data.Effect.Git import Juvix.Data.Effect.Git
import Juvix.Data.Effect.Process import Juvix.Data.Effect.Process
import Juvix.Extra.Paths qualified as Paths
data LoaderResource = LoaderResource data LoaderResource = LoaderResource
{ _loaderResourceResult :: CoreResult, { _loaderResourceResult :: CoreResult,
@ -152,7 +151,7 @@ loadPackage' packagePath = do
_rootPackageGlobal = False, _rootPackageGlobal = False,
_rootPackage = rootPkg, _rootPackage = rootPkg,
_rootInvokeDir = rootPath, _rootInvokeDir = rootPath,
_rootBuildDir = Paths.rootBuildDir rootPath _rootBuildDir = DefaultBuildDir
} }
rootPkg :: Package rootPkg :: Package

View File

@ -34,49 +34,73 @@ v1PackageDescriptionType = PackageDescriptionType v1PackageDescriptionFile "Pack
fromPackage :: Package -> FunctionDefBody 'Parsed fromPackage :: Package -> FunctionDefBody 'Parsed
fromPackage p = run . runReader l $ do fromPackage p = run . runReader l $ do
defaultPackageName' <- NameUnqualified <$> symbol "defaultPackage" bodyExpression <-
argBlock <- argumentBlock Implicit =<< mkNamedArgs maybeM
let defaultPackageArg = namedApplication defaultPackageName' (argBlock :| []) defaultPackageNoArgs
functionDefExpression (defaultPackageArg :| []) defaultPackageWithArgs
(nonEmpty <$> mkNamedArgs)
functionDefExpression bodyExpression
where where
defaultPackageStr :: Text
defaultPackageStr = "defaultPackage"
defaultPackageNoArgs :: (Member (Reader Interval) r) => Sem r (NonEmpty (ExpressionAtom 'Parsed))
defaultPackageNoArgs = NEL.singleton <$> identifier defaultPackageStr
defaultPackageWithArgs :: (Member (Reader Interval) r) => NonEmpty (NamedArgument 'Parsed) -> Sem r (NonEmpty (ExpressionAtom 'Parsed))
defaultPackageWithArgs as = do
defaultPackageName' <- NameUnqualified <$> symbol defaultPackageStr
argBlock <- argumentBlock Implicit as
let defaultPackageArg = namedApplication defaultPackageName' (argBlock :| [])
return (defaultPackageArg :| [])
l :: Interval l :: Interval
l = singletonInterval (mkInitialLoc (p ^. packageFile)) l = singletonInterval (mkInitialLoc (p ^. packageFile))
mkNamedArgs :: forall r. (Member (Reader Interval) r) => Sem r (NonEmpty (NamedArgument 'Parsed)) mkNamedArgs :: forall r. (Member (Reader Interval) r) => Sem r [NamedArgument 'Parsed]
mkNamedArgs = do mkNamedArgs = do
args <- sequence (mkNameArg :| [mkVersionArg, mkDependenciesArg]) catMaybes <$> sequence [mkNameArg, mkVersionArg, mkDependenciesArg, mkMainArg, mkBuildDirArg]
optionalArgs <- catMaybes <$> sequence [mkMainArg, mkBuildDirArg]
return (appendList args optionalArgs)
where where
mkNameArg :: Sem r (NamedArgument 'Parsed) mkNameArg :: Sem r (Maybe (NamedArgument 'Parsed))
mkNameArg = do mkNameArg
n <- literalString (p ^. packageName) | defaultPackageName == p ^. packageName = return Nothing
namedArgument "name" (n :| []) | otherwise = do
n <- literalString (p ^. packageName)
Just <$> namedArgument "name" (n :| [])
mkDependenciesArg :: Sem r (NamedArgument 'Parsed) mkDependenciesArg :: Sem r (Maybe (NamedArgument 'Parsed))
mkDependenciesArg = do mkDependenciesArg = do
deps <- mkList =<< mapM mkDependencyArg (p ^. packageDependencies) let deps = p ^. packageDependencies
namedArgument "dependencies" (deps :| []) dependenciesArg = Just <$> mkDependenciesArg' (p ^. packageDependencies)
case deps of
[d] ->
if
| d == defaultStdlibDep DefaultBuildDir -> return Nothing
| otherwise -> dependenciesArg
_ -> dependenciesArg
where where
mkDependenciesArg' :: [Dependency] -> Sem r (NamedArgument 'Parsed)
mkDependenciesArg' ds = do
deps <- mkList =<< mapM mkDependencyArg ds
namedArgument "dependencies" (deps :| [])
mkDependencyArg :: Dependency -> Sem r (NonEmpty (ExpressionAtom 'Parsed)) mkDependencyArg :: Dependency -> Sem r (NonEmpty (ExpressionAtom 'Parsed))
mkDependencyArg d mkDependencyArg = \case
| d == defaultStdlibDep DefaultBuildDir = NEL.singleton <$> identifier "defaultStdlib" DependencyPath x ->
| otherwise = case d of sequence
DependencyPath x -> ( identifier "path"
sequence :| [literalString (pack (unsafePrepathToFilePath (x ^. pathDependencyPath)))]
( identifier "path" )
:| [literalString (pack (unsafePrepathToFilePath (x ^. pathDependencyPath)))] DependencyGit x ->
) sequence
DependencyGit x -> ( identifier "git"
sequence :| ( literalString
( identifier "git" <$> [ x ^. gitDependencyName,
:| ( literalString x ^. gitDependencyUrl,
<$> [ x ^. gitDependencyName, x ^. gitDependencyRef
x ^. gitDependencyUrl, ]
x ^. gitDependencyRef )
] )
)
)
mkMainArg :: Sem r (Maybe (NamedArgument 'Parsed)) mkMainArg :: Sem r (Maybe (NamedArgument 'Parsed))
mkMainArg = do mkMainArg = do
@ -94,12 +118,17 @@ v1PackageDescriptionType = PackageDescriptionType v1PackageDescriptionFile "Pack
buildDirArg :: SomeBase Dir -> Sem r (NonEmpty (ExpressionAtom 'Parsed)) buildDirArg :: SomeBase Dir -> Sem r (NonEmpty (ExpressionAtom 'Parsed))
buildDirArg d = mkJust =<< literalString (pack (fromSomeDir d)) buildDirArg d = mkJust =<< literalString (pack (fromSomeDir d))
mkVersionArg :: Sem r (NamedArgument 'Parsed) mkVersionArg :: Sem r (Maybe (NamedArgument 'Parsed))
mkVersionArg = do mkVersionArg
mkVersionArgs <- liftM2 (++) explicitArgs implicitArgs | p ^. packageVersion == defaultVersion = return Nothing
mkVersionName <- identifier "mkVersion" | otherwise = Just <$> mkVersionArg'
namedArgument "version" (mkVersionName :| mkVersionArgs)
where where
mkVersionArg' :: Sem r (NamedArgument 'Parsed)
mkVersionArg' = do
mkVersionArgs <- liftM2 (++) explicitArgs implicitArgs
mkVersionName <- identifier "mkVersion"
namedArgument "version" (mkVersionName :| mkVersionArgs)
explicitArgs :: Sem r [ExpressionAtom 'Parsed] explicitArgs :: Sem r [ExpressionAtom 'Parsed]
explicitArgs = explicitArgs =
let SemVer {..} = p ^. packageVersion let SemVer {..} = p ^. packageVersion

View File

@ -44,16 +44,16 @@ findRootAndChangeDir minputFileDir mbuildDir _rootInvokeDir = do
_rootPackage <- readGlobalPackageIO _rootPackage <- readGlobalPackageIO
_rootRootDir <- runM (runFilesIO globalRoot) _rootRootDir <- runM (runFilesIO globalRoot)
let _rootPackageGlobal = True let _rootPackageGlobal = True
_rootBuildDir = getBuildDir mbuildDir _rootRootDir _rootBuildDir = getBuildDir mbuildDir
return Root {..} return Root {..}
Just yamlPath -> do Just yamlPath -> do
let _rootRootDir = parent yamlPath let _rootRootDir = parent yamlPath
_rootPackageGlobal = False _rootPackageGlobal = False
_rootBuildDir = getBuildDir mbuildDir _rootRootDir _rootBuildDir = getBuildDir mbuildDir
_rootPackage <- readPackageIO _rootRootDir (CustomBuildDir (Abs _rootBuildDir)) _rootPackage <- readPackageIO _rootRootDir _rootBuildDir
return Root {..} return Root {..}
getBuildDir :: Maybe (Path Abs Dir) -> Path Abs Dir -> Path Abs Dir getBuildDir :: Maybe (Path Abs Dir) -> BuildDir
getBuildDir mbuildDirOpt pkgDir = case mbuildDirOpt of getBuildDir mbuildDirOpt = case mbuildDirOpt of
Nothing -> Paths.rootBuildDir pkgDir Nothing -> DefaultBuildDir
Just p -> p Just p -> CustomBuildDir (Abs p)

View File

@ -7,7 +7,7 @@ data Root = Root
{ _rootRootDir :: Path Abs Dir, { _rootRootDir :: Path Abs Dir,
_rootPackage :: Package, _rootPackage :: Package,
_rootPackageGlobal :: Bool, _rootPackageGlobal :: Bool,
_rootBuildDir :: Path Abs Dir, _rootBuildDir :: BuildDir,
_rootInvokeDir :: Path Abs Dir _rootInvokeDir :: Path Abs Dir
} }
deriving stock (Show) deriving stock (Show)

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage {name := "tests"};

View File

@ -1,4 +0,0 @@
dependencies:
- .juvix-build/stdlib/
name: tests
version: 0.0.0

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,6 @@
module Package;
import PackageDescription.V1 open;
package : Package :=
defaultPackage {name := "dep1"; dependencies := []};

View File

@ -1,3 +0,0 @@
dependencies: []
name: dep1
version: 0.0.0

View File

@ -0,0 +1,6 @@
module Package;
import PackageDescription.V1 open;
package : Package :=
defaultPackage {name := "dep2"; dependencies := []};

View File

@ -1,3 +0,0 @@
dependencies: []
name: dep2
version: 0.0.0

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage {dependencies := []};

View File

@ -1 +0,0 @@
dependencies: []

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

View File

@ -0,0 +1,5 @@
module Package;
import PackageDescription.V1 open;
package : Package := defaultPackage;

Some files were not shown because too many files have changed in this diff Show More