Skip to content

Commit

Permalink
cmd/gazelle: hack to fix repository name hfor @go_googleapis (#717)
Browse files Browse the repository at this point in the history
Normally, Gazelle detects the repository name by reading the WORKSPACE
file and looking for a workspace rule. In go_googleapis, the proper
workspace name is com_google_googleapis. Before
bazel-contrib/rules_go#2355, we patched the WORKSPACE file before running
Gazelle so the repository name would be set to
go_googleapis. Unfortunately, in newer versions of Bazel, WORKSPACE is
overwritten, so the patch doesn't apply.

This change just adds a hack to set the repository name to
go_googleapis if com_google_googleapis is detected.

Updates bazel-contrib/rules_go#2387
  • Loading branch information
Jay Conrod authored Feb 26, 2020
1 parent 83884f7 commit 960ddc5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/gazelle/fix-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,20 @@ func removeLegacyGoRepository(f *rule.File) {
}

func findWorkspaceName(f *rule.File) string {
var name string
for _, r := range f.Rules {
if r.Kind() == "workspace" {
return r.Name()
name = r.Name()
break
}
}
return ""
// HACK(bazelbuild/rules_go#2355, bazelbuild/rules_go#2387):
// We can't patch the WORKSPACE file with the correct name because Bazel
// writes it first; our patches won't apply.
if name == "com_google_googleapis" {
return "go_googleapis"
}
return name
}

func isDescendingDir(dir, root string) bool {
Expand Down

0 comments on commit 960ddc5

Please sign in to comment.