Development
Gazelle extensions are written in Go.
See the Gazelle documentation for more information on extending Gazelle.
Dependencies
If you add new Go dependencies to the plugin source code, you need to “tidy”
the go.mod file. After changing that file, run go mod tidy or
bazel run @go_sdk//:bin/go -- mod tidy to update the go.mod and go.sum
files. Then run bazel run //:gazelle_update_repos to have gazelle add the
new dependencies to the deps.bzl file. The deps.bzl file is used as
defined in our /WORKSPACE to include the external repos Bazel loads Go
dependencies from.
Then after editing Go code, run bazel run //:gazelle to generate/update
the rules in the BUILD.bazel files in our repo.
Tests
See also
To run tests, cd into the gazelle directory and run
bazel test //....
Test cases are found at gazelle/python/testdata. To make a new test case, create a directory in that folder with the following files:
README.mdwith a short blurb describing the test case(s).test.yaml, either empty (with just the docstart---line) or with the expectedstderrand exit codes of the test case.and empty
WORKSPACEfile
You will also need BUILD.in and BUILD.out files somewhere within the test
case directory. These can be in the test case root, in subdirectories, or
both.
BUILD.infiles are populated with the “before” information - typically things like Gazelle directives or pre-existing targets. This is how theBUILD.bazelfile looks before running Gazelle.BUILD.outfiles are the expected result after running Gazelle within the test case.
Tip
The easiest way to create a new test is to look at one of the existing test cases.
The source code for running tests is gazelle/python/python_test.go.