Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
Gazellify the build (#1367)
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Gazellify the build

`bin/gazelle` should automatically correct `BUILD` files

**Release note**:

```release-note
NONe
```
  • Loading branch information
kyessenov authored and istio-merge-robot committed Oct 9, 2017
1 parent 88aee08 commit 35cbd5d
Show file tree
Hide file tree
Showing 54 changed files with 287 additions and 315 deletions.
4 changes: 3 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"])

load("@io_bazel_rules_go//go:def.bzl", "go_prefix")
load("@io_bazel_rules_go//go:def.bzl", "gazelle", "go_prefix")

go_prefix("istio.io/mixer")

gazelle(name = "gazelle")

filegroup(
name = "generate_word_list",
srcs = ["bin/generate_word_list.py"],
Expand Down
17 changes: 2 additions & 15 deletions adapter/BUILD
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
# gazelle:ignore
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_go//go:def.bzl", "go_library")
load(":inventory.bzl", "inventory_library")

go_library(
name = "go_default_library",
srcs = [
"inventory.go",
],
library = ":inventory_lib", # keep
visibility = ["//visibility:public"],
deps = [
"//adapter/kubernetes:go_default_library",
"//adapter/noopLegacy:go_default_library",
"//pkg/adapter:go_default_library",
],
)

inventory_library(
name = "inventory_lib",
name = "go_default_library",
packages = {
"denier": "istio.io/mixer/adapter/denier",
"list": "istio.io/mixer/adapter/list",
Expand Down
1 change: 0 additions & 1 deletion adapter/denier/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ go_test(
"//template/checknothing:go_default_library",
"//template/listentry:go_default_library",
"//template/quota:go_default_library",
"@com_github_googleapis_googleapis//:google/rpc",
],
)
4 changes: 3 additions & 1 deletion adapter/inventory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ def _inventory_gen(name, packages, out):

DEPS = [
"//pkg/adapter:go_default_library",
"//adapter/kubernetes:go_default_library",
"//adapter/noopLegacy:go_default_library",
]

def inventory_library(name, packages, deps):
_inventory_gen("inventory_file_gen", packages, "inventory.gen.go")

go_library(
name = name,
srcs = ["inventory.gen.go"],
srcs = ["inventory.gen.go", "inventory.go"],
deps = deps + DEPS,
)
1 change: 0 additions & 1 deletion adapter/kubernetes/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ go_library(
"//pkg/adapter:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/labels:go_default_library",
"@io_k8s_apimachinery//pkg/runtime:go_default_library",
"@io_k8s_apimachinery//pkg/watch:go_default_library",
"@io_k8s_client_go//kubernetes:go_default_library",
Expand Down
3 changes: 3 additions & 0 deletions adapter/memquota2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ go_test(
],
library = ":go_default_library",
deps = [
"//adapter/memquota2/config:go_default_library",
"//pkg/adapter:go_default_library",
"//pkg/adapter/test:go_default_library",
"//template/quota:go_default_library",
],
)
6 changes: 1 addition & 5 deletions adapter/noopLegacy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ go_library(
name = "go_default_library",
srcs = ["noop.go"],
visibility = ["//visibility:public"],
deps = [
"//pkg/adapter:go_default_library",
"//pkg/status:go_default_library",
"@com_github_googleapis_googleapis//:google/rpc",
],
deps = ["//pkg/adapter:go_default_library"],
)

go_test(
Expand Down
1 change: 1 addition & 0 deletions adapter/prometheus/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ go_test(
"//adapter/prometheus/config:go_default_library",
"//pkg/adapter:go_default_library",
"//pkg/adapter/test:go_default_library",
"//template/metric:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_model//go:go_default_library",
],
Expand Down
1 change: 1 addition & 0 deletions adapter/stackdriver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go_test(
srcs = ["stackdriver_test.go"],
library = ":go_default_library",
deps = [
"//adapter/stackdriver/config:go_default_library",
"//pkg/adapter:go_default_library",
"//pkg/adapter/test:go_default_library",
"//template/logentry:go_default_library",
Expand Down
4 changes: 4 additions & 0 deletions adapter/stackdriver/log/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ go_test(
"//adapter/stackdriver/config:go_default_library",
"//pkg/adapter/test:go_default_library",
"//template/logentry:go_default_library",
"@com_google_cloud_go//logging:go_default_library",
"@org_golang_google_api//option:go_default_library",
"@org_golang_google_genproto//googleapis/api/monitoredres:go_default_library",
"@org_golang_x_net//context:go_default_library",
],
)
5 changes: 3 additions & 2 deletions adapter/stackdriver/metric/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ go_library(
"@com_github_golang_protobuf//ptypes:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp:go_default_library",
"@com_github_googleapis_gax_go//:go_default_library",
"@com_github_istio_api//:mixer/v1/config/descriptor",
"@com_google_cloud_go//monitoring/apiv3:go_default_library",
"@io_istio_api//:mixer/v1/config/descriptor",
"@org_golang_google_genproto//googleapis/api/distribution:go_default_library",
"@org_golang_google_genproto//googleapis/api/label:go_default_library",
"@org_golang_google_genproto//googleapis/api/metric:go_default_library",
Expand All @@ -45,8 +45,9 @@ go_test(
"@com_github_golang_protobuf//ptypes:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp:go_default_library",
"@com_github_googleapis_gax_go//:go_default_library",
"@com_github_istio_api//:mixer/v1/config/descriptor",
"@com_google_cloud_go//monitoring/apiv3:go_default_library",
"@io_istio_api//:mixer/v1/config/descriptor",
"@org_golang_google_genproto//googleapis/api/distribution:go_default_library",
"@org_golang_google_genproto//googleapis/api/metric:go_default_library",
"@org_golang_google_genproto//googleapis/api/monitoredres:go_default_library",
"@org_golang_google_genproto//googleapis/monitoring/v3:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion adapter/statsd/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ go_test(
"@com_github_cactus_go_statsd_client//statsd:go_default_library",
"@com_github_cactus_go_statsd_client//statsd/statsdtest:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_istio_api//:mixer/v1/config/descriptor",
"@io_istio_api//:mixer/v1/config/descriptor",
],
)
8 changes: 6 additions & 2 deletions adapter/stdio/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ go_test(
srcs = ["stdio_test.go"],
library = ":go_default_library",
deps = [
"//pkg/adapter:go_default_library",
"//adapter/stdio/config:go_default_library",
"//pkg/adapter/test:go_default_library",
"@com_github_istio_api//:mixer/v1/config/descriptor", # keep
"//template/logentry:go_default_library",
"//template/metric:go_default_library",
"@io_istio_api//:mixer/v1/config/descriptor",
"@org_uber_go_zap//:go_default_library",
"@org_uber_go_zap//zapcore:go_default_library",
],
)
5 changes: 1 addition & 4 deletions adapter/svcctrl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ go_library(
"//adapter/svcctrl/config:go_default_library",
"//pkg/adapter:go_default_library",
"//template/metric:go_default_library",
"//template/quota:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
"@com_github_googleapis_googleapis//:google/rpc",
"@com_github_pborman_uuid//:go_default_library",
"@org_golang_google_api//servicecontrol/v1:go_default_library",
"@org_golang_x_net//context:go_default_library",
Expand All @@ -30,7 +27,7 @@ go_test(
srcs = ["svcctrl_test.go"],
library = ":go_default_library",
deps = [
"//template/metric:go_default_library",
"@com_github_davecgh_go_spew//spew:go_default_library",
"@org_golang_google_api//servicecontrol/v1:go_default_library",
],
)
4 changes: 2 additions & 2 deletions bin/bazel_to_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ def tools_generated_files(WKSPC):
makelink(WKSPC + "/bazel-genfiles/tools/codegen/pkg/modelgen/testdata/" + file, WKSPC + "/tools/codegen/pkg/modelgen/testdata/" + file)

def config_proto(WKSPC, genfiles):
if os.path.exists(genfiles + "com_github_istio_api/fixed_cfg.pb.go"):
makelink(genfiles + "com_github_istio_api/fixed_cfg.pb.go", WKSPC + "/pkg/config/proto/fixed_cfg.pb.go")
if os.path.exists(genfiles + "io_istio_api/fixed_cfg.pb.go"):
makelink(genfiles + "io_istio_api/fixed_cfg.pb.go", WKSPC + "/pkg/config/proto/fixed_cfg.pb.go")

def attributes_list(WKSPC, genfiles):
if os.path.exists(WKSPC + "/bazel-genfiles/pkg/attribute/list.gen.go"):
Expand Down
26 changes: 12 additions & 14 deletions bin/gazelle
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

set -ex

if ! type gazelle &> /dev/null ; then
go get github.com/bazelbuild/rules_go/go/tools/gazelle/gazelle
fi

# Force update of gazelle if build_file_name flag is not present.
if ! gazelle --help 2>&1 | grep build_file_name >/dev/null; then
go get -u github.com/bazelbuild/rules_go/go/tools/gazelle/gazelle
fi

# Remove the symbolic link of generated pb.go files and .gen.go files
# to prevent gazelle from creating wrong go_proto_library.
find . -type l \( -name '*.pb.go' -o -name '*.gen.go' \) | xargs rm -f

gazelle \
-go_prefix istio.io/mixer
bazel run //:gazelle

if [[ "$OSTYPE" == "darwin"* ]]; then
params=(-i "")
else
params=(-i)
fi

find . -type f \( -name BUILD -o -name BUILD.bazel \) -print0 | \
xargs -0 sed -i \
-e '/\/\/mixer\/v1.*:go_default_library/d' \
-e 's|google/rpc:go_default_library|:google/rpc|g'
xargs -0 sed "${params[@]}" \
-e 's|google/rpc:go_default_library|:google/rpc|g' \
-e 's|@io_istio_api//mixer/v1/config/descriptor:go_default_library|@io_istio_api//:mixer/v1/config/descriptor|g' \
-e 's|@io_istio_api//mixer/v1:go_default_library|@io_istio_api//:mixer/v1|g' \
-e 's|@io_istio_api//mixer/v1/template:go_default_library|@io_istio_api//:mixer/v1/template|g'
154 changes: 71 additions & 83 deletions bin/linters.sh
Original file line number Diff line number Diff line change
@@ -1,96 +1,84 @@
#!/bin/bash

# Runs all requisite linters over the whole mixer code base.
set -e
SCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P )
source $SCRIPTPATH/use_bazel_go.sh

ROOTDIR=$SCRIPTPATH/..
cd $ROOTDIR
set -o errexit
set -o nounset
set -o pipefail
set -x

prep_linters() {
bin/bazel_to_go.py
}
bin/bazel_to_go.py

go_metalinter() {
LINTER_SHA="bfcc1d6942136fd86eb6f1a6fb328de8398fbd80"
echo Running buildifier...
bazel build @com_github_bazelbuild_buildtools//buildifier
buildifier=$(bazel info bazel-bin)/external/com_github_bazelbuild_buildtools/buildifier/buildifier
$buildifier -showlog -mode=check \
$(find . -type f \( -name 'BUILD*' -or -name 'WORKSPACE' -or -wholename '.*bazel$' -or -wholename '.*bzl$' \) -print )

if [[ "$OSTYPE" == "darwin"* ]]; then
gometalinter=$(which gometalinter)
if [[ -z $gometalinter ]]; then
cat << EOF
echo Running linters...
LINTER_SHA="bfcc1d6942136fd86eb6f1a6fb328de8398fbd80"
if [[ "$OSTYPE" == "darwin"* ]]; then
gometalinter=$(which gometalinter)
if [[ -z $gometalinter ]]; then
cat << EOF
# Please install gometalinter:
go get -d github.com/alecthomas/gometalinter && \
pushd $HOME/go/src/github.com/alecthomas/gometalinter && \
git checkout -q "${LINTER_SHA}" && \
go build -v -o $HOME/bin/gometalinter . && \
gometalinter --install && \
popd
pushd $HOME/go/src/github.com/alecthomas/gometalinter && \
git checkout -q "${LINTER_SHA}" && \
go build -v -o $HOME/bin/gometalinter . && \
gometalinter --install && \
popd
EOF
exit 1
fi
else
# Note: WriteHeaderAndJson excluded because the interface is defined in a 3rd party library.
gometalinter="docker run \
-v $(bazel info output_base):$(bazel info output_base) \
-v $(pwd):/go/src/istio.io/mixer \
-w /go/src/istio.io/mixer \
gcr.io/istio-testing/linter:${LINTER_SHA}"
fi
exit 1
fi
else
# Note: WriteHeaderAndJson excluded because the interface is defined in a 3rd party library.
gometalinter="docker run \
-v $(bazel info output_base):$(bazel info output_base) \
-v $(pwd):/go/src/istio.io/mixer \
-w /go/src/istio.io/mixer \
gcr.io/istio-testing/linter:${LINTER_SHA}"
fi

NUM_CPU=$(getconf _NPROCESSORS_ONLN)
echo Running linters...
$gometalinter \
--concurrency=${NUM_CPU}\
--enable-gc\
--vendored-linters\
--deadline=1200s --disable-all\
--enable=aligncheck\
--enable=deadcode\
--enable=errcheck\
--enable=gas\
--enable=goconst\
--enable=gofmt\
--enable=goimports\
--enable=golint --min-confidence=0\
--enable=gotype\
--exclude=vendor\
--exclude=.pb.go\
--exclude=pkg/config/proto/combined.go\
--exclude=.*.gen.go\
--exclude="should have a package comment"\
--exclude=".*pkg/config/apiserver_test.go:.* method WriteHeaderAndJson should be WriteHeaderAndJSON"\
--enable=ineffassign\
--enable=interfacer\
--enable=lll --line-length=160\
--enable=megacheck\
--enable=misspell\
--enable=structcheck\
--enable=unconvert\
--enable=unparam\
--enable=varcheck\
--enable=vet\
--enable=vetshadow\
--skip=testdata\
--skip=vendor\
--vendor\
./...
}
NUM_CPU=$(getconf _NPROCESSORS_ONLN)
$gometalinter \
--concurrency=${NUM_CPU}\
--enable-gc\
--vendored-linters\
--deadline=1200s --disable-all\
--enable=aligncheck\
--enable=deadcode\
--enable=errcheck\
--enable=gas\
--enable=goconst\
--enable=gofmt\
--enable=goimports\
--enable=golint --min-confidence=0\
--enable=gotype\
--exclude=vendor\
--exclude=.pb.go\
--exclude=pkg/config/proto/combined.go\
--exclude=.*.gen.go\
--exclude="should have a package comment"\
--exclude=".*pkg/config/apiserver_test.go:.* method WriteHeaderAndJson should be WriteHeaderAndJSON"\
--enable=ineffassign\
--enable=interfacer\
--enable=lll --line-length=160\
--enable=megacheck\
--enable=misspell\
--enable=structcheck\
--enable=unconvert\
--enable=unparam\
--enable=varcheck\
--enable=vet\
--enable=vetshadow\
--skip=testdata\
--skip=vendor\
--vendor\
./...

run_linters() {
echo Running buildifier...
bazel build @com_github_bazelbuild_buildtools//buildifier
buildifier=$(bazel info bazel-bin)/external/com_github_bazelbuild_buildtools/buildifier/buildifier
$buildifier -showlog -mode=check $(find . -name BUILD -type f)
$buildifier -showlog -mode=check $(find . -name BUILD.bazel -type f)
$buildifier -showlog -mode=check ./BUILD.ubuntu
$buildifier -showlog -mode=check ./WORKSPACE
go_metalinter
$SCRIPTPATH/check_license.sh
$SCRIPTPATH/check_workspace.sh
}
echo Check license...
bin/check_license.sh

prep_linters
run_linters
echo Check workspace...
bin/check_workspace.sh

echo Done running linters
Loading

0 comments on commit 35cbd5d

Please sign in to comment.