From 2d6a8b8ed1135387fc21a46c7d9a2c6cab738911 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera <kubuxu@protonmail.ch> Date: Fri, 16 Dec 2016 19:04:22 +0100 Subject: [PATCH] make: rework makefiles for non-recursive make and add sharness coverage This commit introduces non-recursive Makefile infrastructure that replaces current Makefile infrastructure. It also generally cleanups the Makefiles, separates them into nicer sub-modules and centralizes common operations into single definitions. It allows to depend on any target that is defined in the makefile, this means that for example `gx install` is called once when `make build test_expensive_sharness` is called instead of 4 or 5 times. It also makes the dependencies much cleaner and allows for reuse of modules. For example sharness coverage collection (WIP) uses sharness target with amended PATH, previously it might have been possible but not without wiring in the coverage collection into sharness make runner code. Yes, it is more complex but not much more. There are few rules that have to be followed and few complexities added but IMHO it is worth it. How to NR-make: 1. If make is to generate some file via a target, it MUST be defined in Rules.mk file in the directory of the target. 2. `Rules.mk` file MUST have `include mk/header.mk` statement as the first line and `include mk/footer.mk` statement as the last line (apart from project root `Rules.mk`). 3. It then MUST be included by the closest `Rules.mk` file up the directory tree. 4. Inside a `Rules.mk` special variable accessed as `$(d)` is defined. Its value is current directory, use it so if the `Rules.mk` file is moved in the tree it still works without a problem. Caution: this variable is not available in the recipe part and MUST NOT be used. Use name of the target or prerequisite to extract it if you need it. 5. Make has only one global scope, this means that name conflicts are a thing. Names SHOULD follow `VAR_NAME_$(d)` convention. There are exceptions from this rule in form of well defined global variables. Examples: General lists `TGT_BIN`, `CLEAN`; General targets: `TEST`, `COVERAGE`; General variables: `GOFLAGS`, `DEPS_GO`. 3. Any rules, definitions or variables that fit some family SHOULD be defined in `mk/$family.mk` file and included from project root `Rules.mk` License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch> --- internal/pb/Rules.mk | 8 ++++++++ pin.go | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 internal/pb/Rules.mk diff --git a/internal/pb/Rules.mk b/internal/pb/Rules.mk new file mode 100644 index 0000000..505f70e --- /dev/null +++ b/internal/pb/Rules.mk @@ -0,0 +1,8 @@ +include mk/header.mk + +PB_$(d) = $(wildcard $(d)/*.proto) +TGTS_$(d) = $(PB_$(d):.proto=.pb.go) + +#DEPS_GO += $(TGTS_$(d)) + +include mk/footer.mk diff --git a/pin.go b/pin.go index baf0d59..c0eccc2 100644 --- a/pin.go +++ b/pin.go @@ -5,7 +5,6 @@ package pin import ( "context" "fmt" - "os" "sync" "time" @@ -26,8 +25,9 @@ var emptyKey *cid.Cid func init() { e, err := cid.Decode("QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n") if err != nil { - log.Error("failed to decode empty key constant") - os.Exit(1) + msg := "failed to decode empty key constant" + log.Error(msg) + panic(msg) } emptyKey = e } -- GitLab