From 29da92c66c3b36cd2d50b496aa88b270b7842aec Mon Sep 17 00:00:00 2001 From: fweikert Date: Fri, 13 Sep 2019 18:24:56 +0200 Subject: [PATCH 1/4] 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. --- BUILD | 8 ++++++++ WORKSPACE | 6 +++--- cc/BUILD | 11 +++++++++++ cc/defs.bzl | 2 ++ distro/BUILD | 30 ++++++++++++++++++++++++++++++ distro/README.md | 11 +++++++++++ internal_deps.bzl | 3 ++- internal_setup.bzl | 3 +++ 8 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 distro/BUILD create mode 100644 distro/README.md diff --git a/BUILD b/BUILD index 001dcb9..f76704f 100644 --- a/BUILD +++ b/BUILD @@ -3,3 +3,11 @@ package(default_visibility = ["//visibility:public"]) licenses(["notice"]) exports_files(["LICENSE"]) + +filegroup( + name = "distribution", + srcs = glob([ + "LICENSE", + ]), + visibility = ["@//distro:__pkg__"], +) \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE index 8d3caad..aab3a77 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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", ) diff --git a/cc/BUILD b/cc/BUILD index 333a58a..21ee541 100644 --- a/cc/BUILD +++ b/cc/BUILD @@ -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__", + ], +) diff --git a/cc/defs.bzl b/cc/defs.bzl index 8de01bd..dbc9331 100644 --- a/cc/defs.bzl +++ b/cc/defs.bzl @@ -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] diff --git a/distro/BUILD b/distro/BUILD new file mode 100644 index 0000000..ed14028 --- /dev/null +++ b/distro/BUILD @@ -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, +) \ No newline at end of file diff --git a/distro/README.md b/distro/README.md new file mode 100644 index 0000000..086436c --- /dev/null +++ b/distro/README.md @@ -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. diff --git a/internal_deps.bzl b/internal_deps.bzl index ea51aeb..fda3634 100644 --- a/internal_deps.bzl +++ b/internal_deps.bzl @@ -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() diff --git a/internal_setup.bzl b/internal_setup.bzl index 99e7d55..0ad32b3 100644 --- a/internal_setup.bzl +++ b/internal_setup.bzl @@ -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() From df4a51f42e264e375602bd86c9d8119f274d8c23 Mon Sep 17 00:00:00 2001 From: Florian Weikert Date: Mon, 30 Sep 2019 15:10:00 +0200 Subject: [PATCH 2/4] Use latest federation version This version includes rules_pkg 0.2.4, which contains the fix required to cut a first rules_cc release. --- WORKSPACE | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index aab3a77..3aa393c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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/ed880c20ec6112984caa47ddc6489028dbcc66e2.zip", - sha256 = "95339d2002756bdde910c93b6c42248725a7c2b61629585f08580cc4f07d1805", - strip_prefix = "bazel-federation-ed880c20ec6112984caa47ddc6489028dbcc66e2", + url = "https://github.com/bazelbuild/bazel-federation/archive/f0e5eda7f0cbfe67f126ef4dacb18c89039b0506.zip", # 2019-09-30 + sha256 = "33222ab7bcc430f1ff1db8788c2e0118b749319dd572476c4fd02322d7d15792", + strip_prefix = "bazel-federation-f0e5eda7f0cbfe67f126ef4dacb18c89039b0506", type = "zip", ) From eae134361b075f6837a35262feb14bf1ffee86e9 Mon Sep 17 00:00:00 2001 From: Florian Weikert Date: Mon, 30 Sep 2019 15:58:14 +0200 Subject: [PATCH 3/4] Make Buildifier happy --- BUILD | 4 ++-- internal_setup.bzl | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/BUILD b/BUILD index f76704f..ce7074e 100644 --- a/BUILD +++ b/BUILD @@ -6,8 +6,8 @@ exports_files(["LICENSE"]) filegroup( name = "distribution", - srcs = glob([ + srcs = [ "LICENSE", - ]), + ], visibility = ["@//distro:__pkg__"], ) \ No newline at end of file diff --git a/internal_setup.bzl b/internal_setup.bzl index 0ad32b3..beee607 100644 --- a/internal_setup.bzl +++ b/internal_setup.bzl @@ -19,7 +19,6 @@ 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(): From 182a47724450188aedda758a9cc0a23b57483a3d Mon Sep 17 00:00:00 2001 From: fweikert Date: Wed, 2 Oct 2019 15:25:05 +0200 Subject: [PATCH 4/4] Add version number to a dedicated bzl file Adding the version number to defs.bzl caused some problems in our internal codebase. --- cc/defs.bzl | 2 -- cc/version.bzl | 17 +++++++++++++++++ distro/BUILD | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 cc/version.bzl diff --git a/cc/defs.bzl b/cc/defs.bzl index dbc9331..8de01bd 100644 --- a/cc/defs.bzl +++ b/cc/defs.bzl @@ -19,8 +19,6 @@ 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] diff --git a/cc/version.bzl b/cc/version.bzl new file mode 100644 index 0000000..4363594 --- /dev/null +++ b/cc/version.bzl @@ -0,0 +1,17 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Information about the present version of rules_cc.""" + +version = "0.0.1" diff --git a/distro/BUILD b/distro/BUILD index ed14028..1a4b0f6 100644 --- a/distro/BUILD +++ b/distro/BUILD @@ -2,7 +2,7 @@ package( default_visibility = ["//visibility:private"], ) -load("@rules_cc//cc:defs.bzl", "version") +load("@rules_cc//cc:version.bzl", "version") load("@rules_pkg//:pkg.bzl", "pkg_tar") load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")