golang.org/x/build@v0.0.0-20240506185731-218518f32b70/repos/repos.go (about)

     1  // 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.
     6  package repos
     7  
     8  import "fmt"
     9  
    10  type Repo struct {
    11  	// GoGerritProject, if non-empty, is the repo's Gerrit project
    12  	// name, such as "go", "net", or "sys".
    13  	GoGerritProject string
    14  
    15  	// ImportPath is the repo's import path.
    16  	// It is empty for the main Go repo and other repos that do not
    17  	// contain Go code.
    18  	ImportPath string
    19  
    20  	// 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
    24  
    25  	// 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
    30  
    31  	// showOnDashboard is whether to show the repo on the bottom
    32  	// of build.golang.org in the repo overview section.
    33  	showOnDashboard bool
    34  
    35  	// CoordinatorCanBuild reports whether this a repo that the
    36  	// build coordinator knows how to build.
    37  	CoordinatorCanBuild bool
    38  
    39  	// GitHubRepo is the "org/repo" of where this repo exists on
    40  	// GitHub. If MirrorToGitHub is true, this is the
    41  	// destination.
    42  	GitHubRepo string
    43  
    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
    48  }
    49  
    50  // ByGerritProject maps from a Gerrit project name ("go", "net", etc)
    51  // to the Repo's information.
    52  var ByGerritProject = map[string]*Repo{ /* initialized below */ }
    53  
    54  // ByImportPath maps from an import path ("golang.org/x/net") to the
    55  // Repo's information.
    56  var ByImportPath = map[string]*Repo{ /* initialized below */ }
    57  
    58  func init() {
    59  	addMirrored("dl", importPath("golang.org/dl"), coordinatorCanBuild)
    60  	addMirrored("gddo", importPath("github.com/golang/gddo"), archivedOnGitHub)
    61  	addMirrored("go", coordinatorCanBuild, noDash, enableCSR("golang-org"))
    62  	addMirrored("gofrontend")
    63  	addMirrored("govulncheck-action")
    64  	addMirrored("proposal")
    65  	addMirrored("sublime-build")
    66  	addMirrored("sublime-config")
    67  	addMirrored("wiki")
    68  
    69  	x("arch")
    70  	x("benchmarks", desc("benchmarks to measure Go as it is developed"))
    71  	x("blog", noDash)
    72  	x("build", desc("build.golang.org's implementation"))
    73  	x("crypto", desc("additional cryptography packages"))
    74  	x("debug", desc("an experimental debugger for Go"))
    75  	x("example", noDash)
    76  	x("exp", desc("experimental and deprecated packages (handle with care; may change without warning)"))
    77  	x("image", desc("additional imaging packages"))
    78  	x("lint", noDash, archivedOnGitHub)
    79  	x("mobile", desc("experimental support for Go on mobile platforms"))
    80  	x("mod")
    81  	x("net", desc("additional networking packages"))
    82  	x("oauth2")
    83  	x("perf", desc("packages and tools for performance measurement, storage, and analysis"))
    84  	x("pkgsite", desc("home of the pkg.go.dev website"), enableCSR("go-discovery"))
    85  	x("pkgsite-metrics", desc("code for serving pkg.go.dev/metrics"), enableCSR("go-ecosystem"))
    86  	x("playground", noDash, enableCSR("golang-org"))
    87  	x("review", desc("a tool for working with Gerrit code reviews"))
    88  	x("scratch", noDash)
    89  	x("sync", desc("additional concurrency primitives"))
    90  	x("sys", desc("packages for making system calls"))
    91  	x("talks", noDash)
    92  	x("telemetry", desc("telemetry server code and libraries"), enableCSR("go-telemetry"))
    93  	x("term")
    94  	x("text", desc("packages for working with text"))
    95  	x("time", desc("additional time packages"))
    96  	x("tools", desc("godoc, goimports, gorename, and other tools"))
    97  	x("tour", noDash)
    98  	x("vgo", noDash)
    99  	x("vuln", desc("code for the Go Vulnerability Database"))
   100  	x("vulndb", desc("reports for the Go Vulnerability Database"), enableCSR("go-vuln"))
   101  	x("website", desc("home of the golang.org and go.dev websites"), enableCSR("golang-org"))
   102  	x("xerrors", noDash)
   103  
   104  	add(&Repo{GoGerritProject: "gollvm"})
   105  	add(&Repo{GoGerritProject: "grpc-review"})
   106  
   107  	add(&Repo{
   108  		GoGerritProject: "protobuf",
   109  		MirrorToGitHub:  true,
   110  		ImportPath:      "google.golang.org/protobuf",
   111  		GitHubRepo:      "protocolbuffers/protobuf-go",
   112  	})
   113  
   114  	add(&Repo{
   115  		GoGerritProject:    "vscode-go",
   116  		MirrorToGitHub:     true,
   117  		GitHubRepo:         "golang/vscode-go",
   118  		WebsiteDesc:        "Go extension for Visual Studio Code",
   119  		MirrorToCSRProject: "go-vscode-go",
   120  	})
   121  }
   122  
   123  type modifyRepo func(*Repo)
   124  
   125  // noDash is an option to the x func that marks the repo as hidden on
   126  // the https://build.golang.org/ dashboard.
   127  func noDash(r *Repo) { r.showOnDashboard = false }
   128  
   129  func coordinatorCanBuild(r *Repo) { r.CoordinatorCanBuild = true }
   130  
   131  func archivedOnGitHub(r *Repo) {
   132  	// When a repository is archived on GitHub, trying to push
   133  	// to it will fail. So don't mirror.
   134  	r.MirrorToGitHub = false
   135  }
   136  
   137  func enableCSR(p string) modifyRepo { return func(r *Repo) { r.MirrorToCSRProject = p } }
   138  
   139  func importPath(v string) modifyRepo { return func(r *Repo) { r.ImportPath = v } }
   140  
   141  func desc(v string) modifyRepo { return func(r *Repo) { r.WebsiteDesc = v } }
   142  
   143  // addMirrored adds a repo that's on Gerrit and mirrored to GitHub.
   144  func addMirrored(proj string, opts ...modifyRepo) {
   145  	repo := &Repo{
   146  		GoGerritProject: proj,
   147  		MirrorToGitHub:  true,
   148  		GitHubRepo:      "golang/" + proj,
   149  	}
   150  	for _, o := range opts {
   151  		o(repo)
   152  	}
   153  	add(repo)
   154  }
   155  
   156  // x adds a golang.org/x repo.
   157  func x(proj string, opts ...modifyRepo) {
   158  	repo := &Repo{
   159  		GoGerritProject:     proj,
   160  		MirrorToGitHub:      true,
   161  		CoordinatorCanBuild: true,
   162  		ImportPath:          "golang.org/x/" + proj,
   163  		GitHubRepo:          "golang/" + proj,
   164  		showOnDashboard:     true,
   165  	}
   166  	for _, o := range opts {
   167  		o(repo)
   168  	}
   169  	add(repo)
   170  }
   171  
   172  func add(r *Repo) {
   173  	if (r.MirrorToCSRProject != "" || r.MirrorToGitHub || r.showOnDashboard) && r.GoGerritProject == "" {
   174  		panic(fmt.Sprintf("project %+v sets feature(s) that require a GoGerritProject, but has none", r))
   175  	}
   176  	if r.MirrorToGitHub && r.GitHubRepo == "" {
   177  		panic(fmt.Sprintf("project %+v has MirrorToGitHub but no gitHubRepo", r))
   178  	}
   179  	if r.showOnDashboard && !r.CoordinatorCanBuild {
   180  		panic(fmt.Sprintf("project %+v is showOnDashboard but not marked buildable by coordinator", r))
   181  	}
   182  
   183  	if p := r.GoGerritProject; p != "" {
   184  		if _, dup := ByGerritProject[p]; dup {
   185  			panic(fmt.Sprintf("duplicate Gerrit project %q in %+v", p, r))
   186  		}
   187  		ByGerritProject[p] = r
   188  	}
   189  	if p := r.ImportPath; p != "" {
   190  		if _, dup := ByImportPath[p]; dup {
   191  			panic(fmt.Sprintf("duplicate import path %q in %+v", p, r))
   192  		}
   193  		ByImportPath[p] = r
   194  	}
   195  }
   196  
   197  // ShowOnDashboard reports whether this repo should show up on build.golang.org
   198  // in the list of repos at bottom.
   199  //
   200  // When this returns true, r.GoGerritProject is guaranteed to be non-empty.
   201  func (r *Repo) ShowOnDashboard() bool { return r.showOnDashboard }