Skip to content

Commit

Permalink
Merge pull request #18 from tweag/modules
Browse files Browse the repository at this point in the history
"Modularize" rules_sh
  • Loading branch information
mergify[bot] authored Jan 13, 2022
2 parents 670efdc + 6d5e537 commit ce44922
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
platforms:
centos7:
build_targets:
- '@rules_sh//...'
debian10:
build_targets:
- '@rules_sh//...'
macos:
build_targets:
- '@rules_sh//...'
ubuntu2004:
build_targets:
- '@rules_sh//...'
windows:
build_targets:
- '@rules_sh//...'
10 changes: 10 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
bzlmod: [workspace, module]
defaults:
run:
shell: bash
Expand All @@ -27,6 +28,15 @@ jobs:
machine api.github.com
password ${{ secrets.GITHUB_TOKEN }}
EOF
if [[ ${{ matrix.bzlmod }} == module ]]; then
# Test with bzlmod enabled.
# Requires https://github.com/bazelbuild/bazel/commit/302971e1b3d803069ac949c0085c0d2a3916c8ab,
# see https://github.com/bazelbuild/bazel-central-registry/pull/47#issuecomment-998883652
echo USE_BAZEL_VERSION=302971e1b3d803069ac949c0085c0d2a3916c8ab >.bazeliskrc
cat >>.bazelrc.local <<-EOF
build --experimental_enable_bzlmod
EOF
fi
- name: Build & Test
run: |
if [[ ${{ runner.os }} == Windows ]]; then
Expand Down
30 changes: 28 additions & 2 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Cutting a new release

- Create a dedicated branch: `release-<version>` (e.g. `release-0.2.0`)
- Check the changes since the last release by
* Create a dedicated branch: `release-<version>` (e.g. `release-0.2.0`)
* Check the changes since the last release by
[comparing the heads](https://github.com/tweag/rules_sh/compare/v0.2.0...HEAD),
add anything relevant to `CHANGELOG.md`,
and update the version heading and unreleased heading in `CHANGELOG.md`.
Expand All @@ -17,3 +17,29 @@
and calling `sha256sum` on it.
* Update the release notes with a workspace setup section for the new version,
such as [this example](https://github.com/tweag/rules_sh/releases/tag/v0.2.0)
* Add the new version to the Bazel Central Registry as described below

## Add a new version to the Bazel Central Registry

* Follow the instructions given in the [README][bcr-add] to add a new version
of this module. Use the following input file to `add_module.py` for
reference - don't forget to update the version and dependencies:
```
{
"build_file": null,
"build_targets": [],
"compatibility_level": "0",
"deps": [["bazel_skylib", "1.0.3"], ["platforms", "0.0.4"]],
"module_dot_bazel": "path/to/rules_sh/MODULE.bazel",
"name": "rules_sh",
"patch_strip": 1,
"patches": [],
"presubmit_yml": "path/to/rules_sh/.bazelci/presubmit.yml",
"strip_prefix": "rules_sh-0.2.0",
"test_targets": [],
"url": "https://github.com/tweag/rules_sh/archive/refs/tags/v0.2.0.tar.gz",
"version": "0.2.0"
}
```

[bcr-add]: https://github.com/bazelbuild/bazel-central-registry#module-contributor
11 changes: 11 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module(
name = "rules_sh",
version = "0.2.0",
compatibility_level = 0,
toolchains_to_register = ["@local_posix_config//:local_posix_toolchain"],
)
bazel_dep(name = "bazel_skylib", version = "1.0.3")
bazel_dep(name = "platforms", version = "0.0.4")

sh_configure = use_extension("@rules_sh//bzlmod:extensions.bzl", "sh_configure")
use_repo(sh_configure, "local_posix_config")
Empty file added bzlmod/BUILD.bazel
Empty file.
6 changes: 6 additions & 0 deletions bzlmod/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("//sh:posix.bzl", "sh_posix_configure")

def _sh_configure_impl(ctx):
sh_posix_configure(register = False)

sh_configure = module_extension(implementation = _sh_configure_impl)
7 changes: 4 additions & 3 deletions sh/posix.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ sh_posix_toolchain = rule(
"cmds": attr.string_dict(
doc = "dict where keys are command names and values are paths",
mandatory = True,
)
),
},
doc = """
A toolchain capturing standard Unix shell commands.
Expand Down Expand Up @@ -339,7 +339,7 @@ _sh_posix_config = repository_rule(
implementation = _sh_posix_config_impl,
)

def sh_posix_configure(name = "local_posix_config"):
def sh_posix_configure(name = "local_posix_config", register = True):
"""Autodetect local Unix commands.
Scans the environment (`$PATH`) for standard shell commands, generates a
Expand All @@ -350,7 +350,8 @@ def sh_posix_configure(name = "local_posix_config"):
`POSIX_MAKE=/usr/bin/gmake` will override the make command.
"""
_sh_posix_config(name = name)
native.register_toolchains("@{}//:local_posix_toolchain".format(name))
if register:
native.register_toolchains("@{}//:local_posix_toolchain".format(name))

posix = struct(
commands = _commands,
Expand Down

0 comments on commit ce44922

Please sign in to comment.