Skip to content

Commit

Permalink
Add some bazel and hack rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fejta committed Aug 21, 2018
1 parent 2f919d7 commit 609570a
Show file tree
Hide file tree
Showing 19 changed files with 668 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test --test_output=errors

4 changes: 4 additions & 0 deletions .kazelcfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"GoPrefix": "k8s.io/org",
"AddSourcesRules": true
}
68 changes: 68 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
load("@io_kubernetes_build//defs:run_in_workspace.bzl", "workspace_binary")

workspace_binary(
name = "dep",
cmd = "//vendor/github.com/golang/dep/cmd/dep",
)

workspace_binary(
name = "golint",
cmd = "//vendor/github.com/golang/lint/golint",
)

load("@bazel_gazelle//:def.bzl", "gazelle")

# gazelle:prefix k8s.io/org
# gazelle:proto disable_global

gazelle(
name = "gazelle",
command = "fix",
external = "vendored",
)

gazelle(
name = "gazelle-diff",
command = "fix",
external = "vendored",
mode = "diff",
)

workspace_binary(
name = "kazel",
cmd = "//vendor/k8s.io/repo-infra/kazel",
)

workspace_binary(
name = "kazel-diff",
args = [
"--dry-run",
"--print-diff",
],
cmd = "//vendor/k8s.io/repo-infra/kazel",
)

filegroup(
name = "package-srcs",
srcs = glob(
["**"],
exclude = [
"bazel-*/**",
".git/**",
],
),
visibility = ["//visibility:private"],
)

filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//admin:all-srcs",
"//cmd/merge:all-srcs",
"//config:all-srcs",
"//vendor:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
35 changes: 35 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
git_repository(
name = "bazel_skylib",
commit = "2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
remote = "https://github.com/bazelbuild/bazel-skylib.git",
)

load("@bazel_skylib//:lib.bzl", "versions")

versions.check(minimum_bazel_version = "0.14.0")

http_archive(
name = "io_bazel_rules_go",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.14.0/rules_go-0.14.0.tar.gz"],
sha256 = "5756a4ad75b3703eb68249d50e23f5d64eaf1593e886b9aa931aa6e938c4e301",
)

http_archive(
name = "bazel_gazelle",
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.14.0/bazel-gazelle-0.14.0.tar.gz"],
sha256 = "c0a5739d12c6d05b6c1ad56f2200cb0b57c5a70e03ebd2f7b87ce88cabf09c7b",
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

go_register_toolchains(go_version = "1.10.2")

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

git_repository(
name = "io_kubernetes_build",
commit = "4ce715fbe67d8fbed05ec2bb47a148e754100a4b",
remote = "https://github.com/kubernetes/repo-infra.git",
)
14 changes: 14 additions & 0 deletions hack/boilerplate/boilerplate.Dockerfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright YEAR 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.

14 changes: 14 additions & 0 deletions hack/boilerplate/boilerplate.Makefile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright YEAR 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.

14 changes: 14 additions & 0 deletions hack/boilerplate/boilerplate.bzl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright YEAR 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.

16 changes: 16 additions & 0 deletions hack/boilerplate/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Copyright YEAR 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.
*/

14 changes: 14 additions & 0 deletions hack/boilerplate/boilerplate.py.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright YEAR 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.

14 changes: 14 additions & 0 deletions hack/boilerplate/boilerplate.sh.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright YEAR 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.

26 changes: 26 additions & 0 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Copyright 2017 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.

set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

cd "$(git rev-parse --show-toplevel)"
for sh in $(ls hack/update* | grep -v update-all); do
"./$sh" && echo "PASS: $sh" && continue
echo "FAIL: $sh"
exit 1
done
24 changes: 24 additions & 0 deletions hack/update-bazel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# 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.

set -o errexit
set -o nounset
set -o pipefail

cd "$(git rev-parse --show-toplevel)"
mkdir -p ./vendor
touch ./vendor/BUILD.bazel
bazel run //:gazelle
bazel run //:kazel
48 changes: 48 additions & 0 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# 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.


# Run dep ensure and generate bazel rules.
#
# Usage:
# update-deps.sh <ARGS>
#
# The args are sent to dep ensure -v <ARGS>

set -o nounset
set -o errexit
set -o pipefail
set -o xtrace

cd "$(git rev-parse --show-toplevel)"
trap 'echo "FAILED" >&2' ERR

# dep itself has a problematic testdata directory with infinite symlinks which
# makes bazel sad: https://github.com/golang/dep/pull/1412
# dep should probably be removing it, but it doesn't:
# https://github.com/golang/dep/issues/1580
rm -rf vendor/github.com/golang/dep/internal/fs/testdata
# go-bindata does too, and is not maintained ...
rm -rf vendor/github.com/jteeuwen/go-bindata/testdata
# docker has a contrib dir with nothing we use in it, dep will retain the licenses
# which includes some GPL, so we manually prune this.
# See https://github.com/kubernetes/steering/issues/57
rm -rf vendor/github.com/docker/docker/contrib
bazel run //:dep -- ensure -v "$@"
rm -rf vendor/github.com/golang/dep/internal/fs/testdata
rm -rf vendor/github.com/jteeuwen/go-bindata/testdata
rm -rf vendor/github.com/docker/docker/contrib
hack/update-bazel.sh
echo SUCCESS
21 changes: 21 additions & 0 deletions hack/update-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Copyright 2017 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.

set -o errexit
set -o nounset
set -o pipefail

find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -w
28 changes: 28 additions & 0 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Copyright 2017 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.

set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

cd "$(git rev-parse --show-toplevel)"
err=0
for sh in $(ls hack/verify* | grep -v verify-all); do
"./$sh" && echo "PASS: $sh" && continue
err=1
echo "FAIL: $sh"
done
exit $err
38 changes: 38 additions & 0 deletions hack/verify-bazel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env 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.

set -o errexit
set -o nounset
set -o pipefail

cd "$(git rev-parse --show-toplevel)"
ls ./vendor/BUILD.bazel >/dev/null
gazelle_diff=$(bazel run //:gazelle-diff)
kazel_diff=$(bazel run //:kazel-diff)

if [[ -n "${gazelle_diff}" ]]; then
echo "Gazelle diff:"
echo "${gazelle_diff}"
fi

if [[ -n "${kazel_diff}" ]]; then
echo "Kazel diff:"
echo "${kazel_diff}"
fi

if [[ -n "${gazelle_diff}${kazel_diff}" ]]; then
echo "FAIL: invalid BUILD.bazel files. Fix with ./hack/update-bazel.sh"
exit 1
fi
Loading

0 comments on commit 609570a

Please sign in to comment.