golang

package
v0.36.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 41 Imported by: 7

Documentation

Overview

Package golang provides support for Go and Go proto rules. It generates go_library, go_binary, go_test, and go_proto_library rules.

Configuration

Go rules support the flags -build_tags, -go_prefix, and -external. They also support the directives # gazelle:build_tags, # gazelle:prefix, and # gazelle:importmap_prefix. See https://github.com/bazelbuild/bazel-gazelle/blob/master/README.rst#directives for information on these.

Rule generation

Currently, Gazelle generates rules for one Go package per directory. In general, we aim to support Go code which is compatible with "go build". If there are no buildable packages, Gazelle will delete existing rules with default names. If there are multiple packages, Gazelle will pick one that matches the directory name or will print an error if no such package is found.

Gazelle names library and test rules somewhat oddly: go_default_library, and go_default_test. This is for historic reasons: before the importpath attribute was mandatory, import paths were inferred from label names. Even if we never support multiple packages in the future (we should), we should migrate away from this because it's surprising. Libraries should generally be named after their directories.

Dependency resolution

Go libraries are indexed by their importpath attribute. Gazelle attempts to resolve libraries by import path using the index, filtered using the vendoring algorithm. If an import doesn't match any known library, Gazelle guesses a name for it, locally (if the import path is under the current prefix), or in an external repository or vendor directory (depending on external mode).

Gazelle has special cases for import paths associated with proto Well Known Types and Google APIs. rules_go declares canonical rules for these.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferImportPath added in v0.21.0

func InferImportPath(c *config.Config, rel string) string

func IsStandard added in v0.19.0

func IsStandard(imp string) bool

IsStandard returns whether a package is in the standard library.

func NewLanguage

func NewLanguage() language.Language

func ResolveGo added in v0.19.0

func ResolveGo(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, imp string, from label.Label) (label.Label, error)

ResolveGo resolves a Go import path to a Bazel label, possibly using the given rule index and remote cache. Some special cases may be applied to known proto import paths, depending on the current proto mode.

This may be used directly by other language extensions related to Go (gomock). Gazelle calls Language.Resolve instead.

Types

This section is empty.

Directories

Path Synopsis
gen_std_package_list reads a text file containing a list of packages (one per line) and generates a .go file containing a set of package names.
gen_std_package_list reads a text file containing a list of packages (one per line) and generates a .go file containing a set of package names.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL