mirror of
https://github.com/anoma/juvix.git
synced 2025-01-05 22:46:08 +03:00
Write compile output file to invoke dir by default (#1999)
This PR fixes the issue below and also adds smoke tests for the target option of the compile command. * Closes https://github.com/anoma/juvix/issues/1998
This commit is contained in:
parent
0fcf22f693
commit
e1a23c677c
@ -73,32 +73,35 @@ prepareRuntime buildDir o = do
|
||||
ensureDir (includeDir <//> parent filePath)
|
||||
BS.writeFile (toFilePath (includeDir <//> filePath)) contents
|
||||
|
||||
outputFile :: Member App r => CompileOptions -> Path Abs File -> Sem r (Path Abs File)
|
||||
outputFile :: forall r. Member App r => CompileOptions -> Path Abs File -> Sem r (Path Abs File)
|
||||
outputFile opts inputFile =
|
||||
maybe (return defaultOutputFile) someBaseToAbs' (opts ^? compileOutputFile . _Just . pathPath)
|
||||
maybe defaultOutputFile someBaseToAbs' (opts ^? compileOutputFile . _Just . pathPath)
|
||||
where
|
||||
defaultOutputFile :: Path Abs File
|
||||
defaultOutputFile = case opts ^. compileTarget of
|
||||
TargetNative64 ->
|
||||
if
|
||||
| opts ^. compileCOutput -> replaceExtension' ".c" inputFile
|
||||
| opts ^. compilePreprocess -> addExtension' ".c" (addExtension' ".out" (removeExtension' inputFile))
|
||||
| opts ^. compileAssembly -> replaceExtension' ".s" inputFile
|
||||
| otherwise -> removeExtension' inputFile
|
||||
TargetWasm32Wasi ->
|
||||
if
|
||||
| opts ^. compileCOutput -> replaceExtension' ".c" inputFile
|
||||
| opts ^. compilePreprocess -> addExtension' ".c" (addExtension' ".out" (removeExtension' inputFile))
|
||||
| opts ^. compileAssembly -> replaceExtension' ".wat" inputFile
|
||||
| otherwise -> replaceExtension' ".wasm" inputFile
|
||||
TargetGeb ->
|
||||
if
|
||||
| opts ^. compileTerm -> replaceExtension' ".geb" inputFile
|
||||
| otherwise -> replaceExtension' ".lisp" inputFile
|
||||
TargetCore ->
|
||||
replaceExtension' ".jvc" inputFile
|
||||
TargetAsm ->
|
||||
replaceExtension' ".jva" inputFile
|
||||
defaultOutputFile :: Sem r (Path Abs File)
|
||||
defaultOutputFile = do
|
||||
invokeDir <- askInvokeDir
|
||||
let baseOutputFile = invokeDir <//> filename inputFile
|
||||
return $ case opts ^. compileTarget of
|
||||
TargetNative64 ->
|
||||
if
|
||||
| opts ^. compileCOutput -> replaceExtension' ".c" inputFile
|
||||
| opts ^. compilePreprocess -> addExtension' ".c" (addExtension' ".out" (removeExtension' inputFile))
|
||||
| opts ^. compileAssembly -> replaceExtension' ".s" inputFile
|
||||
| otherwise -> removeExtension' baseOutputFile
|
||||
TargetWasm32Wasi ->
|
||||
if
|
||||
| opts ^. compileCOutput -> replaceExtension' ".c" inputFile
|
||||
| opts ^. compilePreprocess -> addExtension' ".c" (addExtension' ".out" (removeExtension' inputFile))
|
||||
| opts ^. compileAssembly -> replaceExtension' ".wat" inputFile
|
||||
| otherwise -> replaceExtension' ".wasm" baseOutputFile
|
||||
TargetGeb ->
|
||||
if
|
||||
| opts ^. compileTerm -> replaceExtension' ".geb" inputFile
|
||||
| otherwise -> replaceExtension' ".lisp" baseOutputFile
|
||||
TargetCore ->
|
||||
replaceExtension' ".jvc" baseOutputFile
|
||||
TargetAsm ->
|
||||
replaceExtension' ".jva" baseOutputFile
|
||||
|
||||
clangNativeCompile ::
|
||||
forall r.
|
||||
|
@ -1,4 +1,4 @@
|
||||
working-directory: ./../../../tests
|
||||
working-directory: ./../../../
|
||||
|
||||
tests:
|
||||
- name: shows-file-argument-for-autocompletion
|
||||
@ -16,21 +16,34 @@ tests:
|
||||
shell:
|
||||
- bash
|
||||
script: |
|
||||
cd ./../examples/milestone/HelloWorld
|
||||
cd ./examples/milestone/HelloWorld
|
||||
juvix compile HelloWorld.juvix
|
||||
[ -f HelloWorld ]
|
||||
./HelloWorld
|
||||
exit-status: 0
|
||||
stdout: |
|
||||
hello world!
|
||||
|
||||
- name: option-output-file
|
||||
command:
|
||||
shell:
|
||||
- bash
|
||||
script: |
|
||||
temp=$(mktemp -d)
|
||||
trap 'rm -rf -- "$temp"' EXIT
|
||||
cd ./examples/milestone/HelloWorld
|
||||
juvix compile -o $temp/Hello HelloWorld.juvix
|
||||
$temp/Hello
|
||||
exit-status: 0
|
||||
stdout: |
|
||||
hello world!
|
||||
|
||||
- name: flag-internal-build-dir
|
||||
command:
|
||||
shell:
|
||||
- bash
|
||||
script: |
|
||||
temp=$(mktemp -d)
|
||||
cd ./../examples/milestone/HelloWorld
|
||||
cd ./examples/milestone/HelloWorld
|
||||
juvix compile HelloWorld.juvix --internal-build-dir "$temp"
|
||||
find "$temp" | wc -l
|
||||
rm -rf "$temp"
|
||||
@ -38,3 +51,46 @@ tests:
|
||||
matches: |
|
||||
\s*([2-9]|[1-9][0-9]+)
|
||||
exit-status: 0
|
||||
|
||||
- name: default-output-file-in-invoke-dir
|
||||
command:
|
||||
shell:
|
||||
- bash
|
||||
script: |
|
||||
temp=$(mktemp -d)
|
||||
trap 'rm -rf -- "$temp"' EXIT
|
||||
testdir=$PWD/examples/milestone/HelloWorld
|
||||
cd $temp
|
||||
juvix compile $testdir/HelloWorld.juvix
|
||||
./HelloWorld
|
||||
stdout: |
|
||||
hello world!
|
||||
exit-status: 0
|
||||
|
||||
- name: target-wasm
|
||||
command:
|
||||
shell:
|
||||
- bash
|
||||
script: |
|
||||
temp=$(mktemp -d)
|
||||
trap 'rm -rf -- "$temp"' EXIT
|
||||
testdir=$PWD/examples/milestone/HelloWorld
|
||||
cd $temp
|
||||
juvix compile -t wasm32-wasi $testdir/HelloWorld.juvix
|
||||
[ -f HelloWorld.wasm ]
|
||||
stdout: ""
|
||||
exit-status: 0
|
||||
|
||||
- name: target-geb
|
||||
command:
|
||||
shell:
|
||||
- bash
|
||||
script: |
|
||||
temp=$(mktemp -d)
|
||||
trap 'rm -rf -- "$temp"' EXIT
|
||||
testdir=$PWD/tests/Geb/positive/Compilation
|
||||
cd $temp
|
||||
juvix compile -t geb $testdir/test001.juvix
|
||||
[ -f test001.lisp ]
|
||||
stdout: ""
|
||||
exit-status: 0
|
||||
|
Loading…
Reference in New Issue
Block a user