Skip to content

Commit

Permalink
simplify output (just bin/ instead of _output/bin), speed up verify-g…
Browse files Browse the repository at this point in the history
…enerated
  • Loading branch information
BenTheElder committed May 9, 2019
1 parent d9f8b03 commit 466b9d6
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# build outputs
# build and test outputs
/bin
/_output
/_artifacts

# used for the code generators
# used for the code generators only
/vendor

# macOS
Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ REPO_ROOT:=${CURDIR}
# autodetect host GOOS and GOARCH by default, even if go is not installed
GOOS=$(shell hack/util/goos.sh)
GOARCH=$(shell hack/util/goarch.sh)
# make install will place binaries here
# the default path attempst to mimic go install
INSTALL_DIR=$(shell hack/util/goinstalldir.sh)
# use the official module proxy by default
GOPROXY=https://proxy.golang.org
Expand All @@ -31,8 +33,8 @@ CACHE_VOLUME=kind-build-cache

# variables for consistent logic, don't override these
CONTAINER_REPO_DIR=/src/kind
CONTAINER_OUT_DIR=$(CONTAINER_REPO_DIR)/_output/bin
HOST_OUT_DIR=$(REPO_ROOT)/_output/bin
CONTAINER_OUT_DIR=$(CONTAINER_REPO_DIR)/bin
OUT_DIR=$(REPO_ROOT)/bin

# standard "make" target -> builds
all: build
Expand All @@ -47,18 +49,19 @@ clean-cache:

# creates the output directory
out-dir:
mkdir -p $(REPO_ROOT)/_output/bin
mkdir -p $(OUT_DIR)

# cleans the output directory
clean-output:
rm -rf $(REPO_ROOT)/_output
rm -rf $(OUT_DIR)/

# builds kind in a container, outputs to $(REPO_ROOT)/_output/bin
# builds kind in a container, outputs to $(OUT_DIR)
kind: make-cache out-dir
docker run \
--rm \
-v $(CACHE_VOLUME):/go \
-e GOCACHE=/go/cache \
-v $(OUT_DIR):/out \
-v $(REPO_ROOT):$(CONTAINER_REPO_DIR) \
-w $(CONTAINER_REPO_DIR) \
-e GO111MODULE=on \
Expand All @@ -67,14 +70,14 @@ kind: make-cache out-dir
-e GOOS=$(GOOS) \
-e GOARCH=$(GOARCH) \
$(GO_IMAGE) \
go build -v -o $(CONTAINER_OUT_DIR)/kind .
go build -v -o /out/kind .

# alias for building kind
build: kind

# use: make install INSTALL_DIR=/usr/local/bin
install: build
cp $(HOST_OUT_DIR)/kind $(INSTALL_DIR)/kind
cp $(OUT_DIR)/kind $(INSTALL_DIR)/kind

# standard cleanup target
clean: clean-cache clean-output
Expand Down
2 changes: 1 addition & 1 deletion hack/build/cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set -o pipefail
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

OUT="${REPO_ROOT}/_output/bin"
OUT="${REPO_ROOT}/bin"
mkdir -p "${OUT}"

CLEAN="false"
Expand Down
2 changes: 1 addition & 1 deletion hack/build/push-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cd "${REPO_ROOT}"

# ensure we have up to date kind
make build
KIND="${REPO_ROOT}/_output/bin/kind"
KIND="${REPO_ROOT}/bin/kind"

# generate tag
DATE="$(date +v%Y%m%d)"
Expand Down
2 changes: 1 addition & 1 deletion hack/build/push-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cd "${REPO_ROOT}"

# ensure we have up to date kind
make build
KIND="${REPO_ROOT}/_output/bin/kind"
KIND="${REPO_ROOT}/bin/kind"

# generate tag
DATE="$(date +v%Y%m%d)"
Expand Down
4 changes: 2 additions & 2 deletions hack/update-generated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -o nounset
set -o errexit
set -o pipefail

REPO_ROOT=$(git rev-parse --show-toplevel)
REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"
cd "${REPO_ROOT}"

# enable modules and the proxy cache
Expand All @@ -27,7 +27,7 @@ GOPROXY="${GOPROXY:-https://proxy.golang.org}"
export GOPROXY

# build the generators
BINDIR="${REPO_ROOT}/_output/bin"
BINDIR="${REPO_ROOT}/bin"
go build -o "${BINDIR}/defaulter-gen" k8s.io/code-generator/cmd/defaulter-gen
go build -o "${BINDIR}/deepcopy-gen" k8s.io/code-generator/cmd/deepcopy-gen
go build -o "${BINDIR}/conversion-gen" k8s.io/code-generator/cmd/conversion-gen
Expand Down
13 changes: 9 additions & 4 deletions hack/verify-generated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cd "${REPO_ROOT}"


# place to stick temp binaries
BINDIR="${REPO_ROOT}/_output/bin"
BINDIR="${REPO_ROOT}/bin"
mkdir -p "${BINDIR}"

# TMP_REPO is used in make_temp_repo_copy
Expand All @@ -38,10 +38,14 @@ cleanup() {

# copies repo into a temp root saved to TMP_REPO
make_temp_repo_copy() {
# we need to copy everything but _output (which is .gitignore anyhow)
# we need to copy everything but bin (and the old _output) (which is .gitignore anyhow)
find . \
-mindepth 1 -maxdepth 1 \
-type d -path "./_output" -prune -o \
\( \
-type d -path "./.git" -o \
-type d -path "./bin" -o \
-type d -path "./_output" \
\) -prune -o \
-exec bash -c 'cp -r "${0}" "${1}/${0}" >/dev/null 2>&1' {} "${TMP_REPO}" \;
}

Expand All @@ -53,11 +57,12 @@ main() {

# run generated code update script
cd "${TMP_REPO}"
hack/update-generated.sh
REPO_ROOT="${TMP_REPO}" hack/update-generated.sh

# make sure the temp repo has no changes relative to the real repo
diff=$(diff -Nupr \
-x ".git" \
-x "bin" \
-x "_output" \
-x "vendor" \
"${REPO_ROOT}" "${TMP_REPO}" 2>/dev/null || true)
Expand Down

0 comments on commit 466b9d6

Please sign in to comment.