Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Nov 14, 2024
1 parent 1b8c93b commit 9984489
Show file tree
Hide file tree
Showing 60 changed files with 1,375 additions and 859 deletions.
983 changes: 307 additions & 676 deletions DEPS.bzl

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions br/pkg/storage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ go_library(
"@com_github_aws_aws_sdk_go//service/s3",
"@com_github_aws_aws_sdk_go//service/s3/s3iface",
"@com_github_aws_aws_sdk_go//service/s3/s3manager",
"@com_github_azure_azure_sdk_for_go_sdk_azcore//:azcore",
"@com_github_azure_azure_sdk_for_go_sdk_azcore//policy",
"@com_github_azure_azure_sdk_for_go_sdk_azidentity//:azidentity",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//:azblob",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//blob",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//bloberror",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//blockblob",
"@com_github_azure_azure_sdk_for_go_sdk_storage_azblob//container",
"@com_github_google_uuid//:uuid",
"@com_github_klauspost_compress//gzip",
"@com_github_klauspost_compress//snappy",
Expand Down
12 changes: 11 additions & 1 deletion build/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_go//go:def.bzl", "nogo")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "nogo")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//build/linter/staticcheck:def.bzl", "staticcheck_analyzers")

Expand Down Expand Up @@ -147,3 +147,13 @@ nogo(
"//conditions:default": [],
}),
)

go_library(
name = "build",
srcs = ["config.go"],
embedsrcs = [
"nogo_config.json",
],
importpath = "github.com/pingcap/tidb/build",
visibility = ["//visibility:public"],
)
42 changes: 42 additions & 0 deletions build/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2023 PingCAP, Inc.
//
// 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.

package build

import (
_ "embed"
"encoding/json"
)

//go:embed nogo_config.json
var configFile []byte

// NogoConfig is the nogo config file
var NogoConfig NogoConfigFormat

// NogoConfigFormat is the format of the nogo config file
type NogoConfigFormat map[string]AnalysisConfig

// AnalysisConfig represents the config of an analysis pass
type AnalysisConfig struct {
ExcludeFiles map[string]string `json:"exclude_files"`
OnlyFiles map[string]string `json:"only_files"`
}

func init() {
err := json.Unmarshal(configFile, &NogoConfig)
if err != nil {
panic("fail to parse nogo_config.json")
}
}
9 changes: 9 additions & 0 deletions build/linter/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "linter",
srcs = ["linter.go"],
importpath = "github.com/pingcap/tidb/build/linter",
visibility = ["//visibility:public"],
deps = ["@com_github_apache_skywalking_eyes//pkg/config"],
)
1 change: 1 addition & 0 deletions build/linter/allrevive/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//build/linter/util",
"@com_github_hashicorp_go_version//:go-version",
"@com_github_mgechev_revive//config",
"@com_github_mgechev_revive//lint",
"@com_github_mgechev_revive//rule",
Expand Down
23 changes: 14 additions & 9 deletions build/linter/allrevive/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package allrevive

import (
"encoding/json"
"fmt"
"go/token"
"os"

goversion "github.com/hashicorp/go-version"
"github.com/mgechev/revive/config"
"github.com/mgechev/revive/lint"
"github.com/mgechev/revive/rule"
Expand All @@ -37,6 +37,7 @@ var Analyzer = &analysis.Analyzer{
}

func init() {
util.SkipAnalyzerByConfig(Analyzer)
util.SkipAnalyzer(Analyzer)
}

Expand Down Expand Up @@ -88,11 +89,11 @@ var allRules = append([]lint.Rule{
&rule.ConstantLogicalExprRule{},
&rule.BoolLiteralRule{},
//&rule.RedefinesBuiltinIDRule{},
&rule.ImportsBlacklistRule{},
&rule.BlankImportsRule{},
//&rule.FunctionResultsLimitRule{},
//&rule.MaxPublicStructsRule{},
&rule.RangeValInClosureRule{},
&rule.RangeValAddress{},
//&rule.RangeValInClosureRule{},
//&rule.RangeValAddress{},
&rule.WaitGroupByValueRule{},
&rule.AtomicRule{},
&rule.EmptyLinesRule{},
Expand All @@ -106,7 +107,7 @@ var allRules = append([]lint.Rule{
//&rule.CognitiveComplexityRule{},
&rule.StringOfIntRule{},
&rule.StringFormatRule{},
//&rule.EarlyReturnRule{},
&rule.EarlyReturnRule{},
&rule.UnconditionalRecursionRule{},
&rule.IdenticalBranchesRule{},
&rule.DeferRule{},
Expand All @@ -126,9 +127,13 @@ func run(pass *analysis.Pass) (any, error) {
files = append(files, pass.Fset.PositionFor(file.Pos(), false).Filename)
}
packages := [][]string{files}

gv, err := goversion.NewVersion("1.21")
if err != nil {
panic(err)
}
revive := lint.New(os.ReadFile, 1024)
conf := lint.Config{
GoVersion: gv,
IgnoreGeneratedHeader: false,
Confidence: 0.8,
Severity: "error",
Expand All @@ -140,7 +145,7 @@ func run(pass *analysis.Pass) (any, error) {
conf.Rules[r.Name()] = lint.RuleConfig{}
}
conf.Rules["defer"] = lint.RuleConfig{
Arguments: []interface{}{[]interface{}{"loop", "method-call", "immediate-recover", "return"}},
Arguments: []any{[]any{"loop", "method-call", "immediate-recover", "return"}},
}

lintingRules, err := config.GetLintingRules(&conf, []lint.Rule{})
Expand Down Expand Up @@ -187,12 +192,12 @@ func run(pass *analysis.Pass) (any, error) {
}
for i := range results {
res := &results[i]
text := fmt.Sprintf("%s: %s", res.RuleName, res.Failure.Failure)
fileContent, tf, err := util.ReadFile(pass.Fset, res.Position.Start.Filename)
if err != nil {
panic(err)
}
pass.Reportf(token.Pos(tf.Base()+util.FindOffset(string(fileContent), res.Position.Start.Line, res.Position.Start.Column)), text)
pass.Reportf(token.Pos(tf.Base()+util.FindOffset(string(fileContent), res.Position.Start.Line, res.Position.Start.Column)),
"%s: %s", res.RuleName, res.Failure.Failure)
}
return nil, nil
}
5 changes: 4 additions & 1 deletion build/linter/asciicheck/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ go_library(
srcs = ["analysis.go"],
importpath = "github.com/pingcap/tidb/build/linter/asciicheck",
visibility = ["//visibility:public"],
deps = ["@com_github_tdakkota_asciicheck//:asciicheck"],
deps = [
"//build/linter/util",
"@com_github_tdakkota_asciicheck//:asciicheck",
],
)
9 changes: 8 additions & 1 deletion build/linter/asciicheck/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@

package asciicheck

import "github.com/tdakkota/asciicheck"
import (
"github.com/pingcap/tidb/build/linter/util"
"github.com/tdakkota/asciicheck"
)

// Analyzer is the analyzer struct of asciicheck.
var Analyzer = asciicheck.NewAnalyzer()

func init() {
util.SkipAnalyzerByConfig(Analyzer)
}
12 changes: 12 additions & 0 deletions build/linter/bootstrap/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "bootstrap",
srcs = ["analyzer.go"],
importpath = "github.com/pingcap/tidb/build/linter/bootstrap",
visibility = ["//visibility:public"],
deps = [
"//build/linter/util",
"@org_golang_x_tools//go/analysis",
],
)
167 changes: 167 additions & 0 deletions build/linter/bootstrap/analyzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Copyright 2023 PingCAP, Inc.
//
// 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.

package bootstrap

import (
"go/ast"
"go/token"
"strconv"
"strings"

"github.com/pingcap/tidb/build/linter/util"
"golang.org/x/tools/go/analysis"
)

// Analyzer is the analyzer struct of unconvert.
var Analyzer = &analysis.Analyzer{
Name: "bootstrap",
Doc: "Check developers don't forget something in TiDB bootstrap logic",
Requires: []*analysis.Analyzer{},
Run: run,
}

const (
bootstrapCodeFile = "/bootstrap.go"
)

func run(pass *analysis.Pass) (any, error) {
for _, file := range pass.Files {
if !strings.HasSuffix(pass.Fset.File(file.Pos()).Name(), bootstrapCodeFile) {
continue
}

var (
maxVerVariable int
maxVerVariablePos token.Pos
curVerVariable int
curVerVariablePos token.Pos
maxVerFunc int
maxVerFuncPos token.Pos
maxVerFuncUsed int
maxVerFuncUsedPos token.Pos
err error
)

for _, decl := range file.Decls {
switch v := decl.(type) {
case *ast.GenDecl:
switch {
case len(v.Specs) == 1:
spec := v.Specs[0]
v2, ok := spec.(*ast.ValueSpec)
if !ok {
continue
}
if len(v2.Names) != 1 {
continue
}
switch v2.Names[0].Name {
case "bootstrapVersion":
composeLit := v2.Values[0].(*ast.CompositeLit)
lastElm := composeLit.Elts[len(composeLit.Elts)-1]
ident := lastElm.(*ast.Ident)
maxVerFuncUsed, err = strconv.Atoi(ident.Name[len("upgradeToVer"):])
if err != nil {
panic("unexpected value of bootstrapVersion: " + ident.Name)
}
maxVerFuncUsedPos = lastElm.Pos()
case "currentBootstrapVersion":
valueIdent := v2.Values[0].(*ast.Ident)
curVerVariablePos = valueIdent.Pos()
value := v2.Values[0].(*ast.Ident).Name
curVerVariable, err = strconv.Atoi(value[len("version"):])
if err != nil {
panic("unexpected value of currentBootstrapVersion: " + value)
}
default:
continue
}
case v.Tok == token.CONST && len(v.Specs) > 1:
for _, spec := range v.Specs {
v2, ok := spec.(*ast.ValueSpec)
if !ok {
continue
}
if len(v2.Names) != 1 {
continue
}
name := v2.Names[0].Name
if !strings.HasPrefix(name, "version") {
continue
}

valInName, err := strconv.Atoi(name[len("version"):])
if err != nil {
continue
}

if valInName < maxVerVariable {
pass.Reportf(spec.Pos(), "version variable %q is not valid, we should have a increment list of version variables", name)
continue
}

maxVerVariable = valInName
maxVerVariablePos = v2.Names[0].Pos()

if len(v2.Values) != 1 {
pass.Reportf(spec.Pos(), "the value of version variable %q must be specified explicitly", name)
continue
}

valStr := v2.Values[0].(*ast.BasicLit).Value
val, err := strconv.Atoi(valStr)
if err != nil {
pass.Reportf(spec.Pos(), "unexpected value of version variable %q: %q", name, valStr)
continue
}

if val != valInName {
pass.Reportf(spec.Pos(), "the value of version variable %q must be '%d', but now is '%d'", name, valInName, val)
continue
}
}
}
case *ast.FuncDecl:
name := v.Name.Name
if !strings.HasPrefix(name, "upgradeToVer") {
continue
}
t, err := strconv.Atoi(name[len("upgradeToVer"):])
if err != nil {
continue
}
if t > maxVerFunc {
maxVerFunc = t
maxVerFuncPos = v.Pos()
}
}
}
minv := min(maxVerVariable, maxVerFunc, maxVerFuncUsed, curVerVariable)
maxv := max(maxVerVariable, maxVerFunc, maxVerFuncUsed, curVerVariable)
if minv == maxv && minv != 0 {
return nil, nil
}
pass.Reportf(maxVerFuncUsedPos, "found inconsistent bootstrap versions:")
pass.Reportf(maxVerFuncUsedPos, "max version function used: %d", maxVerFuncUsed)
pass.Reportf(maxVerFuncPos, "max version function: %d", maxVerFunc)
pass.Reportf(maxVerVariablePos, "max version variable: %d", maxVerVariable)
pass.Reportf(curVerVariablePos, "current version variable: %d", curVerVariable)
}
return nil, nil
}

func init() {
util.SkipAnalyzerByConfig(Analyzer)
}
Loading

0 comments on commit 9984489

Please sign in to comment.