This commit is contained in:
Jaremy Creechley 2024-05-02 00:21:45 +03:00
parent 6352392d87
commit 7ed2c0a531
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300

View File

@ -1,24 +1,5 @@
import std/[hashes, json, strutils, strformat, os, osproc] import std/[hashes, json, strutils, strformat, os, osproc]
template withDir(dir: string, blk: untyped) =
let prev = getCurrentDir()
try:
setCurrentDir(dir)
`blk`
finally:
setCurrentDir(prev)
proc setProjDir(prev = getCurrentDir()): string =
if not "codex.nimble".fileExists():
setCurrentDir("..")
if prev == getCurrentDir():
echo "\nERROR: Codex project folder not found (could not find codex.nimble)"
echo "\nBenchmark must be run from within the Codex project folder"
quit 1
setProjDir()
else:
getCurrentDir()
type type
CircuitEnv* = object CircuitEnv* = object
nimCircuitCli = nimCircuitCli =
@ -41,8 +22,29 @@ type
ncells*: int ncells*: int
index*: int index*: int
proc checkEnv*() = template withDir(dir: string, blk: untyped) =
codexProjDir = setProjDir() let prev = getCurrentDir()
try:
setCurrentDir(dir)
`blk`
finally:
setCurrentDir(prev)
proc findCodexProjectDir(prev = getCurrentDir()): string =
## check that the CWD of script is in the codex parent
if not "codex.nimble".fileExists():
setCurrentDir("..")
if prev == getCurrentDir():
echo "\nERROR: Codex project folder not found (could not find codex.nimble)"
echo "\nBenchmark must be run from within the Codex project folder"
quit 1
setProjDir()
else:
getCurrentDir()
proc checkEnv*(env: CircuitEnv) =
## check that the CWD of script is in the codex parent
codexProjDir = findCodexProjectDir()
echo "\n\nFound project dir: ", codexProjDir echo "\n\nFound project dir: ", codexProjDir
let snarkjs = findExe("snarkjs") let snarkjs = findExe("snarkjs")
@ -187,6 +189,7 @@ proc createCircuit*(
return (circdir, name) return (circdir, name)
when isMainModule: when isMainModule:
## test run creating a circuit
checkEnv() checkEnv()
let args = CircArgs( let args = CircArgs(