-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate all Juvix projects from juvix.yaml to Package.juvix in the re…
…pository (#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 #2487
- Loading branch information
1 parent
473ed25
commit 68d4314
Showing
177 changed files
with
642 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {..} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Package; | ||
|
||
import PackageDescription.V1 open; | ||
|
||
package : Package := | ||
defaultPackage | ||
{name := "Demo"; version := mkVersion 0 1 0}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Package; | ||
|
||
import PackageDescription.V1 open; | ||
|
||
package : Package := | ||
defaultPackage | ||
{name := "midsquare"; version := mkVersion 0 1 0}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Package; | ||
|
||
import PackageDescription.V1 open; | ||
|
||
package : Package := defaultPackage {name := "bank"}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Package; | ||
|
||
import PackageDescription.V1 open; | ||
|
||
package : Package := | ||
defaultPackage | ||
{name := "Tutorial"; version := mkVersion 0 1 0}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.