use "nim" instead of "nimble" to run *.nimble tasks

This commit is contained in:
Ștefan Talpalaru 2019-02-15 03:11:20 +01:00 committed by zah
parent 16f9183dc9
commit 44a88bbf4c
4 changed files with 56 additions and 14 deletions

View File

@ -72,11 +72,9 @@ premix persist debug dumper hunter: | build deps
$(ENV_SCRIPT) nim c -o:build/$@ premix/$@.nim && \
echo -e "\nThe binary is in './build/$@'.\n"
#- "--nimbleDir" is ignored for custom tasks: https://github.com/nim-lang/nimble/issues/495
# so we can't run `nimble ... nimbus` or `nimble ... test`. We have to duplicate those custom tasks here.
#- a phony target, because teaching `make` how to do conditional recompilation of Nim projects is too complicated
nimbus: | build deps
$(ENV_SCRIPT) nim c -o:build/nimbus nimbus/nimbus.nim && \
./nimble.sh nimbus && \
echo -e "\nThe binary is in './build/nimbus'.\n"
# dir
@ -102,7 +100,7 @@ $(NIMBLE_DIR): | $(NIM_DIR)/bin/nim
# builds and runs all tests
test: | build deps
$(ENV_SCRIPT) nim c -r -d:chronicles_log_level=ERROR -o:build/all_tests tests/all_tests.nim
./nimble.sh test
# usual cleaning
clean:

View File

@ -154,6 +154,15 @@ git checkout <commit hash here>
make -j8 clean update
```
Running a dependency's test suite using `nim` instead of `nimble` (which cannot be
convinced not to run a dependency check, thus clashing with our jury-rigged
"vendor/.nimble/pkgs"):
```bash
cd vendor/nim-blscurve
../../nimble.sh test
```
### Troubleshooting
Report any errors you encounter, please, if not [already documented](https://github.com/status-im/nimbus/issues)!

31
nimble.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
######################################################
# run *.nimble tasks using "nim" instead of "nimble" #
######################################################
# exit on command error
set -e
[ -z "$1" ] && { echo "usage: $0 task_name"; exit 1; }
F=""
for F in *.nimble; do
# get the first one
break
done
[ -z "$F" ] && { echo "No *.nimble file found."; exit 1; }
# "nim" seems to only run custom NimScript files if they have a "nims" extension
NIMS="${F%.nimble}.nims"
ln -s "$F" "$NIMS"
# delete the temporary symlink on script exit
cleanup() {
rm -rf "$NIMS"
}
trap cleanup EXIT
# can't have an "exec" here or the EXIT pseudo-signal won't be triggered
$(dirname $0)/env.sh nim "$1" "$NIMS"

View File

@ -25,22 +25,26 @@ proc buildBinary(name: string, srcDir = ".", lang = "c") =
setCommand lang, srcDir & name & ".nim"
proc test(name: string, lang = "c") =
--define:"chronicles_log_level=ERROR"
switch("define", "chronicles_log_level=ERROR")
--run
buildBinary name, "tests/"
task test, "Run tests":
test "all_tests"
# debugging tools don't yet have tests
# but they should be compilable
exec "nim c -r tests/test_rpc"
exec "nim c premix/premix"
exec "nim c premix/persist"
exec "nim c premix/debug"
exec "nim c premix/dumper"
exec "nim c premix/hunter"
exec "nim c tests/tracerTestGen"
exec "nim c tests/persistBlockTestGen"
for binary in [
"premix/premix",
"premix/persist",
"premix/debug",
"premix/dumper",
"premix/hunter",
"tests/tracerTestGen",
"tests/persistBlockTestGen",
]:
exec "nim c --verbosity:0 --hints:off --warnings:off " & binary
rmFile binary
# executed last, no matter where you place it, because of "setCommand"
test "all_tests"
task nimbus, "Build Nimbus":
buildBinary "nimbus", "nimbus/"