diff --git a/Makefile b/Makefile index edfbc3f1b1..3b319efc0a 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,9 @@ DOCKER_CLI_IMAGE := gcr.io/cloud-builders/docker:20.10.14 # Directory containing installed go binaries. BIN_DIR := $(GO_DIR)/bin +# Vendered. Use "go get github.com/google/go-licenses" to update. +GO_LICENSES := $(BIN_DIR)/go-licenses + ADDLICENSE_VERSION := v1.1.1 ADDLICENSE := $(BIN_DIR)/addlicense @@ -355,8 +358,21 @@ lint-bash: @./scripts/lint-bash.sh .PHONY: lint-license -lint-license: buildenv-dirs - ./scripts/lint-license.sh +# Lints licenses for all packages, even ones just for testing. +lint-license: "$(GO_LICENSES)" + @echo "\"$(GO_LICENSES)\" check \$$(go list all)" + @"$(GO_LICENSES)" check $(shell go list all) + +"$(GO_LICENSES)": buildenv-dirs + GOPATH="$(GO_DIR)" go install github.com/google/go-licenses + +.PHONY: install-go-licenses +# install go-licenses (user-friendly target alias) +install-go-licenses: "$(GO_LICENSES)" + +.PHONY: clean-go-licenses +clean-go-licenses: + @rm -rf $(GO_LICENSES) "$(ADDLICENSE)": buildenv-dirs GOPATH="$(GO_DIR)" go install github.com/google/addlicense@$(ADDLICENSE_VERSION) diff --git a/scripts/lint-license.sh b/scripts/lint-license.sh deleted file mode 100755 index 4d8b93db33..0000000000 --- a/scripts/lint-license.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# Copyright 2022 Google LLC -# -# 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 -euo pipefail - -# Install go-licenses binary from vendored source -go install github.com/google/go-licenses - -chmod -R +rwx .output - -echo "Ensuring dependencies contain approved licenses. This may take up to 3 minutes." -# Lints licenses for all packages, even ones just for testing. -# Faster than evaluating the dependencies of each individual binary by about 3x. -# We want word-splitting here rather than manually looping through the packages one-by-one. -# shellcheck disable=SC2046 -go-licenses check $(go list all)