This is a collection of helper rules. These are not core to building a go binary, but are supplied to make life a little easier.
This rule has moved. See gazelle rule in the Gazelle repository.
go_embed_data(name, flatten, package, src, srcs, string, unpack, var)
Deprecated: Will be removed in rules_go 0.39.
go_embed_data
generates a .go file that contains data from a file or a
list of files. It should be consumed in the srcs list of one of the
core go rules.
Before using go_embed_data
, you must add the following snippet to your
WORKSPACE:
load("@io_bazel_rules_go//extras:embed_data_deps.bzl", "go_embed_data_dependencies")
go_embed_data_dependencies()
go_embed_data
accepts the attributes listed below.
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
flatten | If True and srcs is used, map keys are file base names instead of relative paths. |
Boolean | optional | False |
package | Go package name for the generated .go file. | String | optional | "" |
src | A single file to embed. This cannot be used at the same time as srcs . The generated file will have a variable of type []byte or string with the contents of this file. |
Label | optional | None |
srcs | A list of files to embed. This cannot be used at the same time as src . The generated file will have a variable of type map[string][]byte or map[string]string with the contents of each file. The map keys are relative paths of the files from the repository root. Keys for files in external repositories will be prefixed with "external/repo/" where "repo" is the name of the external repository. |
List of labels | optional | [] |
string | If True , the embedded data will be stored as string instead of []byte . |
Boolean | optional | False |
unpack | If True , sources are treated as archives and their contents will be stored. Supported formats are .zip and .tar |
Boolean | optional | False |
var | Name of the variable that will contain the embedded data. | String | optional | "Data" |
gomock(name, library, out, source, interfaces, package, self_package, aux_files, mockgen_tool, imports, copyright_file, mock_names, kwargs)
Calls mockgen to generates a Go file containing mocks from the given library.
If source
is given, the mocks are generated in source mode; otherwise in reflective mode.
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | the target name. | none |
library | the Go library to took for the interfaces (reflecitve mode) or source (source mode). | none |
out | the output Go file name. | none |
source | a Go file in the given library . If this is given, gomock will call mockgen in source mode to mock all interfaces in the file. |
None |
interfaces | a list of interfaces in the given library to be mocked in reflective mode. |
[] |
package | the name of the package the generated mocks should be in. If not specified, uses mockgen's default. See mockgen's -package for more information. | "" |
self_package | the full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. See mockgen's -self_package for more information. | "" |
aux_files | a map from source files to their package path. This only needed when source is provided. See mockgen's -aux_files for more information. |
{} |
mockgen_tool | the mockgen tool to run. | Label("//extras/gomock:mockgen") |
imports | dictionary of name-path pairs of explicit imports to use. See mockgen's -imports for more information. | {} |
copyright_file | optional file containing copyright to prepend to the generated contents. See mockgen's -copyright_file for more information. | None |
mock_names | dictionary of interface name to mock name pairs to change the output names of the mock objects. Mock names default to 'Mock' prepended to the name of the interface. See mockgen's -mock_names for more information. | {} |
kwargs | - |
none |