warn if "make update" was not executed

and warn if Make's parallelism is not enabled
This commit is contained in:
Ștefan Talpalaru 2020-12-02 22:35:05 +01:00 committed by zah
parent 059d8151c5
commit e2de003ce6
3 changed files with 58 additions and 14 deletions

View File

@ -144,6 +144,18 @@ Link PCRE, defaults to 1.
Internal target that creates the directory with the same name. Internal target that creates the directory with the same name.
### sanity-checks
Internal target used to check that a C compiler is installed.
### warn-update
Internal target that checks if `make update` was executed for the current Git commit.
### warn-jobs
Internal target that checks if Make's parallelism was enabled by specifying the number of jobs.
### deps-common ### deps-common
Internal target that needs to be a dependency for a custom "deps" target which, Internal target that needs to be a dependency for a custom "deps" target which,

View File

@ -7,6 +7,8 @@
.PHONY: \ .PHONY: \
sanity-checks \ sanity-checks \
warn-update \
warn-jobs \
deps-common \ deps-common \
build-nim \ build-nim \
update-common \ update-common \
@ -36,9 +38,24 @@ build:
sanity-checks: sanity-checks:
which $(CC) &>/dev/null || { echo "C compiler ($(CC)) not installed. Aborting."; exit 1; } which $(CC) &>/dev/null || { echo "C compiler ($(CC)) not installed. Aborting."; exit 1; }
#- runs only the first time and after `make update`, so have "normal" #- check if "make update" was executed
# (timestamp-checked) prerequisites here warn-update:
deps-common: sanity-checks $(NIMBLE_DIR) if [[ -e $(UPDATE_TIMESTAMP) ]]; then \
if [[ $$(cat $(UPDATE_TIMESTAMP)) -ne $$($(GET_CURRENT_COMMIT_TIMESTAMP)) ]]; then \
echo -e "\n\"$$(basename "$(MAKE)") update\" was not executed for the current Git commit! The resulting build is unsupported.\n"; \
fi; \
fi
#- check if we're enabling multiple jobs - https://stackoverflow.com/a/48865939
warn-jobs:
+ if [[ ! "${MAKEFLAGS}" =~ --jobserver[^=]+= ]]; then \
NPROC=$$($(NPROC_CMD)); \
if [[ $${NPROC} -gt 1 ]]; then \
echo -e "\nTip of the day: this will probably build faster if you use \"$$(basename "$(MAKE)") -j$${NPROC} ...\".\n"; \
fi; \
fi
deps-common: | sanity-checks warn-update warn-jobs $(NIMBLE_DIR)
# - don't build our Nim target if it's not going to be used # - don't build our Nim target if it's not going to be used
ifeq ($(USE_SYSTEM_NIM), 0) ifeq ($(USE_SYSTEM_NIM), 0)
deps-common: $(NIM_BINARY) deps-common: $(NIM_BINARY)
@ -66,6 +83,7 @@ build-nim: | sanity-checks
#- initialises and updates the Git submodules #- initialises and updates the Git submodules
#- hard-resets the working copies of submodules #- hard-resets the working copies of submodules
#- deletes "nimcache" directories #- deletes "nimcache" directories
#- updates ".update.timestamp"
#- deletes the ".nimble" dir and executes the "deps" target #- deletes the ".nimble" dir and executes the "deps" target
#- allows parallel building with the '+' prefix #- allows parallel building with the '+' prefix
#- rebuilds the Nim compiler if the corresponding submodule is updated #- rebuilds the Nim compiler if the corresponding submodule is updated
@ -77,6 +95,7 @@ update-common: | sanity-checks
git submodule update --init --recursive git submodule update --init --recursive
git submodule foreach --quiet --recursive 'git reset --quiet --hard' git submodule foreach --quiet --recursive 'git reset --quiet --hard'
find . -type d -name nimcache -print0 | xargs -0 rm -rf find . -type d -name nimcache -print0 | xargs -0 rm -rf
$(GET_CURRENT_COMMIT_TIMESTAMP) > $(UPDATE_TIMESTAMP)
rm -rf $(NIMBLE_DIR) rm -rf $(NIMBLE_DIR)
+ "$(MAKE)" --no-print-directory deps + "$(MAKE)" --no-print-directory deps
ifeq ($(USE_SYSTEM_NIM), 0) ifeq ($(USE_SYSTEM_NIM), 0)

View File

@ -66,33 +66,46 @@ GIT_STATUS := git status
#- duplicated in "env.sh" for the env var with the same name #- duplicated in "env.sh" for the env var with the same name
NIMBLE_DIR := vendor/.nimble NIMBLE_DIR := vendor/.nimble
REPOS_DIR := vendor REPOS_DIR := vendor
ifeq ($(OS), Windows_NT) ifeq ($(OS), Windows_NT)
PWD := pwd -W PWD := pwd -W
EXE_SUFFIX := .exe
# available since Git 2.9.4
GIT_TIMESTAMP_ARG := --date=unix
else else
PWD := pwd PWD := pwd
EXE_SUFFIX :=
# available since Git 2.7.0
GIT_TIMESTAMP_ARG := --date=format-local:%s
endif endif
ifeq ($(shell uname), Darwin)
# md5sum - macOS is a special case
MD5SUM := md5 -r
NPROC_CMD := sysctl -n hw.logicalcpu
else
MD5SUM := md5sum
NPROC_CMD := nproc
endif
GET_CURRENT_COMMIT_TIMESTAMP := git log --pretty=format:%cd -n 1 $(GIT_TIMESTAMP_ARG)
UPDATE_TIMESTAMP := .update.timestamp
ifeq ($(BUILD_SYSTEM_DIR),) ifeq ($(BUILD_SYSTEM_DIR),)
$(error You need to define BUILD_SYSTEM_DIR before including this file) $(error You need to define BUILD_SYSTEM_DIR before including this file)
endif endif
# we want a "recursively expanded" (delayed interpolation) variable here, so we can set CMD in rule recipes # we want a "recursively expanded" (delayed interpolation) variable here, so we can set CMD in rule recipes
RUN_CMD_IN_ALL_REPOS = git submodule foreach --recursive --quiet 'echo -e "\n\e[32m$$name:\e[39m"; $(CMD)'; echo -e "\n\e[32m$$($(PWD)):\e[39m"; $(CMD) RUN_CMD_IN_ALL_REPOS = git submodule foreach --recursive --quiet 'echo -e "\n\e[32m$$name:\e[39m"; $(CMD)'; echo -e "\n\e[32m$$($(PWD)):\e[39m"; $(CMD)
# absolute path, since it will be run at various subdirectory depths # absolute path, since it will be run at various subdirectory depths
ENV_SCRIPT := "$(CURDIR)/$(BUILD_SYSTEM_DIR)/scripts/env.sh" ENV_SCRIPT := "$(CURDIR)/$(BUILD_SYSTEM_DIR)/scripts/env.sh"
# duplicated in "env.sh" to prepend NIM_DIR/bin to PATH # duplicated in "env.sh" to prepend NIM_DIR/bin to PATH
NIM_DIR := $(BUILD_SYSTEM_DIR)/vendor/Nim NIM_DIR := $(BUILD_SYSTEM_DIR)/vendor/Nim
ifeq ($(OS), Windows_NT)
EXE_SUFFIX := .exe
else
EXE_SUFFIX :=
endif
NIM_BINARY := $(NIM_DIR)/bin/nim$(EXE_SUFFIX) NIM_BINARY := $(NIM_DIR)/bin/nim$(EXE_SUFFIX)
# md5sum - macOS is a special case
ifeq ($(shell uname), Darwin)
MD5SUM := md5 -r
else
MD5SUM := md5sum
endif
# AppVeyor/Travis cache of $(NIM_DIR)/bin # AppVeyor/Travis cache of $(NIM_DIR)/bin
CI_CACHE := CI_CACHE :=