From da79a7e996b79099c4dbd73d145ae510a8f046f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Sat, 16 Feb 2019 22:23:17 +0100 Subject: [PATCH] very simple reproducibility test Additional changes: - Makefile verbosity control - nimble.sh can now run in parallel on the same *.nimble file - nimble.sh no longer used in the Makefile, in favour of a nimbus.nims symlink that eliminates race risks in parallel jobs - nimbus.nimble takes extra params in the command line, with the caveat that they also apply to nim - setCommand() replaced with exec(), to avoid splitting param strings --- .appveyor.yml | 4 ++-- .travis.yml | 4 ++-- Makefile | 23 +++++++++++++++++++---- README.md | 7 +++++++ env.sh | 1 + nimble.sh | 6 ++---- nimbus.nimble | 20 ++++++++++---------- nimbus.nims | 1 + 8 files changed, 44 insertions(+), 22 deletions(-) create mode 120000 nimbus.nims diff --git a/.appveyor.yml b/.appveyor.yml index 482890543..acbae6a59 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -25,11 +25,11 @@ build_script: - git submodule update --init --recursive --depth 10 # the 32-bit build is done on a 64-bit image, so we need to override the architecture - mingw32-make ARCH_OVERRIDE=%PLATFORM% fetch-dlls - - mingw32-make -j2 ARCH_OVERRIDE=%PLATFORM% nimbus + - mingw32-make -j2 ARCH_OVERRIDE=%PLATFORM% V=0 nimbus test_script: - build\nimbus.exe --help - - mingw32-make -j2 ARCH_OVERRIDE=%PLATFORM% test + - mingw32-make -j2 ARCH_OVERRIDE=%PLATFORM% V=0 test test-reproducibility deploy: off diff --git a/.travis.yml b/.travis.yml index 311dda19a..4fabacafc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ install: script: - set -e # fail fast - - make -j${NPROC} nimbus + - make -j${NPROC} V=0 nimbus - ./build/nimbus --help - - make -j${NPROC} test + - make -j${NPROC} V=0 test test-reproducibility diff --git a/Makefile b/Makefile index 6f25b7544..0c129b008 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,12 @@ BUILD_NIM := cd $(NIM_DIR) && \ } && \ sh build_all.sh NIM_BINARY := $(NIM_DIR)/bin/nim$(EXE_SUFFIX) +# verbosity level +V := 1 +NIM_PARAMS := --verbosity:$(V) +ifeq ($(V), 0) + NIM_PARAMS := $(NIM_PARAMS) --hints:off --warnings:off +endif OpenSystemsLab/tempfile.nim \ status-im/nim-eth \ @@ -77,12 +83,12 @@ all: premix persist debug dumper hunter nimbus # debugging tools premix persist debug dumper hunter: | build deps - $(ENV_SCRIPT) nim c -o:build/$@ premix/$@.nim && \ + $(ENV_SCRIPT) nim c $(NIM_PARAMS) -o:build/$@ premix/$@.nim && \ echo -e "\nThe binary is in './build/$@'.\n" #- a phony target, because teaching `make` how to do conditional recompilation of Nim projects is too complicated nimbus: | build deps - ./nimble.sh nimbus && \ + $(ENV_SCRIPT) nim nimbus $(NIM_PARAMS) nimbus.nims && \ echo -e "\nThe binary is in './build/nimbus'.\n" # dir @@ -108,7 +114,16 @@ $(NIMBLE_DIR): | $(NIM_BINARY) # builds and runs all tests test: | build deps - ./nimble.sh test + $(ENV_SCRIPT) nim test $(NIM_PARAMS) nimbus.nims + +# primitive reproducibility test +test-reproducibility: + + [ -e build/nimbus ] || $(MAKE) V=0 nimbus; \ + MD5SUM1=$$(md5sum build/nimbus | cut -d ' ' -f 1); \ + $(MAKE) V=0 nimbus; \ + MD5SUM2=$$(md5sum build/nimbus | cut -d ' ' -f 1); \ + [ "$$MD5SUM1" = "$$MD5SUM2" ] && echo "Success: identical binaries." || \ + { echo "Failure: the binary changed between builds."; exit 1; } # usual cleaning clean: @@ -154,7 +169,7 @@ ntags: #- actually binaries, but have them as phony targets to force rebuilds beacon_node validator_keygen: | build deps - $(ENV_SCRIPT) nim c -o:build/$@ $(REPOS_DIR)/nim-beacon-chain/beacon_chain/$@.nim + $(ENV_SCRIPT) nim c $(NIM_PARAMS) -o:build/$@ $(REPOS_DIR)/nim-beacon-chain/beacon_chain/$@.nim clean_eth2_network_simulation_files: rm -rf $(REPOS_DIR)/nim-beacon-chain/tests/simulation/data diff --git a/README.md b/README.md index 8aed663c7..d469c5a6a 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,13 @@ You can now follow those instructions in the previous section by replacing `make - the Premix debugging tools are [documented separately](premix/readme.md) +- you can control the Makefile's verbosity with the V variable (defaults to 1): + +```bash +make V=0 # quiet +make V=2 test # more verbose than usual +``` + #### Git submodule workflow Working on a dependency: diff --git a/env.sh b/env.sh index d38b001fb..decf85096 100755 --- a/env.sh +++ b/env.sh @@ -13,3 +13,4 @@ export NIMBLE_DIR="${abs_path}/vendor/.nimble" export BUILD_OUTPUTS_DIR="${abs_path}/build" exec "$@" + diff --git a/nimble.sh b/nimble.sh index e8980129f..4e3717d58 100755 --- a/nimble.sh +++ b/nimble.sh @@ -18,14 +18,12 @@ done # "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 +[ -e "$NIMS" ] || { ln -s "$F" "$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" +$(dirname $0)/env.sh nim "$@" "$NIMS" diff --git a/nimbus.nimble b/nimbus.nimble index 87751b843..60464dcb6 100644 --- a/nimbus.nimble +++ b/nimbus.nimble @@ -19,19 +19,20 @@ requires "nim >= 0.19", "eth", "std_shims" -proc buildBinary(name: string, srcDir = ".", lang = "c") = - if not dirExists "build": mkDir "build" - switch("out", ("./build/" & name)) - setCommand lang, srcDir & name & ".nim" +proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") = + if not dirExists "build": + mkDir "build" + # allow something like "nim nimbus --verbosity:0 --hints:off nimbus.nims" + var extra_params = params + for i in 2..