-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.in
126 lines (105 loc) · 4.15 KB
/
Makefile.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
MAKEFILE_PATH := $(abspath $(firstword $(MAKEFILE_LIST)))
ROOT_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
SRC_DIR := $(ROOT_DIR)/src
TESTS_DIR := $(ROOT_DIR)/tests
VENDOR_DIR := $(ROOT_DIR)/vendor
PROTO_PATH := $(VENDOR_DIR)/$(PROTO_PACKAGE)
PROTO_FILES := $(foreach var,$(PROTOS),$(PROTO_PATH)/$(var).proto)
PACKAGE_BETTERPROTO := $(PROJECT_ROOT)/_internal
PACKAGE_BETTERPROTO_PATH := $(SRC_DIR)/$(PACKAGE_BETTERPROTO)
PACKAGE_LEGACY := $(PROJECT_ROOT)/_legacy
PACKAGE_LEGACY_PATH := $(SRC_DIR)/$(PACKAGE_LEGACY)
define USAGE
This makefile provides a sugar-coated interface for automation of
development environment tasks/chores and also provides a easy-to-use
interface for ci-jobs.
Usage: make <target>
If you would like see target specific help (where available) use
$ make <target>/help
endef
export USAGE
.PHONY:all
all:
@echo "$$USAGE"
define command_check
@type $(1) > /dev/null 2>&1 || {\
echo 1>&2 "$(1) command not found in \$$PATH"; exit 1;\
}
endef
# custom wrapper to generate python source from gnmi proto files using default python
define protoc-legacy
@echo "Regenerating legacy python code for $(1) ..."
@{\
install -d $(PACKAGE_LEGACY_PATH);\
proto=$(1);\
src="$(PROTO_PATH)/$${proto}.proto";\
dst="$(PACKAGE_LEGACY_PATH)/$${proto}.proto";\
install -D $${src} $${dst};\
touch $$(dirname $${dst}/__init__.py);\
sed -i s+'^option go_package = "$(PROTO_PACKAGE)'+'option go_package = "$(PACKAGE_LEGACY)'+g $${dst};\
sed -i s+'^import "$(PROTO_PACKAGE)'+'import "$(PACKAGE_LEGACY)'+g $${dst};\
poetry run python -m grpc.tools.protoc \
--proto_path="$(SRC_DIR)/" \
--python_out=$(SRC_DIR)/ \
--grpc_python_out=$(SRC_DIR)/ $${dst};\
}
endef
.PHONY: %/help
%/help: HELP_TARGET = $(subst /help,,$@)
%/help:
@make -C $(ROOT_DIR) help | grep -Pzo "\n$(HELP_TARGET)(/\w+)*:.*(\n\s+(.*)?)*\n" \
|| echo >&2 "No help found. You are on your own. All alone. In this big bad world."
### help:
##### displays this help message.
.PHONY: help
help: | all
@grep -P '^\s*###* ' $(MAKEFILE_LIST) | sed s/'\s*### '// | sed s/'#'/' '/g
### debug/show/vars:
##### debug target to list all variables and their values.
.PHONY: debug/show/vars
debug/show/vars:
@echo "===================================================================="
@echo "MAKEFILE_PATH = $(MAKEFILE_PATH)"
@echo "ROOT_DIR = $(ROOT_DIR)"
@echo "SRC_DIR = $(TESTS_DIR)"
@echo "TESTS_DIR = $(TESTS_DIR)"
@echo "VENDOR_DIR = $(VENDOR_DIR)"
@echo "PROJECT_ROOT = $(PROJECT_ROOT)"
@echo "PROTO_PACKAGE = $(PROTO_PACKAGE)"
@echo "PROTOS = $(PROTOS)"
@echo "PACKAGE_BETTERPROTO_PATH = $(PACKAGE_BETTERPROTO_PATH)"
@echo "PACKAGE_LEGACY_PATH = $(PACKAGE_LEGACY_PATH)"
@echo "===================================================================="
### check/commands:
##### Checks if all required commands are available.
.PHONY: check/commands
check/commands:
$(call command_check,poetry)
$(call command_check,git)
### update/vendor
##### updated vendored source
.PHONY: update/vendor
update/vendor: | check/commands
@echo "Updating git submodules ..."
@git submodule update --init --recursive
.PHONY: update/proto/legacy/%
update/proto/legacy/%:
$(call protoc-legacy,$*)
### update/proto/legacy
##### regenerate legacy source from proto files
.PHONY: update/proto/legacy
update/proto/legacy: | $(foreach var,$(PROTOS),update/proto/legacy/$(var))
@:
### update/proto
##### regenerate source from proto files
.PHONY: update/proto
update/proto:
@echo "Regenerating betterproto source ..."
@poetry run python -m grpc.tools.protoc --proto_path="$(VENDOR_DIR):$(ROOT_DIR)" \
--python_betterproto_out=$(PACKAGE_BETTERPROTO_PATH) \
$(PROTO_FILES)
### update
##### update vendored source and regenerate python source
.PHONY: update
update: | update/vendor update/proto update/proto/legacy
@echo "Update completed successfully"