forked from apache/yunikorn-scheduler-interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
168 lines (147 loc) · 6.04 KB
/
Makefile
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Check if this GO tools version used is at least the version of go specified in
# the go.mod file. The version in go.mod should be in sync with other repos.
GO_VERSION := $(shell go version | awk '{print substr($$3, 3, 4)}')
MOD_VERSION := $(shell cat .go_version)
GM := $(word 1,$(subst ., ,$(GO_VERSION)))
MM := $(word 1,$(subst ., ,$(MOD_VERSION)))
FAIL := $(shell if [ $(GM) -lt $(MM) ]; then echo MAJOR; fi)
ifdef FAIL
$(error Build should be run with at least go $(MOD_VERSION) or later, found $(GO_VERSION))
endif
GM := $(word 2,$(subst ., ,$(GO_VERSION)))
MM := $(word 2,$(subst ., ,$(MOD_VERSION)))
FAIL := $(shell if [ $(GM) -lt $(MM) ]; then echo MINOR; fi)
ifdef FAIL
$(error Build should be run with at least go $(MOD_VERSION) or later, found $(GO_VERSION))
endif
# Retrieve the protobuf version defined in the go module, and download the same version of binary for the build
# This variable will be exported and accessed from lib/go/Makefile
PROTOBUF_VERSION := $(shell go list -m 'google.golang.org/protobuf' | cut -d' ' -f 2)
ifndef PROTOBUF_VERSION
$(error Build requires to set a proper version of google.golang.org/protobuf in go.mod file)
endif
export PROTOBUF_VERSION
# Make sure we are in the same directory as the Makefile
BASE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
SI_SPEC := scheduler-interface-spec.md
SI_PROTO := si.proto
LIB_DIR := lib/go
COMMON_LIB := $(LIB_DIR)/common
CONSTANTS_GO := $(COMMON_LIB)/constants.go
CONSTANTS_TMP := $(COMMON_LIB)/tmp_constants.go
API_LIB := $(LIB_DIR)/api
INTERFACE_GO := $(API_LIB)/interface.go
INTERFACE_TMP := $(API_LIB)/tmp_interface.go
define GENERATED_HEADER
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by make build. DO NOT EDIT
endef
export GENERATED_HEADER
define PACKAGE_DEF
package common
endef
export PACKAGE_DEF
all:
$(MAKE) -C $(dir $(BASE_DIR)) build
# Generate the proto file from the spec, leave proto untouched if there are no changes
$(SI_PROTO).tmp: $(SI_SPEC)
@echo "$$GENERATED_HEADER" > $@
cat $< | sed -n -e '/```protobuf$$/,/^```$$/ p' | sed '/^```/d' >> $@
awk '{ if (length > 200) print NR, $$0 }' $@ | diff - /dev/null
(diff $@ $(SI_PROTO) > /dev/null 2>&1 || mv -f $@ $(SI_PROTO)) && \
rm -f $@
$(CONSTANTS_TMP): $(SI_SPEC)
test -d $(COMMON_LIB) || mkdir -p $(COMMON_LIB)
@echo "$$GENERATED_HEADER" > $@
@echo "$$PACKAGE_DEF" >> $@
cat $< | sed -n -e '/```constants$$/,/^```$$/ p' | sed '/^```/ s/.*//g' >> $@
go fmt $@
(diff $@ $(CONSTANTS_GO) > /dev/null 2>&1 || mv -f $@ $(CONSTANTS_GO)) && \
rm -f $@
$(INTERFACE_TMP): $(SI_SPEC)
test -d $(API_LIB) || mkdir -p $(API_LIB)
@echo "$$GENERATED_HEADER" > $@
cat $< | sed -n -e '/```golang$$/,/^```$$/ p' | sed '/^```/ s/.*//g' >> $@
go fmt $@
(diff $@ $(INTERFACE_GO) > /dev/null 2>&1 || mv -f $@ $(INTERFACE_GO)) && \
rm -f $@
# Build the go language bindings from the spec via a generated proto
build: $(SI_PROTO).tmp $(CONSTANTS_TMP) $(INTERFACE_TMP)
$(MAKE) -C $(LIB_DIR)
# Set a empty recipe
.PHONY: test
test:
@echo ""
# Check that the updates are made in the source file: scheduler-interface.md
# The check is run as part of the pre-commit and a build should not update any files.
.PHONY: check
check: build
@echo "Check for changes by build"
@if ! git diff --quiet; then \
echo "'make build' updated the following files:\n" ; \
git status --untracked-files=no --porcelain ; \
echo "\nUpdates must be made in scheduler-interface.md" ; \
echo "Run 'make build' before committing PR changes" ; \
exit 1; \
fi
@echo " all OK"
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
# Check for missing license headers
.PHONY: license-check
license-check:
@echo "checking license headers:"
ifeq (darwin,$(OS))
$(shell find -E . -not -path "./.git*" -not -path "*lib*" -regex ".*\.(go|sh|md|yaml|yml|mod)" -exec grep -L "Licensed to the Apache Software Foundation" {} \; > LICRES)
else
$(shell find . -not -path "./.git*" -not -path "*lib*" -regex ".*\.\(go\|sh\|md\|yaml\|yml\|mod\)" -exec grep -L "Licensed to the Apache Software Foundation" {} \; > LICRES)
endif
@if [ -s LICRES ]; then \
echo "following files are missing license header:" ; \
cat LICRES ; \
rm -f LICRES ; \
exit 1; \
fi ; \
rm -f LICRES
@echo " all OK"
# Simple clean of generated files only (no local cleanup).
.PHONY: clean
clean:
rm -rf $(CONSTANTS_GO)
rm -rf $(INTERFACE_GO)
cd $(BASE_DIR) && \
$(MAKE) -C $(LIB_DIR) $@
# Remove all non versioned files,
# Running this target will trigger a re-install of protoc etc in te next build cycle.
.PHONY: clobber
clobber: clean
cd $(BASE_DIR) && \
$(MAKE) -C $(LIB_DIR) $@