blob: cdf14d546089d5c37e5a5f7af5c9ebb3c53e2a4d [file] [log] [blame]
#
# 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, 10)}')
MOD_VERSION := $(shell awk '/^go/ {print $$2}' go.mod)
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
API_LIB := $(LIB_DIR)/api
INTERFACE_GO := $(API_LIB)/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_GO).tmp: $(SI_SPEC)
test -d $(COMMON_LIB) || mkdir -p $(COMMON_LIB)
@echo "$$GENERATED_HEADER" > $@
@echo "$$PACKAGE_DEF" >> $@
cat $< | sed -n -e '/``constants$$/,/^```$$/ p' | sed '/^```/d' >> $@
(diff $@ $(CONSTANTS_GO) > /dev/null 2>&1 || mv -f $@ $(CONSTANTS_GO)) && \
rm -f $@
$(INTERFACE_GO).tmp: $(SI_SPEC)
test -d $(API_LIB) || mkdir -p $(API_LIB)
@echo "$$GENERATED_HEADER" > $@
cat $< | sed -n -e '/``golang$$/,/^```$$/ p' | sed '/^```/d' >> $@
(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_GO).tmp $(INTERFACE_GO).tmp
$(MAKE) -C $(LIB_DIR)
# Set a empty recipe
.PHONY: test
test:
@echo ""
# Check for missing license headers
.PHONY: license-check
license-check:
@echo "checking license header"
@licRes=$$(grep -Lr --exclude-dir=lib --include=*.{go,sh,md,yaml,mod} "Licensed to the Apache Software Foundation" .) ; \
if [ -n "$${licRes}" ]; then \
echo "following files have incorrect license header:\n$${licRes}" ; \
exit 1; \
fi
# Simple clean of generated files only (no local cleanup).
.PHONY: clean
clean:
rm -rf $(COMMON_LIB)
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:
cd $(BASE_DIR) && \
$(MAKE) -C $(LIB_DIR) $@