1*bcb5dc79SHONG Yifan# Skylib Maintainer's Guide 2*bcb5dc79SHONG Yifan 3*bcb5dc79SHONG Yifan## The Parts of Skylib 4*bcb5dc79SHONG Yifan 5*bcb5dc79SHONG Yifan* `bzl_library.bzl` - used by almost all rule sets, and thus requiring 6*bcb5dc79SHONG Yifan especial attention to maintaining backwards compatibility. Ideally, it ought 7*bcb5dc79SHONG Yifan to be moved out of Skylib and and into Bazel's bundled `@bazel_tools` repo 8*bcb5dc79SHONG Yifan (see https://github.com/bazelbuild/bazel-skylib/issues/127). 9*bcb5dc79SHONG Yifan* Test libraries - `rules/analysis_test.bzl`, `rules/build_test.bzl`, 10*bcb5dc79SHONG Yifan `lib/unittest.bzl`; these are under more active development than the rest of 11*bcb5dc79SHONG Yifan Skylib, because we want to provide rule authors with a good testing story. 12*bcb5dc79SHONG Yifan Ideally, these ought to be moved out of Skylib and evolved at a faster pace. 13*bcb5dc79SHONG Yifan* A kitchen sink of utility modules (everything else). Formerly, these 14*bcb5dc79SHONG Yifan features were piled on in a rather haphazard manner. For any new additions, 15*bcb5dc79SHONG Yifan we want to be more conservative: add a feature only if it is widely needed 16*bcb5dc79SHONG Yifan (or was already independently implemented in multiple rule sets), if the 17*bcb5dc79SHONG Yifan interface is unimpeachable, if level of abstraction is not shallow, and the 18*bcb5dc79SHONG Yifan implementation is efficient. 19*bcb5dc79SHONG Yifan 20*bcb5dc79SHONG Yifan## PR Review Standards 21*bcb5dc79SHONG Yifan 22*bcb5dc79SHONG YifanBecause Skylib is so widely used, breaking backwards compatibility can cause 23*bcb5dc79SHONG Yifanwidespread pain, and shouldn't be done lightly. Therefore: 24*bcb5dc79SHONG Yifan 25*bcb5dc79SHONG Yifan1. In the first place, avoid adding insufficiently thought out, insufficiently 26*bcb5dc79SHONG Yifan tested features which will later need to be replaced in a 27*bcb5dc79SHONG Yifan backwards-incompatible manner. See the criteria in README.md. 28*bcb5dc79SHONG Yifan2. Given a choice between breaking backwards compatibility and keeping it, try 29*bcb5dc79SHONG Yifan to keep backwards compatibility. For example, if adding a new argument to a 30*bcb5dc79SHONG Yifan function, add it to the end of the argument list, so that existing callers' 31*bcb5dc79SHONG Yifan positional arguments continue to work. 32*bcb5dc79SHONG Yifan3. Keep Skylib out-of-the-box compatible with the current stable Bazel release 33*bcb5dc79SHONG Yifan (ideally - with two most recent stable releases). 34*bcb5dc79SHONG Yifan * For example, when adding a new function which calls the new 35*bcb5dc79SHONG Yifan `native.foobar()` method which was introduced in the latest Bazel 36*bcb5dc79SHONG Yifan pre-release or is gated behind an `--incompatible` flag, use an `if 37*bcb5dc79SHONG Yifan hasattr(native, "foobar")` check to keep the rest of your module (which 38*bcb5dc79SHONG Yifan doesn't need `native.foobar()`) working even when `native.foobar()` is 39*bcb5dc79SHONG Yifan not available. 40*bcb5dc79SHONG Yifan 41*bcb5dc79SHONG YifanIn addition, make sure that new code is documented and tested. 42*bcb5dc79SHONG Yifan 43*bcb5dc79SHONG YifanIf a PR changes any docstring in an existing module, the corresponding 44*bcb5dc79SHONG Yifan`stardoc_with_diff_test` in `docs` will fail. To fix the test, ask the PR 45*bcb5dc79SHONG Yifanauthor to run `bazel run //docs:update`. 46*bcb5dc79SHONG Yifan 47*bcb5dc79SHONG YifanIf a PR adds a new module, make sure that the PR also adds a corresponding 48*bcb5dc79SHONG Yifan`stardoc_with_diff_test` target in `docs/BUILD` and a corresponding `*doc.md` 49*bcb5dc79SHONG Yifanfile under `docs` (generated by `bazel run //docs:update`). 50*bcb5dc79SHONG Yifan 51*bcb5dc79SHONG Yifan## Making a New Release 52*bcb5dc79SHONG Yifan 53*bcb5dc79SHONG Yifan1. Update CHANGELOG.md at the top. You may want to use the following template: 54*bcb5dc79SHONG Yifan 55*bcb5dc79SHONG Yifan-------------------------------------------------------------------------------- 56*bcb5dc79SHONG Yifan 57*bcb5dc79SHONG Yifan``` 58*bcb5dc79SHONG Yifan# Release $VERSION 59*bcb5dc79SHONG Yifan 60*bcb5dc79SHONG Yifan**New Features** 61*bcb5dc79SHONG Yifan 62*bcb5dc79SHONG Yifan- Feature 63*bcb5dc79SHONG Yifan- Feature 64*bcb5dc79SHONG Yifan 65*bcb5dc79SHONG Yifan**Incompatible Changes** 66*bcb5dc79SHONG Yifan 67*bcb5dc79SHONG Yifan- Change 68*bcb5dc79SHONG Yifan- Change 69*bcb5dc79SHONG Yifan 70*bcb5dc79SHONG Yifan**Contributors** 71*bcb5dc79SHONG Yifan 72*bcb5dc79SHONG YifanName 1, Name 2, Name 3 (alphabetically from `git log`) 73*bcb5dc79SHONG Yifan``` 74*bcb5dc79SHONG Yifan 75*bcb5dc79SHONG Yifan-------------------------------------------------------------------------------- 76*bcb5dc79SHONG Yifan 77*bcb5dc79SHONG Yifan2. Bump `version` in version.bzl, MODULE.bazel, *and* gazelle/MODULE.bazel to 78*bcb5dc79SHONG Yifan the new version. 79*bcb5dc79SHONG Yifan TODO(#386): add a test to make sure all the versions are in sync. 80*bcb5dc79SHONG Yifan3. Ensure that the commits for steps 1 and 2 have been merged. All further 81*bcb5dc79SHONG Yifan steps must be performed on a single, known-good git commit. 82*bcb5dc79SHONG Yifan4. `bazel build //distribution` 83*bcb5dc79SHONG Yifan5. Copy the `bazel-skylib-$VERSION.tar.gz` and 84*bcb5dc79SHONG Yifan `bazel-skylib-gazelle-plugin-$VERSION.tar.gz` tarballs to the mirror (you'll 85*bcb5dc79SHONG Yifan need Bazel developer gcloud credentials; assuming you are a Bazel developer, 86*bcb5dc79SHONG Yifan you can obtain them via `gcloud init`): 87*bcb5dc79SHONG Yifan 88*bcb5dc79SHONG Yifan```bash 89*bcb5dc79SHONG Yifangsutil cp bazel-bin/distribution/bazel-skylib{,-gazelle-plugin}-$VERSION.tar.gz gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/ 90*bcb5dc79SHONG Yifangsutil setmeta -h "Cache-Control: public, max-age=31536000" gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib{,-gazelle-plugin}-$VERSION.tar.gz 91*bcb5dc79SHONG Yifan``` 92*bcb5dc79SHONG Yifan 93*bcb5dc79SHONG Yifan6. Obtain checksums for release notes: 94*bcb5dc79SHONG Yifan 95*bcb5dc79SHONG Yifan```bash 96*bcb5dc79SHONG Yifansha256sum bazel-bin/distribution/bazel-skylib-$VERSION.tar.gz 97*bcb5dc79SHONG Yifansha256sum bazel-bin/distribution/bazel-skylib-gazelle-plugin-$VERSION.tar.gz 98*bcb5dc79SHONG Yifan```` 99*bcb5dc79SHONG Yifan 100*bcb5dc79SHONG Yifan7. Draft a new release with a new tag named $VERSION in github. Attach 101*bcb5dc79SHONG Yifan `bazel-skylib-$VERSION.tar.gz` and 102*bcb5dc79SHONG Yifan `bazel-skylib-gazelle-plugin-$VERSION.tar.gz` to the release. For the 103*bcb5dc79SHONG Yifan release notes, use the CHANGELOG.md entry plus the following template: 104*bcb5dc79SHONG Yifan 105*bcb5dc79SHONG Yifan-------------------------------------------------------------------------------- 106*bcb5dc79SHONG Yifan 107*bcb5dc79SHONG Yifan**WORKSPACE setup** 108*bcb5dc79SHONG Yifan 109*bcb5dc79SHONG Yifan``` 110*bcb5dc79SHONG Yifanload("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 111*bcb5dc79SHONG Yifan 112*bcb5dc79SHONG Yifanhttp_archive( 113*bcb5dc79SHONG Yifan name = "bazel_skylib", 114*bcb5dc79SHONG Yifan sha256 = "$SHA256SUM", 115*bcb5dc79SHONG Yifan urls = [ 116*bcb5dc79SHONG Yifan "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz", 117*bcb5dc79SHONG Yifan "https://github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz", 118*bcb5dc79SHONG Yifan ], 119*bcb5dc79SHONG Yifan) 120*bcb5dc79SHONG Yifan 121*bcb5dc79SHONG Yifanload("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") 122*bcb5dc79SHONG Yifan 123*bcb5dc79SHONG Yifanbazel_skylib_workspace() 124*bcb5dc79SHONG Yifan``` 125*bcb5dc79SHONG Yifan 126*bcb5dc79SHONG Yifan***Additional WORKSPACE setup for the Gazelle plugin*** 127*bcb5dc79SHONG Yifan 128*bcb5dc79SHONG Yifan```starlark 129*bcb5dc79SHONG Yifanhttp_archive( 130*bcb5dc79SHONG Yifan name = "bazel_skylib_gazelle_plugin", 131*bcb5dc79SHONG Yifan sha256 = "$SHA256SUM_GAZELLE_PLUGIN", 132*bcb5dc79SHONG Yifan urls = [ 133*bcb5dc79SHONG Yifan "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-gazelle-plugin-$VERSION.tar.gz", 134*bcb5dc79SHONG Yifan "https://github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-gazelle-plugin-$VERSION.tar.gz", 135*bcb5dc79SHONG Yifan ], 136*bcb5dc79SHONG Yifan) 137*bcb5dc79SHONG Yifan 138*bcb5dc79SHONG Yifanload("@bazel_skylib_gazelle_plugin//:workspace.bzl", "bazel_skylib_gazelle_plugin_workspace") 139*bcb5dc79SHONG Yifan 140*bcb5dc79SHONG Yifanbazel_skylib_gazelle_plugin_workspace() 141*bcb5dc79SHONG Yifan 142*bcb5dc79SHONG Yifanload("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_setup") 143*bcb5dc79SHONG Yifan 144*bcb5dc79SHONG Yifanbazel_skylib_gazelle_plugin_setup() 145*bcb5dc79SHONG Yifan``` 146*bcb5dc79SHONG Yifan 147*bcb5dc79SHONG Yifan**Using the rules** 148*bcb5dc79SHONG Yifan 149*bcb5dc79SHONG YifanSee [the source](https://github.com/bazelbuild/bazel-skylib/tree/$VERSION). 150*bcb5dc79SHONG Yifan 151*bcb5dc79SHONG Yifan-------------------------------------------------------------------------------- 152*bcb5dc79SHONG Yifan 153*bcb5dc79SHONG Yifan8. Review a PR at [Bazel Central Registry](https://github.com/bazelbuild/bazel-central-registry) 154*bcb5dc79SHONG Yifan created by Publish-to-BCR plugin. 155*bcb5dc79SHONG Yifan 156*bcb5dc79SHONG Yifan Use https://github.com/bazelbuild/bazel-central-registry/pull/403 as the 157*bcb5dc79SHONG Yifan model. 158*bcb5dc79SHONG Yifan 159*bcb5dc79SHONG Yifan9. Once the Bazel Central Registry PR is merged, insert in the release 160*bcb5dc79SHONG Yifan description after the WORKSPACE setup section: 161*bcb5dc79SHONG Yifan 162*bcb5dc79SHONG Yifan-------------------------------------------------------------------------------- 163*bcb5dc79SHONG Yifan 164*bcb5dc79SHONG Yifan**MODULE.bazel setup** 165*bcb5dc79SHONG Yifan 166*bcb5dc79SHONG Yifan```starlark 167*bcb5dc79SHONG Yifanbazel_dep(name = "bazel_skylib", version = "$VERSION") 168*bcb5dc79SHONG Yifan``` 169*bcb5dc79SHONG Yifan 170*bcb5dc79SHONG YifanAnd for the Gazelle plugin: 171*bcb5dc79SHONG Yifan 172*bcb5dc79SHONG Yifan```starlark 173*bcb5dc79SHONG Yifanbazel_dep(name = "bazel_skylib_gazelle_plugin", version = "$VERSION", dev_dependency = True) 174*bcb5dc79SHONG Yifan``` 175*bcb5dc79SHONG Yifan 176*bcb5dc79SHONG Yifan-------------------------------------------------------------------------------- 177