|
| 1 | +# Development |
| 2 | + |
| 3 | +Gazelle extensions are written in Go. |
| 4 | + |
| 5 | +See the [Gazelle documentation][gazelle-extend] for more information on |
| 6 | +extending Gazelle. |
| 7 | + |
| 8 | +[gazelle-extend]: https://github.com/bazel-contrib/bazel-gazelle/blob/master/extend.md |
| 9 | + |
| 10 | + |
| 11 | +## Dependencies |
| 12 | + |
| 13 | +If you add new Go dependencies to the plugin source code, you need to "tidy" |
| 14 | +the go.mod file. After changing that file, run `go mod tidy` or |
| 15 | +`bazel run @go_sdk//:bin/go -- mod tidy` to update the `go.mod` and `go.sum` |
| 16 | +files. Then run `bazel run //:gazelle_update_repos` to have gazelle add the |
| 17 | +new dependencies to the `deps.bzl` file. The `deps.bzl` file is used as |
| 18 | +defined in our `/WORKSPACE` to include the external repos Bazel loads Go |
| 19 | +dependencies from. |
| 20 | + |
| 21 | +Then after editing Go code, run `bazel run //:gazelle` to generate/update |
| 22 | +the rules in the `BUILD.bazel` files in our repo. |
| 23 | + |
| 24 | + |
| 25 | +## Tests |
| 26 | + |
| 27 | +:::{seealso} |
| 28 | +{gh-path}`gazelle/python/testdata/README.md` |
| 29 | +::: |
| 30 | + |
| 31 | +To run tests, {command}`cd` into the {gh-path}`gazelle` directory and run |
| 32 | +`bazel test //...`. |
| 33 | + |
| 34 | +Test cases are found at {gh-path}`gazelle/python/testdata`. To make a new |
| 35 | +test case, create a directory in that folder with the following files: |
| 36 | + |
| 37 | ++ `README.md` with a short blurb describing the test case(s). |
| 38 | ++ `test.yaml`, either empty (with just the docstart `---` line) or with |
| 39 | + the expected `stderr` and exit codes of the test case. |
| 40 | ++ and empty `WORKSPACE` file |
| 41 | + |
| 42 | +You will also need `BUILD.in` and `BUILD.out` files somewhere within the test |
| 43 | +case directory. These can be in the test case root, in subdirectories, or |
| 44 | +both. |
| 45 | + |
| 46 | ++ `BUILD.in` files are populated with the "before" information - typically |
| 47 | + things like Gazelle directives or pre-existing targets. This is how the |
| 48 | + `BUILD.bazel` file looks before running Gazelle. |
| 49 | ++ `BUILD.out` files are the expected result after running Gazelle within |
| 50 | + the test case. |
| 51 | + |
| 52 | +:::{tip} |
| 53 | +The easiest way to create a new test is to look at one of the existing test |
| 54 | +cases. |
| 55 | +::: |
| 56 | + |
| 57 | +The source code for running tests is {gh-path}`gazelle/python/python_test.go`. |
0 commit comments