Skip to content

Commit

Permalink
language/go: stop generating go_tool_library rules for x/tools
Browse files Browse the repository at this point in the history
bazel-contrib/rules_go#2374 has been fixed, so there is no more need for it.
  • Loading branch information
Rob Figueiredo committed Oct 6, 2021
1 parent 136915e commit 1a9fb0f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
65 changes: 0 additions & 65 deletions language/go/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ func (gl *goLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
libName = lib.Name()
}
rules = append(rules, lib)
if r := g.maybeGenerateToolLib(lib, pkg); r != nil {
rules = append(rules, r)
}
if r := g.maybeGenerateExtraLib(lib, pkg); r != nil {
rules = append(rules, r)
}
Expand Down Expand Up @@ -535,68 +532,6 @@ func (g *generator) generateTest(pkg *goPackage, library string) *rule.Rule {
return goTest
}

// maybeGenerateToolLib generates a go_tool_library target equivalent to the
// go_library in the same directory. maybeGenerateToolLib returns nil for
// packages outside golang.org/x/tools and for packages that aren't known
// dependencies of nogo.
//
// HACK(#834): This is only needed by golang.org/x/tools for dependencies of
// nogo. go_tool_library should be removed when bazelbuild/rules_go#2374 is
// resolved, so these targets shouldn't be generated in other repositories.
// Generating them here automatically makes it easier to upgrade
// org_golang_x_tools.
func (g *generator) maybeGenerateToolLib(lib *rule.Rule, pkg *goPackage) *rule.Rule {
// Check whether we should generate go_tool_library.
gc := getGoConfig(g.c)
if gc.prefix != "golang.org/x/tools" || gc.prefixRel != "" || !isToolLibImportPath(pkg.importPath) {
return nil
}

// Generate the target.
toolLib := rule.NewRule("go_tool_library", "go_tool_library")
var visibility []string
if pkg.importPath == "golang.org/x/tools/go/analysis/internal/facts" {
// Imported by nogo main. We add a visibility exception.
visibility = []string{"//visibility:public"}
} else {
visibility = g.commonVisibility(pkg.importPath)
}
g.setCommonAttrs(toolLib, pkg.rel, visibility, pkg.library, "")
g.setImportAttrs(toolLib, pkg.importPath)
return toolLib
}

func isToolLibImportPath(imp string) bool {
if !strings.HasPrefix(imp, "golang.org/x/tools/") {
return false
}
pass := strings.TrimPrefix(imp, "golang.org/x/tools/go/analysis/passes/")
if pass != imp && strings.Index(pass, "/") < 0 {
// Direct dependency of nogo
return true
}
switch imp {
case "golang.org/x/tools/go/analysis",
"golang.org/x/tools/go/analysis/internal/facts",
"golang.org/x/tools/go/analysis/passes/internal/analysisutil",
"golang.org/x/tools/go/ast/astutil",
"golang.org/x/tools/go/ast/inspector",
"golang.org/x/tools/go/cfg",
"golang.org/x/tools/go/gcexportdata",
"golang.org/x/tools/go/internal/gcimporter",
"golang.org/x/tools/go/ssa",
"golang.org/x/tools/go/types/objectpath",
"golang.org/x/tools/go/types/typeutil",
"golang.org/x/tools/internal/analysisinternal",
"golang.org/x/tools/internal/typeparams",
"golang.org/x/tools/internal/lsp/fuzzy":
// Indirect dependency of nogo.
return true
default:
return false
}
}

// maybeGenerateExtraLib generates extra equivalent library targets for
// certain protobuf libraries. These "_gen" targets depend on Well Known Types
// built with go_proto_library and are used together with go_proto_library.
Expand Down
15 changes: 0 additions & 15 deletions language/go/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ func (gl *goLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo.Remo
switch r.Kind() {
case "go_proto_library":
resolve = resolveProto
case "go_tool_library":
resolve = resolveGoTool
default:
resolve = ResolveGo
}
Expand Down Expand Up @@ -330,19 +328,6 @@ func resolveProto(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache,
return label.New("", rel, libName), nil
}

func resolveGoTool(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, imp string, from label.Label) (label.Label, error) {
if isToolLibImportPath(imp) {
gc := getGoConfig(c)
var repo string
if gc.prefix != "golang.org/x/tools" {
repo = "org_golang_x_tools"
}
pkg := strings.TrimPrefix(imp, "golang.org/x/tools/")
return label.Label{Repo: repo, Pkg: pkg, Name: "go_tool_library"}, nil
}
return ResolveGo(c, ix, rc, imp, from)
}

// wellKnownProtos is the set of proto sets for which we don't need to add
// an explicit dependency in go_proto_library.
// TODO(jayconrod): generate from
Expand Down

0 comments on commit 1a9fb0f

Please sign in to comment.