Skip to content

Commit 5bed878

Browse files
authored
Update common files. (#5052)
1 parent a5f38e1 commit 5bed878

11 files changed

+131
-61
lines changed

.gitattributes

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.descriptor linguist-generated=true
2+
*.descriptor -diff -merge
3+
*.descriptor_set linguist-generated=true
4+
*.descriptor_set -diff -merge
5+
*.pb.html linguist-generated=true
6+
*.pb.go linguist-generated=true
7+
*.gen.go linguist-generated=true
8+
*.gen.yaml linguist-generated=true
9+
*_pb2.py linguist-generated=true

Makefile

+32-26
Original file line numberDiff line numberDiff line change
@@ -28,62 +28,68 @@
2828
# figure out all the tools you need in your environment to make that work.
2929
export BUILD_WITH_CONTAINER ?= 0
3030

31-
ifeq ($(BUILD_WITH_CONTAINER),1)
32-
IMG = gcr.io/istio-testing/build-tools:2019-08-29T13-57-48
33-
UID = $(shell id -u)
34-
PWD = $(shell pwd)
35-
GOBIN_SOURCE ?= $(GOPATH)/bin
36-
GOBIN ?= /work/out/bin
37-
3831
LOCAL_ARCH := $(shell uname -m)
3932
ifeq ($(LOCAL_ARCH),x86_64)
40-
GOARCH_LOCAL := amd64
33+
TARGET_ARCH ?= amd64
4134
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
42-
GOARCH_LOCAL := arm64
35+
TARGET_ARCH ?= arm64
4336
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
44-
GOARCH_LOCAL := arm
37+
TARGET_ARCH ?= arm
4538
else
46-
GOARCH_LOCAL := $(LOCAL_ARCH)
39+
$(error "This system's architecture $(LOCAL_ARCH) isn't recognized/supported")
4740
endif
4841

49-
GOARCH ?= $(GOARCH_LOCAL)
50-
5142
LOCAL_OS := $(shell uname)
5243
ifeq ($(LOCAL_OS),Linux)
53-
GOOS_LOCAL = linux
44+
TARGET_OS ?= linux
45+
READLINK_FLAGS="-f"
5446
else ifeq ($(LOCAL_OS),Darwin)
55-
GOOS_LOCAL = darwin
47+
TARGET_OS ?= darwin
48+
READLINK_FLAGS=""
5649
else
5750
$(error "This system's OS $(LOCAL_OS) isn't recognized/supported")
5851
endif
5952

60-
GOOS ?= $(GOOS_LOCAL)
53+
REPO_ROOT = $(shell git rev-parse --show-toplevel)
54+
REPO_NAME = $(shell basename $(REPO_ROOT))
55+
TARGET_OUT ?= $(HOME)/istio_out/$(REPO_NAME)
56+
57+
ifeq ($(BUILD_WITH_CONTAINER),1)
58+
CONTAINER_CLI ?= docker
59+
DOCKER_SOCKET_MOUNT ?= -v /var/run/docker.sock:/var/run/docker.sock
60+
IMG ?= gcr.io/istio-testing/build-tools:2019-09-23T12-48-14
61+
UID = $(shell id -u)
62+
PWD = $(shell pwd)
63+
64+
# Determine the timezone across various platforms to pass into the
65+
# docker run operation. This operation assumes zoneinfo is within
66+
# the path of the file.
67+
TIMEZONE=`readlink $(READLINK_FLAGS) /etc/localtime | sed -e 's/^.*zoneinfo\///'`
6168

62-
RUN = docker run -t -i --sig-proxy=true -u $(UID) --rm \
63-
-e GOOS="$(GOOS)" \
64-
-e GOARCH="$(GOARCH)" \
65-
-e GOBIN="$(GOBIN)" \
69+
RUN = $(CONTAINER_CLI) run -t -i --sig-proxy=true -u $(UID) --rm \
6670
-e BUILD_WITH_CONTAINER="$(BUILD_WITH_CONTAINER)" \
71+
-e TZ="$(TIMEZONE)" \
72+
-e TARGET_ARCH="$(TARGET_ARCH)" \
73+
-e TARGET_OS="$(TARGET_OS)" \
6774
-v /etc/passwd:/etc/passwd:ro \
68-
-v $(readlink /etc/localtime):/etc/localtime:ro \
69-
-v /var/run/docker.sock:/var/run/docker.sock \
75+
$(DOCKER_SOCKET_MOUNT) \
7076
$(CONTAINER_OPTIONS) \
7177
--mount type=bind,source="$(PWD)",destination="/work" \
72-
--mount type=volume,source=istio-go-mod,destination="/go/pkg/mod" \
73-
--mount type=volume,source=istio-go-cache,destination="/gocache" \
74-
--mount type=bind,source="$(GOBIN_SOURCE)",destination="/go/out/bin" \
78+
--mount type=bind,source="$(TARGET_OUT)",destination="/targetout" \
79+
--mount type=volume,source=home,destination="/home" \
7580
-w /work $(IMG)
7681
else
77-
export GOBIN ?= ./out/bin
7882
RUN =
7983
endif
8084

8185
MAKE = $(RUN) make --no-print-directory -e -f Makefile.core.mk
8286

8387
%:
88+
@mkdir -p $(TARGET_OUT)
8489
@$(MAKE) $@
8590

8691
default:
92+
@mkdir -p $(TARGET_OUT)
8793
@$(MAKE)
8894

8995
.PHONY: default

common/.commonfiles.sha

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c3b89849b7ad86801e4511bc915137981c1ec0f1
1+
b911e0db0ccb611ae4fd361d295af2ef5f8089d7

common/Makefile.common.mk

+17-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# See the License for the specific language governing permissions and
2020
# limitations under the License.
2121

22-
FINDFILES=find . \( -path ./vendor -o -path ./.git \) -prune -o -type f
22+
FINDFILES=find . \( -path ./common-protos -o -path ./.git -o -path ./.github \) -prune -o -type f
2323
XARGS = xargs -0 -r
2424

2525
lint-dockerfiles:
@@ -36,43 +36,50 @@ lint-helm:
3636

3737
lint-copyright-banner:
3838
@${FINDFILES} \( -name '*.go' -o -name '*.cc' -o -name '*.h' -o -name '*.proto' -o -name '*.py' -o -name '*.sh' \) \( ! \( -name '*.gen.go' -o -name '*.pb.go' -o -name '*_pb2.py' \) \) -print0 |\
39-
${XARGS} common/scripts/lint_copyright_banner.sh
39+
${XARGS} common/scripts/lint_copyright_banner.sh
4040

4141
lint-go:
42-
@${FINDFILES} -name '*.go' \( ! \( -name '*.gen.go' -o -name '*.pb.go' \) \) -print0 | : | ${XARGS} golangci-lint run -j 8 -c ./common/config/.golangci.yml
42+
@${FINDFILES} -name '*.go' \( ! \( -name '*.gen.go' -o -name '*.pb.go' \) \) -print0 | ${XARGS} common/scripts/lint_go.sh
4343

4444
lint-python:
45-
@${FINDFILES} -name '*.py' -print0 | ${XARGS} autopep8 --max-line-length 160 --exit-code -d
45+
@${FINDFILES} -name '*.py' \( ! \( -name '*_pb2.py' \) \) -print0 | ${XARGS} autopep8 --max-line-length 160 --exit-code -d
4646

4747
lint-markdown:
4848
@${FINDFILES} -name '*.md' -print0 | ${XARGS} mdl --ignore-front-matter --style common/config/mdl.rb
49-
@${FINDFILES} -name '*.md' -print0 | ${XARGS} awesome_bot --skip-save-results --allow_ssl --allow-timeout --allow-dupe --allow-redirect
49+
@${FINDFILES} -name '*.md' -print0 | ${XARGS} awesome_bot --skip-save-results --allow_ssl --allow-timeout --allow-dupe --allow-redirect --white-list ${MARKDOWN_LINT_WHITELIST}
5050

5151
lint-sass:
5252
@${FINDFILES} -name '*.scss' -print0 | ${XARGS} sass-lint -c common/config/sass-lint.yml --verbose
5353

5454
lint-typescript:
5555
@${FINDFILES} -name '*.ts' -print0 | ${XARGS} tslint -c common/config/tslint.json
5656

57-
lint-all: lint-dockerfiles lint-scripts lint-yaml lint-helm lint-copyright-banner lint-go lint-python lint-markdown lint-sass lint-typescript
57+
lint-protos:
58+
@if test -d common-protos; then $(FINDFILES) -name '*.proto' -print0 | $(XARGS) -L 1 prototool lint --protoc-bin-path=/usr/bin/protoc --protoc-wkt-path=common-protos; fi
59+
60+
lint-all: lint-dockerfiles lint-scripts lint-yaml lint-helm lint-copyright-banner lint-go lint-python lint-markdown lint-sass lint-typescript lint-protos
5861

5962
format-go:
6063
@${FINDFILES} -name '*.go' \( ! \( -name '*.gen.go' -o -name '*.pb.go' \) \) -print0 | ${XARGS} goimports -w -local "istio.io"
6164

6265
format-python:
6366
@${FINDFILES} -name '*.py' -print0 | ${XARGS} autopep8 --max-line-length 160 --aggressive --aggressive -i
6467

68+
format-protos:
69+
@$(FINDFILES) -name '*.proto' -print0 | $(XARGS) -L 1 prototool format -w
70+
6571
update-common:
66-
@git clone --depth 1 --single-branch --branch master https://github.com/istio/common-files
72+
@git clone -q --depth 1 --single-branch --branch master https://github.com/istio/common-files
6773
@cd common-files ; git rev-parse HEAD >files/common/.commonfiles.sha
6874
@rm -fr common
69-
@cp -r common-files/files/* .
75+
@cp -rT common-files/files .
7076
@rm -fr common-files
7177

7278
update-common-protos:
73-
@git clone --depth 1 --single-branch --branch master https://github.com/istio/common-files
79+
@git clone -q --depth 1 --single-branch --branch master https://github.com/istio/common-files
7480
@cd common-files ; git rev-parse HEAD > common-protos/.commonfiles.sha
81+
@rm -fr common-protos
7582
@cp -ar common-files/common-protos common-protos
7683
@rm -fr common-files
7784

78-
.PHONY: lint-dockerfiles lint-scripts lint-yaml lint-copyright-banner lint-go lint-pyhton lint-helm lint-markdown lint-sass lint-typescript lint-all format-go format-python update-common update-common-protos
85+
.PHONY: lint-dockerfiles lint-scripts lint-yaml lint-copyright-banner lint-go lint-pyhton lint-helm lint-markdown lint-sass lint-typescript lint-protos lint-all format-go format-python format-protos update-common update-common-protos

common/config/.golangci.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
service:
99
# When updating this, also update the version stored in docker/build-tools/Dockerfile in the istio/tools repo.
10-
golangci-lint-version: 1.16.x # use the fixed version to not introduce new linters unexpectedly
10+
golangci-lint-version: 1.18.x # use the fixed version to not introduce new linters unexpectedly
1111
run:
1212
# timeout for analysis, e.g. 30s, 5m, default is 1m
1313
deadline: 20m
@@ -42,6 +42,8 @@ linters:
4242
- nakedret
4343
- prealloc
4444
- scopelint
45+
- funlen
46+
- bodyclose
4547
fast: false
4648

4749
linters-settings:
@@ -74,6 +76,8 @@ linters-settings:
7476
# Default is to use a neutral variety of English.
7577
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
7678
locale: US
79+
ignore-words:
80+
- cancelled
7781
lll:
7882
# max line length, lines longer will be reported. Default is 120.
7983
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
@@ -142,9 +146,9 @@ linters-settings:
142146
- unslice
143147
- valSwap
144148
- weakCond
145-
- yodaStyleExpr
146149

147150
# Unused
151+
# - yodaStyleExpr
148152
# - appendAssign
149153
# - commentFormatting
150154
# - emptyStringTest

common/config/mdl.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
all
2-
rule 'MD002', :level => 2
2+
rule 'MD002', :level => 1
33
rule 'MD007', :indent => 4
44
rule 'MD013', :line_length => 160, :code_blocks => false, :tables => false
55
rule 'MD026', :punctuation => ".,;:!"

common/scripts/gobuild.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
2+
3+
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
24
#
5+
# The original version of this file is located in the https://github.com/istio/common-files repo.
6+
# If you're looking at this file in a different repo and want to make a change, please go to the
7+
# common-files repo, make the change there and check it in. Then come back to this repo and run
8+
# "make update-common".
9+
310
# Copyright Istio Authors. All Rights Reserved.
411
#
512
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,16 +33,17 @@ fi
2633
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2734

2835
OUT=${1:?"output path"}
29-
BUILDPATH=${2:?"path to build"}
36+
shift
3037

3138
set -e
3239

3340
BUILD_GOOS=${GOOS:-linux}
3441
BUILD_GOARCH=${GOARCH:-amd64}
3542
GOBINARY=${GOBINARY:-go}
43+
GOPKG="$GOPATH/pkg"
3644
BUILDINFO=${BUILDINFO:-""}
3745
STATIC=${STATIC:-1}
38-
LDFLAGS="-extldflags -static"
46+
LDFLAGS=${LDFLAGS:--extldflags -static}
3947
GOBUILDFLAGS=${GOBUILDFLAGS:-""}
4048
# Split GOBUILDFLAGS by spaces into an array called GOBUILDFLAGS_ARRAY.
4149
IFS=' ' read -r -a GOBUILDFLAGS_ARRAY <<< "$GOBUILDFLAGS"
@@ -57,11 +65,14 @@ fi
5765

5866
# BUILD LD_EXTRAFLAGS
5967
LD_EXTRAFLAGS=""
68+
6069
while read -r line; do
6170
LD_EXTRAFLAGS="${LD_EXTRAFLAGS} -X ${line}"
6271
done < "${BUILDINFO}"
6372

6473
time GOOS=${BUILD_GOOS} GOARCH=${BUILD_GOARCH} ${GOBINARY} build \
6574
${V} "${GOBUILDFLAGS_ARRAY[@]}" ${GCFLAGS:+-gcflags "${GCFLAGS}"} \
6675
-o "${OUT}" \
67-
-ldflags "${LDFLAGS} ${LD_EXTRAFLAGS}" "${BUILDPATH}"
76+
-trimpath \
77+
-pkgdir="${GOPKG}/${BUILD_GOOS}_${BUILD_GOARCH}" \
78+
-ldflags "${LDFLAGS} ${LD_EXTRAFLAGS}" "${@}"

common/scripts/lint_go.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
4+
#
5+
# The original version of this file is located in the https://github.com/istio/common-files repo.
6+
# If you're looking at this file in a different repo and want to make a change, please go to the
7+
# common-files repo, make the change there and check it in. Then come back to this repo and run
8+
# "make update-common".
9+
10+
# Copyright Istio Authors
11+
#
12+
# Licensed under the Apache License, Version 2.0 (the "License");
13+
# you may not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing, software
19+
# distributed under the License is distributed on an "AS IS" BASIS,
20+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
# See the License for the specific language governing permissions and
22+
# limitations under the License.
23+
24+
GOGC=25 golangci-lint run -c ./common/config/.golangci.yml

common/scripts/report_build_info.sh

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22

3+
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
4+
#
5+
# The original version of this file is located in the https://github.com/istio/common-files repo.
6+
# If you're looking at this file in a different repo and want to make a change, please go to the
7+
# common-files repo, make the change there and check it in. Then come back to this repo and run
8+
# "make update-common".
9+
310
# Copyright Istio Authors
411
#
512
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,11 +22,11 @@
1522
# limitations under the License.
1623

1724
if BUILD_GIT_REVISION=$(git rev-parse HEAD 2> /dev/null); then
18-
if ! git diff-index --quiet HEAD; then
19-
BUILD_GIT_REVISION=${BUILD_GIT_REVISION}"-dirty"
20-
fi
25+
if [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then
26+
BUILD_GIT_REVISION=${BUILD_GIT_REVISION}"-dirty"
27+
fi
2128
else
22-
BUILD_GIT_REVISION=unknown
29+
BUILD_GIT_REVISION=unknown
2330
fi
2431

2532
# Check for local changes
@@ -29,26 +36,16 @@ else
2936
tree_status="Modified"
3037
fi
3138

32-
# XXX This needs to be updated to accommodate tags added after building, rather than prior to builds
33-
RELEASE_TAG=$(git describe --match '[0-9]*\.[0-9]*\.[0-9]*' --exact-match 2> /dev/null || echo "")
34-
3539
# security wanted VERSION='unknown'
3640
VERSION="${BUILD_GIT_REVISION}"
37-
if [[ -n "${RELEASE_TAG}" ]]; then
38-
VERSION="${RELEASE_TAG}"
39-
elif [[ -n ${ISTIO_VERSION} ]]; then
41+
if [[ -n ${ISTIO_VERSION} ]]; then
4042
VERSION="${ISTIO_VERSION}"
4143
fi
4244

43-
DOCKER_HUB="docker.io/istio"
44-
if [[ -n ${ISTIO_DOCKER_HUB} ]]; then
45-
DOCKER_HUB="${ISTIO_DOCKER_HUB}"
46-
fi
45+
GIT_DESCRIBE_TAG=$(git describe --tags)
4746

4847
# used by common/scripts/gobuild.sh
4948
echo "istio.io/pkg/version.buildVersion=${VERSION}"
5049
echo "istio.io/pkg/version.buildGitRevision=${BUILD_GIT_REVISION}"
51-
echo "istio.io/pkg/version.buildUser=$(whoami)"
52-
echo "istio.io/pkg/version.buildHost=$(hostname -f)"
53-
echo "istio.io/pkg/version.buildDockerHub=${DOCKER_HUB}"
5450
echo "istio.io/pkg/version.buildStatus=${tree_status}"
51+
echo "istio.io/pkg/version.buildTag=${GIT_DESCRIBE_TAG}"

mdl.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
all
2+
rule 'MD002', :level => 2
3+
rule 'MD007', :indent => 4
4+
rule 'MD013', :line_length => 160, :code_blocks => false, :tables => false
5+
rule 'MD026', :punctuation => ".,;:!"
6+
exclude_rule 'MD013'
7+
exclude_rule 'MD014'
8+
exclude_rule 'MD030'
9+
exclude_rule 'MD032'
10+
exclude_rule 'MD033'
11+
exclude_rule 'MD041'
12+
exclude_rule 'MD046'

scripts/lint_site.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ check_content() {
3939
# create a throwaway copy of the content
4040
cp -R "${DIR}" "${TMP}"
4141
cp .spelling "${TMP}"
42-
cp common/config/mdl.rb "${TMP}"
42+
cp mdl.rb "${TMP}"
4343

4444
# replace the {{< text >}} shortcodes with ```plain
4545
find "${TMP}" -type f -name \*.md -exec sed -E -i "s/\\{\\{< text .*>\}\}/\`\`\`plain/g" {} ";"

0 commit comments

Comments
 (0)