build pkged.go directly with make (#841)

Also removes the dependency on a modern bash when building on a stock OS
X box (which ships with a 15-year old version).
This commit is contained in:
Luke Kingland 2022-02-22 04:06:03 +09:00 committed by GitHub
parent f25724ad71
commit 64091fbc39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 40 deletions

View File

@ -22,12 +22,6 @@ VTAG := $(shell [ -z $(VTAG) ] && echo $(ETAG) || echo $(VTAG))
VERS ?= $(shell [ -z $(VTAG) ] && echo 'tip' || echo $(VTAG) )
LDFLAGS := "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)"
# Templates
# Built into the binary are the contents of ./templates. This is done by
# running 'pkger' which generates pkged.go containing templates encoded
# as Go objects and exposed at runtime as a filesystem.
PKGER ?= ./hack/update-pkger.sh
# All Code prerequisites, including generated files, etc.
CODE := $(shell find . -name '*.go') pkged.go go.mod schema/func_yaml-schema.json
TEMPLATES := $(shell find templates -name '*' -type f)
@ -65,6 +59,7 @@ bin/golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin v1.43.0
pkged.go: $(TEMPLATES)
# Removing temporary template files
@rm -rf templates/node/cloudevents/node_modules
@rm -rf templates/node/http/node_modules
@rm -rf templates/python/cloudevents/__pycache__
@ -77,8 +72,15 @@ pkged.go: $(TEMPLATES)
@rm -rf templates/quarkus/http/target
@rm -rf templates/springboot/cloudevents/target
@rm -rf templates/springboot/http/target
# Generating pkged.go using pkger
$(PKGER)
# Encoding ./templates as pkged.go
# See ./hack/tools.go which triggers the vendoring of pkger cmd
# The temp file ./hack/package.go averts a "no buildable files" error
# gofmt updates the resultant pkged.go file to the new build tag f ormat.
@echo "package tools" > hack/package.go
@go run ./vendor/github.com/markbates/pkger/cmd/pkger
@rm hack/package.go
@gofmt -s -w pkged.go
clean: ## Remove generated artifacts such as binaries and schemas
rm -f $(BIN) $(BIN_WINDOWS) $(BIN_LINUX) $(BIN_DARWIN)

View File

@ -1,32 +0,0 @@
#!/usr/bin/env bash
# Copyright 2021 The Knative Authors
#
# Licensed 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.
set -o errexit
set -o nounset
set -o pipefail
source $(dirname $0)/../vendor/knative.dev/hack/library.sh
# Hack: touch a non-tagged file so that pkger doesn't complain
echo -e "package tools" > "$REPO_ROOT_DIR/hack/package.go"
go run ./vendor/github.com/markbates/pkger/cmd/pkger
# Hack: remove touched file.
rm "$REPO_ROOT_DIR/hack/package.go"
# Ensure pkged.go is migrated
gofmt -s -w pkged.go