add go-bindata bazel

This commit is contained in:
Benjamin Elder
2018-08-06 11:23:29 -07:00
parent 05e273f7d6
commit e82fe2d4e5
5 changed files with 151 additions and 1 deletions

13
hack/BUILD.bazel 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"],
)

74
hack/bindata.bzl Normal file
View File

@@ -0,0 +1,74 @@
# 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.
# forked from https://github.com/kubernetes/kubernetes/blob/master/build/bindata.bzl
# this variant only supports once source dir
# IMPORTANT: Any changes to this rule may also require changes to hack/generate.sh.
def go_bindata(
# these are for bazel
name,
srcs,
outs,
# -prefix flag
prefix,
# the sources to pass to go-bindata
# NOTE: these must be contained in srcs or bazel will not populate them
bindata_srcs,
# label for the file containing the go:generate directive, so we can
# run go-bindata from the containing package / directory
generate_directive_file,
# -mode flag
mode = "0666",
# -nometadata flag
include_metadata = True,
# -pkg flag
pkg = "generated",
# -ignore flag
ignores = [],
**kw):
args = ['-pkg', pkg]
if not include_metadata:
args.append("-nometadata")
if mode:
args.append("-mode=%s" % mode)
for ignore in ignores:
args.extend(["-ignore", "'%s'" % ignore])
if prefix:
args.append("-prefix=%s" % prefix)
native.genrule(
name = name,
srcs = srcs,
outs = outs,
cmd = " ".join([
# save the original working directory (repo root)
# all paths will be relative to this
"ORIG_WD=$$(pwd);",
# cd to the directory containing the go:generate directive,
# since this is what go generate would do
"cd $$(dirname $(location %s));" % (generate_directive_file),
# run go-bindata
"$$ORIG_WD/$(location %s) -o $$ORIG_WD/$@ %s %s" % (
"//vendor/github.com/jteeuwen/go-bindata/go-bindata:go-bindata",
" ".join(args),
bindata_srcs,
),
]),
tools = [
"//vendor/github.com/jteeuwen/go-bindata/go-bindata",
generate_directive_file,
],
**kw
)

16
images/node/BUILD.bazel Normal file
View File

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

View File

@@ -17,7 +17,10 @@ filegroup(
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
srcs = [
":package-srcs",
"//kind/pkg/build/sources:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,44 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("//kind/hack:bindata.bzl", "go_bindata")
# IMPORTANT: if you make any cahnges here, you must also update hack/generate.sh
go_bindata(
name = "bindata",
srcs = [
"//kind/images/node:all-srcs",
],
outs = [
"images_node_sources.go",
],
bindata_srcs = "./../../../images/node/...",
generate_directive_file = "generate.go",
ignores = ["(\.*README\.md)|(\.*BUILD\.bazel)"],
include_metadata = False,
mode = "0666",
pkg = "sources",
prefix = "./../../../",
)
go_library(
name = "go_default_library",
srcs = [
"generate.go",
"images_node_sources.go",
],
importpath = "k8s.io/test-infra/kind/pkg/build/sources",
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)