Merge pull request #62432 from ixdy/pkg-generated-bindata

Automatic merge from submit-queue (batch tested with PRs 62432, 62868, 63040). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

bazel: generate pkg/generated/bindata.go at build time and remove from repo

**What this PR does / why we need it**: `pkg/generated/bindata.go` is a generated file, and it's one that's easy for us to handle in bazel (we already handle `test/e2e/generated/bindata.go`, for example).

The translations also have an additional generation step (`hack/update-translations.sh`) which I'm not handling here, but this enables us to remove the `bindata.go` files from the tree (when combined with #62151).

**Release note**:

```release-note
NONE
```

/assign @rmmh @cblecker @thockin @fejta
This commit is contained in:
Kubernetes Submit Queue 2018-04-25 12:56:08 -07:00 committed by GitHub
commit e63cf9a4d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 87 additions and 19502 deletions

2
.gitignore vendored
View File

@ -114,7 +114,9 @@ zz_generated.openapi.go
# make-related metadata
/.make/
# Just in time generated data in the source, should never be committed
/pkg/generated/bindata.go
/test/e2e/generated/bindata.go
# This file used by some vendor repos (e.g. github.com/go-openapi/...) to store secret variables and should not be ignored

45
build/bindata.bzl Normal file
View File

@ -0,0 +1,45 @@
# Copyright 2018 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.
# Genrule wrapper around the go-bindata utility.
# IMPORTANT: Any changes to this rule may also require changes to hack/generate-bindata.sh.
def go_bindata(
name, srcs, outs,
compress=True,
include_metadata=True,
pkg="generated",
ignores=["\.jpg", "\.png", "\.md", "BUILD(\.bazel)?"],
**kw):
args = []
for ignore in ignores:
args.extend(["-ignore", "'%s'" % ignore])
if not include_metadata:
args.append("-nometadata")
if not compress:
args.append("-nocompress")
native.genrule(
name = name,
srcs = srcs,
outs = outs,
cmd = """
$(location //vendor/github.com/jteeuwen/go-bindata/go-bindata:go-bindata) \
-o "$@" -pkg %s -prefix $$(pwd) %s $(SRCS)
""" % (pkg, " ".join(args)),
tools = [
"//vendor/github.com/jteeuwen/go-bindata/go-bindata",
],
**kw
)

View File

@ -70,6 +70,7 @@ filegroup(
"//staging:all-srcs",
"//test:all-srcs",
"//third_party:all-srcs",
"//translations:all-srcs",
"//vendor:all-srcs",
],
tags = ["automanaged"],

View File

@ -41,8 +41,10 @@ pushd "${KUBE_ROOT}" >/dev/null
# These are files for e2e tests.
BINDATA_OUTPUT="test/e2e/generated/bindata.go"
# IMPORTANT: if you make any changes to these arguments, you must also update
# test/e2e/generated/BUILD and/or build/bindata.bzl.
go-bindata -nometadata -o "${BINDATA_OUTPUT}.tmp" -pkg generated \
-ignore .jpg -ignore .png -ignore .md \
-ignore .jpg -ignore .png -ignore .md -ignore 'BUILD(\.bazel)?' \
"test/e2e/testing-manifests/..." \
"test/images/..." \
"test/fixtures/..."
@ -63,8 +65,10 @@ rm -f "${BINDATA_OUTPUT}.tmp"
# These are files for runtime code
BINDATA_OUTPUT="pkg/generated/bindata.go"
# IMPORTANT: if you make any changes to these arguments, you must also update
# pkg/generated/BUILD and/or build/bindata.bzl.
go-bindata -nometadata -nocompress -o "${BINDATA_OUTPUT}.tmp" -pkg generated \
-ignore .jpg -ignore .png -ignore .md \
-ignore .jpg -ignore .png -ignore .md -ignore 'BUILD(\.bazel)?' \
"translations/..."
gofmt -s -w "${BINDATA_OUTPUT}.tmp"

View File

@ -25,6 +25,7 @@ CLEAN_PATTERNS=(
"_tmp"
"doc_tmp"
".*/zz_generated.openapi.go"
"pkg/generated/bindata.go"
"test/e2e/generated/bindata.go"
)

View File

@ -4,6 +4,18 @@ load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
load("//build:bindata.bzl", "go_bindata")
# IMPORTANT: if you make any changes here, you must also update hack/generate-bindata.sh.
go_bindata(
name = "bindata",
srcs = [
"//translations:all-srcs",
],
outs = ["bindata.go"],
compress = False,
include_metadata = False,
)
go_library(
name = "go_default_library",

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@ load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
load("//build:bindata.bzl", "go_bindata")
go_library(
name = "go_default_library",
@ -18,24 +19,17 @@ go_library(
],
)
genrule(
# IMPORTANT: if you make any changes here, you must also update hack/generate-bindata.sh.
go_bindata(
name = "bindata",
srcs = [
"//test/images:all-srcs",
"//test/fixtures:all-srcs",
"//test/e2e/testing-manifests:all-srcs",
"//test/fixtures:all-srcs",
"//test/images:all-srcs",
],
outs = ["bindata.go"],
cmd = """
$(location //vendor/github.com/jteeuwen/go-bindata/go-bindata:go-bindata) \
-nometadata -o "$(OUTS)" -pkg generated \
-prefix $$(pwd) \
-ignore .jpg -ignore .png -ignore .md \
$(SRCS)
""",
tools = [
"//vendor/github.com/jteeuwen/go-bindata/go-bindata",
],
compress = True,
include_metadata = False,
)
filegroup(

13
translations/BUILD Normal file
View File

@ -0,0 +1,13 @@
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)