Skip to content

Latest commit

 

History

History
executable file
·
136 lines (90 loc) · 11 KB

extensions.md

File metadata and controls

executable file
·
136 lines (90 loc) · 11 KB

go_deps

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.archive_override(patch_strip, patches, path, sha256, strip_prefix, urls)
go_deps.config(check_direct_dependencies, debug_mode, go_env)
go_deps.from_file(fail_on_version_conflict, go_mod, go_work)
go_deps.gazelle_override(build_extra_args, build_file_generation, directives, path)
go_deps.gazelle_default_attributes(build_extra_args, build_file_generation, directives)
go_deps.module(build_file_proto_mode, build_naming_convention, indirect, local_path, path, sum,
               version)
go_deps.module_override(patch_strip, patches, path)

TAG CLASSES

archive_override

Override the default source location on a given Go module in this extension.

Attributes

Name Description Type Mandatory Default
patch_strip The number of leading path segments to be stripped from the file name in the patches. Integer optional 0
patches A list of patches to apply to the repository after gazelle runs. List of labels optional []
path The Go module path for the repository to be overridden.

This module path must be defined by other tags in this extension within this Bazel module.
String required
sha256 If the repository is downloaded via HTTP (urls is set), this is the SHA-256 sum of the downloaded archive. When set, Bazel will verify the archive against this sum before extracting it. String optional ""
strip_prefix If the repository is downloaded via HTTP (urls is set), this is a directory prefix to strip. See [http_archive.strip_prefix]. String optional ""
urls A list of HTTP(S) URLs where an archive containing the project can be downloaded. Bazel will attempt to download from the first URL; the others are mirrors. List of strings optional []

config

Configures the general behavior of the go_deps extension.

Only the root module's config tag is used.

Attributes

Name Description Type Mandatory Default
check_direct_dependencies The way in which warnings about version mismatches for direct dependencies and Go modules that are also Bazel modules are reported. String optional ""
debug_mode Whether or not to print stdout and stderr messages from gazelle Boolean optional False
go_env The environment variables to use when fetching Go dependencies or running the @rules_go//go tool. Dictionary: String -> String optional {}

from_file

Imports Go module dependencies from either a go.mod file or a go.work file.

All direct and indirect dependencies of the specified module will be imported, but only direct dependencies should be imported into the scope of the using module via use_repo calls. Use bazel mod tidy to update these calls automatically.

Attributes

Name Description Type Mandatory Default
fail_on_version_conflict Fail if duplicate modules have different versions Boolean optional True
go_mod - Label optional None
go_work - Label optional None

gazelle_override

Override Gazelle's behavior on a given Go module defined by other tags in this extension.

Attributes

Name Description Type Mandatory Default
build_extra_args A list of additional command line arguments to pass to Gazelle when generating build files. List of strings optional []
build_file_generation One of "auto", "on" (default), "off", "clean".

Whether Gazelle should generate build files for the Go module.

Although "auto" is the default globally for build_file_generation, if a "gazelle_override" or "gazelle_default_attributes" tag is present for a Go module, the "build_file_generation" attribute will default to "on" since these tags indicate the presence of "directives" or "build_extra_args".

In "auto" mode, Gazelle will run if there is no build file in the Go module's root directory.

In "clean" mode, Gazelle will first remove any existing build files.
String optional "on"
directives Gazelle configuration directives to use for this Go module's external repository.

Each directive uses the same format as those that Gazelle accepts as comments in Bazel source files, with the directive name followed by optional arguments separated by whitespace.
List of strings optional []
path The Go module path for the repository to be overridden.

This module path must be defined by other tags in this extension within this Bazel module.
String required

gazelle_default_attributes

Override Gazelle's default attribute values for all modules in this extension.

Attributes

Name Description Type Mandatory Default
build_extra_args A list of additional command line arguments to pass to Gazelle when generating build files. List of strings optional []
build_file_generation One of "auto", "on" (default), "off", "clean".

Whether Gazelle should generate build files for the Go module.

Although "auto" is the default globally for build_file_generation, if a "gazelle_override" or "gazelle_default_attributes" tag is present for a Go module, the "build_file_generation" attribute will default to "on" since these tags indicate the presence of "directives" or "build_extra_args".

In "auto" mode, Gazelle will run if there is no build file in the Go module's root directory.

In "clean" mode, Gazelle will first remove any existing build files.
String optional "on"
directives Gazelle configuration directives to use for this Go module's external repository.

Each directive uses the same format as those that Gazelle accepts as comments in Bazel source files, with the directive name followed by optional arguments separated by whitespace.
List of strings optional []

module

Declare a single Go module dependency. Prefer using from_file instead.

Attributes

Name Description Type Mandatory Default
build_file_proto_mode Removed, do not use String optional ""
build_naming_convention Removed, do not use String optional ""
indirect Whether this Go module is an indirect dependency. Boolean optional False
local_path For when a module is replaced by one residing in a local directory path String optional ""
path The module path. String required
sum - String optional ""
version - String required

module_override

Apply patches to a given Go module defined by other tags in this extension.

Attributes

Name Description Type Mandatory Default
patch_strip The number of leading path segments to be stripped from the file name in the patches. Integer optional 0
patches A list of patches to apply to the repository after gazelle runs. List of labels optional []
path The Go module path for the repository to be overridden.

This module path must be defined by other tags in this extension within this Bazel module.
String required