Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add juvix clean to remove project build artifact directory #2018

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/Commands/Clean.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Commands.Clean where

import Commands.Base

runCommand :: Members '[Files, App] r => Sem r ()
runCommand = do
buildDir <- askBuildDir
whenM (directoryExists' buildDir) (removeDirectoryRecursive' buildDir)
2 changes: 2 additions & 0 deletions app/TopCommand.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module TopCommand where

import Commands.Base hiding (Format)
import Commands.Clean qualified as Clean
import Commands.Compile qualified as Compile
import Commands.Dev qualified as Dev
import Commands.Doctor qualified as Doctor
Expand Down Expand Up @@ -32,6 +33,7 @@ runTopCommand = \case
Dev opts -> Dev.runCommand opts
Typecheck opts -> Typecheck.runCommand opts
Compile opts -> Compile.runCommand opts
Clean -> runFilesIO Clean.runCommand
Eval opts -> Eval.runCommand opts
Html opts -> Html.runCommand opts
JuvixRepl opts -> Repl.runCommand opts
Expand Down
19 changes: 14 additions & 5 deletions app/TopCommand/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data TopCommand
| DisplayHelp
| Typecheck TypecheckOptions
| Compile CompileOptions
| Clean
| Eval EvalOptions
| Html HtmlOptions
| Dev Dev.DevCommand
Expand Down Expand Up @@ -87,7 +88,8 @@ parseUtility =
commandInit,
commandDev,
commandRepl,
commandFormat
commandFormat,
commandClean
]
)
where
Expand Down Expand Up @@ -121,18 +123,25 @@ parseUtility =
command "format" $
info
(JuvixFormat <$> parseFormat)
( progDescDoc
( headerDoc
( Just
( vsep
[ "Format a Juvix file or Juvix project",
[ "juvix format is used to format Juvix source files.",
"",
"When the command is run with an unformatted file it prints the reformatted source to standard output.",
"When the command is run with a project directory it prints a list of unformatted files in the project."
"Given an unformatted file, it prints the reformatted source to standard output.",
"Given a project directory it prints a list of unformatted files in the project."
]
)
)
<> progDesc "Format a Juvix file or Juvix project"
)

commandClean :: Mod CommandFields TopCommand
commandClean =
command
"clean"
(info (pure Clean) (progDesc "Delete build artifacts"))

commandCheck :: Mod CommandFields TopCommand
commandCheck =
command "typecheck" $
Expand Down
61 changes: 61 additions & 0 deletions tests/smoke/Commands/clean.smoke.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
working-directory: ./../../../

tests:
- name: clean-with-no-build-dir
command:
shell:
- bash
script: |
temp=$(mktemp -d)
trap 'rm -rf -- "$temp"' EXIT
cd $temp
juvix clean
stdout: ""
exit-status: 0

- name: clean-with-default-build-dir
command:
shell:
- bash
script: |
temp=$(mktemp -d)
trap 'rm -rf -- "$temp"' EXIT
cd ./examples/milestone/HelloWorld
juvix compile -o $temp/Hello HelloWorld.juvix
juvix clean
[ -d $temp/.juvix-build ]
stdout: ""
exit-status: 1

- name: clean-with-internal-build-dir
command:
shell:
- bash
script: |
temp=$(mktemp -d)
trap 'rm -rf -- "$temp"' EXIT
temp_build_dir=$(mktemp -d)
trap 'rm -rf -- "$temp_build_dir"' EXIT
cd ./examples/milestone/HelloWorld
juvix compile -o $temp/Hello HelloWorld.juvix --internal-build-dir "$temp_build_dir"
juvix --internal-build-dir "$temp_build_dir" clean
[ -d $temp_build_dir ]
stdout: ""
exit-status: 1

- name: clean-with-internal-build-dir-does-not-remove-default-build-dir
command:
shell:
- bash
script: |
temp=$(mktemp -d)
trap 'rm -rf -- "$temp"' EXIT
temp_build_dir=$(mktemp -d)
trap 'rm -rf -- "$temp_build_dir"' EXIT
cp -r ./examples/milestone/HelloWorld/. $temp
cd $temp
juvix compile HelloWorld.juvix
juvix --internal-build-dir "$temp_build_dir" clean
[ -d $temp/.juvix-build ]
stdout: ""
exit-status: 0