blob: 0555b4a7f4eeff906933ead400a1f07fc7c506f5 [file] [log] [blame]
Brad Fitzpatricke2b91412019-11-25 06:11:04 +00001// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package repos contains information about Go source repositories.
6package repos
7
8import "fmt"
9
10type Repo struct {
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +000011 // GoGerritProject, if non-empty, is the repo's Gerrit project
12 // name, such as "go", "net", or "sys".
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000013 GoGerritProject string
14
15 // ImportPath is the repo's import path.
Dmitri Shuralyov52506642020-03-06 12:29:13 -050016 // It is empty for the main Go repo and other repos that do not
17 // contain Go code.
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000018 ImportPath string
19
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +000020 // MirrorToGitHub controls whether this repo is mirrored
21 // from Gerrit to GitHub. If true, GoGerritProject and
22 // gitHubRepo must both be defined.
23 MirrorToGitHub bool
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000024
Jamal Carvalho6cdc0192021-11-03 23:33:31 +000025 // MirrorToCSRProject controls whether this repo is mirrored from
26 // Gerrit to Cloud Source Repositories. If not empty, GoGerritProject
27 // must be defined. It will be mirrored to a CSR repo in the given
28 // project with the same name as the Gerrit repo.
29 MirrorToCSRProject string
Heschi Kreinick9477c7e2021-06-02 09:59:40 -040030
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +000031 // showOnDashboard is whether to show the repo on the bottom
32 // of build.golang.org in the repo overview section.
33 showOnDashboard bool
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000034
35 // CoordinatorCanBuild reports whether this a repo that the
36 // build coordinator knows how to build.
37 CoordinatorCanBuild bool
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +000038
Heschi Kreinick27cb3d82021-06-02 17:48:15 -040039 // GitHubRepo is the "org/repo" of where this repo exists on
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +000040 // GitHub. If MirrorToGitHub is true, this is the
41 // destination.
Heschi Kreinick27cb3d82021-06-02 17:48:15 -040042 GitHubRepo string
Brad Fitzpatrick24401732019-12-13 16:46:49 +000043
44 // WebsiteDesc is the description of the repo for showing on
45 // https://golang.org/pkg/#subrepo.
46 // It should be plain text. Hostnames may be auto-linkified.
47 WebsiteDesc string
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000048}
49
50// ByGerritProject maps from a Gerrit project name ("go", "net", etc)
51// to the Repo's information.
52var ByGerritProject = map[string]*Repo{ /* initialized below */ }
53
54// ByImportPath maps from an import path ("golang.org/x/net") to the
55// Repo's information.
56var ByImportPath = map[string]*Repo{ /* initialized below */ }
57
58func init() {
Jamal Carvalho6cdc0192021-11-03 23:33:31 +000059 addMirrored("go", coordinatorCanBuild, noDash, enableCSR("golang-org"))
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +000060 addMirrored("dl", importPath("golang.org/dl"), coordinatorCanBuild)
Dmitri Shuralyovcd15c8b2021-02-04 12:51:44 -050061 addMirrored("gddo", importPath("github.com/golang/gddo"), archivedOnGitHub)
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +000062 addMirrored("gofrontend")
63 addMirrored("proposal")
64 addMirrored("sublime-build")
65 addMirrored("sublime-config")
66
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000067 x("arch")
Brad Fitzpatrick24401732019-12-13 16:46:49 +000068 x("benchmarks", desc("benchmarks to measure Go as it is developed"))
Dmitri Shuralyov8adac882021-06-02 19:29:35 -040069 x("blog", noDash)
Brad Fitzpatrick24401732019-12-13 16:46:49 +000070 x("build", desc("build.golang.org's implementation"))
71 x("crypto", desc("additional cryptography packages"))
72 x("debug", desc("an experimental debugger for Go"))
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000073 x("example", noDash)
Brad Fitzpatrick24401732019-12-13 16:46:49 +000074 x("exp", desc("experimental and deprecated packages (handle with care; may change without warning)"))
75 x("image", desc("additional imaging packages"))
Daniel Martí58cc22b2021-05-08 22:34:43 +010076 x("lint", noDash, archivedOnGitHub)
Brad Fitzpatrick24401732019-12-13 16:46:49 +000077 x("mobile", desc("experimental support for Go on mobile platforms"))
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000078 x("mod")
Brad Fitzpatrick24401732019-12-13 16:46:49 +000079 x("net", desc("additional networking packages"))
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000080 x("oauth2")
Brad Fitzpatrick24401732019-12-13 16:46:49 +000081 x("perf", desc("packages and tools for performance measurement, storage, and analysis"))
Jamal Carvalhocca73452021-11-03 23:36:05 +000082 x("pkgsite", desc("home of the pkg.go.dev website"), noBuildAndNoDash, enableCSR("go-discovery"))
Jamal Carvalho6cdc0192021-11-03 23:33:31 +000083 x("playground", noDash, enableCSR("golang-org"))
Brad Fitzpatrick24401732019-12-13 16:46:49 +000084 x("review", desc("a tool for working with Gerrit code reviews"))
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000085 x("scratch", noDash)
Brad Fitzpatrick24401732019-12-13 16:46:49 +000086 x("sync", desc("additional concurrency primitives"))
87 x("sys", desc("packages for making system calls"))
Dmitri Shuralyov0e191722021-11-23 10:46:45 -050088 x("talks", noDash)
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000089 x("term")
Brad Fitzpatrick24401732019-12-13 16:46:49 +000090 x("text", desc("packages for working with text"))
91 x("time", desc("additional time packages"))
92 x("tools", desc("godoc, goimports, gorename, and other tools"))
Dmitri Shuralyov8adac882021-06-02 19:29:35 -040093 x("tour", noDash)
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000094 x("vgo", noDash)
Julie Qiuc046fca2021-11-01 15:34:42 -040095 x("vuln", desc("code for the Go Vulnerability Database"))
Jamal Carvalho6cdc0192021-11-03 23:33:31 +000096 x("vulndb", desc("reports for the Go Vulnerability Database"), enableCSR("golang-org"))
97 x("website", desc("home of the golang.org and go.dev websites"), enableCSR("golang-org"))
Brad Fitzpatricke2b91412019-11-25 06:11:04 +000098 x("xerrors", noDash)
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +000099
100 add(&Repo{GoGerritProject: "gollvm"})
101 add(&Repo{GoGerritProject: "grpc-review"})
102
103 add(&Repo{
104 GoGerritProject: "protobuf",
105 MirrorToGitHub: true,
Dmitri Shuralyovc6b82d52020-03-02 15:15:29 -0500106 ImportPath: "google.golang.org/protobuf",
Heschi Kreinick27cb3d82021-06-02 17:48:15 -0400107 GitHubRepo: "protocolbuffers/protobuf-go",
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000108 })
Dmitri Shuralyov52506642020-03-06 12:29:13 -0500109
110 add(&Repo{
111 GoGerritProject: "vscode-go",
112 MirrorToGitHub: true,
Heschi Kreinick27cb3d82021-06-02 17:48:15 -0400113 GitHubRepo: "golang/vscode-go",
Dmitri Shuralyov52506642020-03-06 12:29:13 -0500114 })
Brad Fitzpatricke2b91412019-11-25 06:11:04 +0000115}
116
117type modifyRepo func(*Repo)
118
119// noDash is an option to the x func that marks the repo as hidden on
120// the https://build.golang.org/ dashboard.
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000121func noDash(r *Repo) { r.showOnDashboard = false }
122
Dmitri Shuralyovfd3ecdd2020-03-09 21:22:09 +0000123func noBuildAndNoDash(r *Repo) { r.CoordinatorCanBuild, r.showOnDashboard = false, false }
124
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000125func coordinatorCanBuild(r *Repo) { r.CoordinatorCanBuild = true }
126
Dmitri Shuralyovcd15c8b2021-02-04 12:51:44 -0500127func archivedOnGitHub(r *Repo) {
128 // When a repository is archived on GitHub, trying to push
129 // to it will fail. So don't mirror.
130 r.MirrorToGitHub = false
131}
132
Jamal Carvalho6cdc0192021-11-03 23:33:31 +0000133func enableCSR(p string) modifyRepo { return func(r *Repo) { r.MirrorToCSRProject = p } }
Heschi Kreinickc5421122021-06-03 16:43:04 -0400134
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000135func importPath(v string) modifyRepo { return func(r *Repo) { r.ImportPath = v } }
136
Brad Fitzpatrick24401732019-12-13 16:46:49 +0000137func desc(v string) modifyRepo { return func(r *Repo) { r.WebsiteDesc = v } }
138
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000139// addMirrored adds a repo that's on Gerrit and mirrored to GitHub.
140func addMirrored(proj string, opts ...modifyRepo) {
141 repo := &Repo{
142 GoGerritProject: proj,
143 MirrorToGitHub: true,
Heschi Kreinick27cb3d82021-06-02 17:48:15 -0400144 GitHubRepo: "golang/" + proj,
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000145 }
146 for _, o := range opts {
147 o(repo)
148 }
149 add(repo)
150}
Brad Fitzpatricke2b91412019-11-25 06:11:04 +0000151
152// x adds a golang.org/x repo.
153func x(proj string, opts ...modifyRepo) {
154 repo := &Repo{
155 GoGerritProject: proj,
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000156 MirrorToGitHub: true,
Brad Fitzpatricke2b91412019-11-25 06:11:04 +0000157 CoordinatorCanBuild: true,
158 ImportPath: "golang.org/x/" + proj,
Heschi Kreinick27cb3d82021-06-02 17:48:15 -0400159 GitHubRepo: "golang/" + proj,
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000160 showOnDashboard: true,
Brad Fitzpatricke2b91412019-11-25 06:11:04 +0000161 }
162 for _, o := range opts {
163 o(repo)
164 }
165 add(repo)
166}
167
168func add(r *Repo) {
Jamal Carvalho6cdc0192021-11-03 23:33:31 +0000169 if (r.MirrorToCSRProject != "" || r.MirrorToGitHub || r.showOnDashboard) && r.GoGerritProject == "" {
Heschi Kreinick9477c7e2021-06-02 09:59:40 -0400170 panic(fmt.Sprintf("project %+v sets feature(s) that require a GoGerritProject, but has none", r))
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000171 }
Heschi Kreinick27cb3d82021-06-02 17:48:15 -0400172 if r.MirrorToGitHub && r.GitHubRepo == "" {
Heschi Kreinick9477c7e2021-06-02 09:59:40 -0400173 panic(fmt.Sprintf("project %+v has MirrorToGitHub but no gitHubRepo", r))
174 }
175 if r.showOnDashboard && !r.CoordinatorCanBuild {
176 panic(fmt.Sprintf("project %+v is showOnDashboard but not marked buildable by coordinator", r))
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000177 }
178
Brad Fitzpatricke2b91412019-11-25 06:11:04 +0000179 if p := r.GoGerritProject; p != "" {
180 if _, dup := ByGerritProject[p]; dup {
181 panic(fmt.Sprintf("duplicate Gerrit project %q in %+v", p, r))
182 }
183 ByGerritProject[p] = r
184 }
185 if p := r.ImportPath; p != "" {
186 if _, dup := ByImportPath[p]; dup {
187 panic(fmt.Sprintf("duplicate import path %q in %+v", p, r))
188 }
189 ByImportPath[p] = r
190 }
191}
Brad Fitzpatrick6e1808a2019-12-09 06:08:22 +0000192
193// ShowOnDashboard reports whether this repo should show up on build.golang.org
194// in the list of repos at bottom.
195//
196// When this returns true, r.GoGerritProject is guaranteed to be non-empty.
197func (r *Repo) ShowOnDashboard() bool { return r.showOnDashboard }