diff --git a/Makefile.generated_files b/Makefile.generated_files index 5198892fb63..2f61af300ef 100644 --- a/Makefile.generated_files +++ b/Makefile.generated_files @@ -198,11 +198,11 @@ DEEPCOPY_FILES := $(addsuffix /$(DEEPCOPY_FILENAME), $(DEEPCOPY_DIRS)) # in a single run of the tool. .PHONY: gen_deepcopy gen_deepcopy: $(DEEPCOPY_FILES) - if [[ -f $(META_DIR)/$(DEEPCOPY_GEN).todo ]]; then \ - $(DEEPCOPY_GEN) \ + if [[ -f $(META_DIR)/$(DEEPCOPY_GEN).todo ]]; then \ + ./hack/run-in-gopath.sh $(DEEPCOPY_GEN) \ -i $$(cat $(META_DIR)/$(DEEPCOPY_GEN).todo | paste -sd, -) \ - --bounding-dirs $(PRJ_SRC_PATH) \ - -O $(DEEPCOPY_BASENAME); \ + --bounding-dirs $(PRJ_SRC_PATH) \ + -O $(DEEPCOPY_BASENAME); \ fi # For each dir in DEEPCOPY_DIRS, this establishes a dependency between the @@ -243,6 +243,7 @@ $(META_DIR)/$(DEEPCOPY_GEN).mk: -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' \ ./cmd/libs/go2idl/deepcopy-gen \ | grep "^$(PRJ_SRC_PATH)" \ + | sed 's|^$(PRJ_SRC_PATH)|./|' \ | xargs go list -e -f '{{.Dir}} {{.Dir}}/*.go'); \ echo $$DIRECT $$INDIRECT | sed 's/ / =,/g' | tr '=,' '\n\t'; \ ) | sed "s|$$(pwd -P)/||" > $@.tmp; \ @@ -308,10 +309,10 @@ CONVERSION_FILES := $(addsuffix /$(CONVERSION_FILENAME), $(CONVERSION_DIRS)) # in a single run of the tool. .PHONY: gen_conversion gen_conversion: $(CONVERSION_FILES) - if [[ -f $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \ - $(CONVERSION_GEN) \ + if [[ -f $(META_DIR)/$(CONVERSION_GEN).todo ]]; then \ + ./hack/run-in-gopath.sh $(CONVERSION_GEN) \ -i $$(cat $(META_DIR)/$(CONVERSION_GEN).todo | paste -sd, -) \ - -O $(CONVERSION_BASENAME); \ + -O $(CONVERSION_BASENAME); \ fi # Establish a dependency between the deps file and the dir. Whenever a dir @@ -419,6 +420,7 @@ $(META_DIR)/$(CONVERSION_GEN).mk: -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' \ ./cmd/libs/go2idl/conversion-gen \ | grep "^$(PRJ_SRC_PATH)" \ + | sed 's|^$(PRJ_SRC_PATH)|./|' \ | xargs go list -e -f '{{.Dir}} {{.Dir}}/*.go'); \ echo $$DIRECT $$INDIRECT | sed 's/ / =,/g' | tr '=,' '\n\t'; \ ) | sed "s|$$(pwd -P)/||" > $@.tmp; \ diff --git a/hack/run-in-gopath.sh b/hack/run-in-gopath.sh new file mode 100755 index 00000000000..bbd4dd3d156 --- /dev/null +++ b/hack/run-in-gopath.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Copyright 2016 The Kubernetes 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. + +# This script sets up a temporary Kubernetes GOPATH and runs an arbitrary +# command under it. Go tooling requires that the current directory be under +# GOPATH or else it fails to find some things, such as the vendor directory for +# the project. + +set -o errexit +set -o nounset +set -o pipefail + +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/lib/init.sh" + +# This sets up a clean GOPATH and makes sure we are currently in it. +kube::golang::setup_env + +# Run the user-provided command. +"${@}"