Use rules_pkg for building releases

This commit allows the creation of distributions, with 0.0.1 being the first version.
See distro/README.md for details on how to build a release.

This commit also uses a new version of the Bazel federation that contains rules_pkg 0.2.2 instead of 0.2.1.

There are still some problems with the WORKSPACE stanza that is being printed by the release notes generation script, though:
- It references a //cc:deps.bzl file, which doesn't exist. I have to modify the scripts in rules_pkg to support a flag like 'has_deps'.
- It doesn't support the Bazel federation yet, since it always tells users to download code from the rules_cc repository.
This commit is contained in:
fweikert 2019-09-13 18:24:56 +02:00
parent 42ed56d8ac
commit 29da92c66c
8 changed files with 70 additions and 4 deletions

8
BUILD
View File

@ -3,3 +3,11 @@ package(default_visibility = ["//visibility:public"])
licenses(["notice"])
exports_files(["LICENSE"])
filegroup(
name = "distribution",
srcs = glob([
"LICENSE",
]),
visibility = ["@//distro:__pkg__"],
)

View File

@ -4,9 +4,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "bazel_federation",
url = "https://github.com/bazelbuild/bazel-federation/archive/a3e140a91ea9ea25b01ad0cc6fbfcaf74f65498f.zip",
sha256 = "026149d1273a87c634d2270004865fd7474420f88d5bd6ea8d8cd71f4b0f0542",
strip_prefix = "bazel-federation-a3e140a91ea9ea25b01ad0cc6fbfcaf74f65498f",
url = "https://github.com/bazelbuild/bazel-federation/archive/ed880c20ec6112984caa47ddc6489028dbcc66e2.zip",
sha256 = "95339d2002756bdde910c93b6c42248725a7c2b61629585f08580cc4f07d1805",
strip_prefix = "bazel-federation-ed880c20ec6112984caa47ddc6489028dbcc66e2",
type = "zip",
)

View File

@ -44,3 +44,14 @@ filegroup(
],
visibility = ["//visibility:public"],
)
# TODO(aiuto): Find a way to strip this rule from the distribution tarball.
filegroup(
name = "distribution",
srcs = glob([
"**",
]),
visibility = [
"//distro:__pkg__",
],
)

View File

@ -19,6 +19,8 @@ load("@rules_cc//cc/private/rules_impl:compiler_flag.bzl", _compiler_flag = "com
_MIGRATION_TAG = "__CC_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
version = "0.0.1"
def _add_tags(attrs):
if "tags" in attrs and attrs["tags"] != None:
attrs["tags"] += [_MIGRATION_TAG]

30
distro/BUILD Normal file
View File

@ -0,0 +1,30 @@
package(
default_visibility = ["//visibility:private"],
)
load("@rules_cc//cc:defs.bzl", "version")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")
# Build the artifact to put on the github release page.
pkg_tar(
name = "rules_cc-%s" % version,
srcs = [
"//:distribution",
"//cc:distribution",
],
extension = "tar.gz",
# It is all source code, so make it read-only.
mode = "0444",
# Make it owned by root so it does not have the uid of the CI robot.
owner = "0.0",
package_dir = ".",
strip_prefix = ".",
)
print_rel_notes(
name = "relnotes",
outs = ["relnotes.txt"],
repo = "rules_cc",
version = version,
)

11
distro/README.md Normal file
View File

@ -0,0 +1,11 @@
# Package rules_cc
```bash
bazel build :relnotes
cat ../bazel-bin/distro/relnotes.txt
tar tzf ../bazel-bin/distro/rules_cc-*.tar.gz
```
- Create a new release
- Copy/paste relnotes.txt into the notes. Adjust as needed.
- Upload the tar.gz file as an artifact.

View File

@ -14,7 +14,7 @@
"""Dependencies that are needed for rules_cc tests and tools."""
load("@bazel_federation//:repositories.bzl", "bazel_skylib", "protobuf", "rules_go")
load("@bazel_federation//:repositories.bzl", "bazel_skylib", "protobuf", "rules_go", "rules_pkg")
load("@bazel_federation//:third_party_repositories.bzl", "abseil_py", "py_mock", "six", "zlib")
def rules_cc_internal_deps():
@ -22,6 +22,7 @@ def rules_cc_internal_deps():
bazel_skylib()
protobuf()
rules_go()
rules_pkg()
abseil_py()
py_mock()

View File

@ -20,7 +20,10 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
# TODO(fweikert): Also load rules_go's setup.bzl file from the federation once it exists
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_federation//setup:rules_pkg.bzl", "rules_pkg_setup")
def rules_cc_internal_setup():
bazel_skylib_workspace()
go_rules_dependencies()
go_register_toolchains()
rules_pkg_setup()