Add tooling to make a release smaller & easier. - Create a tarball which contains just what we need to use the rules - temporarily copy release note maker from rules_pkg. - improvements here, but it should be extracted to a different repo
diff --git a/BUILD b/BUILD index 3638149..4ab8e13 100644 --- a/BUILD +++ b/BUILD
@@ -1,3 +1,12 @@ licenses(["notice"]) exports_files(["LICENSE"]) + +filegroup( + name = "standard_package", + srcs = glob([ + "LICENSE", + "java/**", + ]), + visibility = ["@//distro:__pkg__"], +)
diff --git a/WORKSPACE b/WORKSPACE index c820ee6..0bc9cf1 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -3,3 +3,16 @@ load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains") rules_java_dependencies() rules_java_toolchains() + + +# +# Dependencies for development of rules_java itself. +# +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "rules_pkg", + url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.0/rules_pkg-0.2.0.tar.gz", + sha256 = "5bdc04987af79bd27bc5b00fe30f59a858f77ffa0bd2d8143d5b31ad8b1bd71c", +) +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") +rules_pkg_dependencies()
diff --git a/distro/BUILD b/distro/BUILD new file mode 100644 index 0000000..619c4fd --- /dev/null +++ b/distro/BUILD
@@ -0,0 +1,65 @@ +package( + default_visibility = ["//visibility:private"], +) + +load("@rules_java//java:defs.bzl", "version") +load("@rules_pkg//:pkg.bzl", "pkg_tar") + +# Build the artifact to put on the github release page. +pkg_tar( + name = "rules_java-%s" % version, + srcs = [ + "@rules_java//:standard_package", + ], + 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 = ".", +) + +# TODO(aiuto): Package print_rel_notes as a rule so this is easier to write. +genrule( + name = "relnotes", + srcs = [ + ":rules_java-%s.tar.gz" % version, + ], + outs = ["relnotes.txt"], + cmd = " ".join([ + "$(location :print_rel_notes)", + "rules_java", + version, + "$(location :rules_java-%s.tar.gz)" % version, + ">$@", + ]), + tools = [ + ":print_rel_notes", + ], +) + +# TODO(aiuto): All below should be a component of a different repo. +# Possibly rules_pkg. +py_library( + name = "util", + srcs = [ + "__init__.py", + "release_tools.py", + ], + srcs_version = "PY3", + deps = [ + "@bazel_tools//tools/python/runfiles", + ], +) + +py_binary( + name = "print_rel_notes", + srcs = [ + "print_rel_notes.py", + ], + python_version = "PY3", + deps = [ + ":util", + "@bazel_tools//tools/python/runfiles", + ], +)
diff --git a/distro/README.md b/distro/README.md new file mode 100644 index 0000000..0c832c7 --- /dev/null +++ b/distro/README.md
@@ -0,0 +1,5 @@ +# Package rules_java + +``` +bazel run :print_rel_notes +```
diff --git a/distro/__init__.py b/distro/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/distro/__init__.py
diff --git a/distro/print_rel_notes.py b/distro/print_rel_notes.py new file mode 100644 index 0000000..521301b --- /dev/null +++ b/distro/print_rel_notes.py
@@ -0,0 +1,63 @@ +# 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. +"""Print release notes for a package. + +""" + +import sys +from string import Template +import textwrap + +from distro import release_tools + + +def print_notes(repo, version, tarball_path, org='bazelbuild'): + file_name = release_tools.package_basename(repo, version) + sha256 = release_tools.get_package_sha256(tarball_path) + + url = 'https://github.com/%s/%s/releases/download/%s/%s' % ( + org, repo, version, file_name) + workspace_stanza = release_tools.workspace_content(url, repo, sha256) + relnotes_template = Template(textwrap.dedent( + """ + ------------------------ snip ---------------------------- + **New Features** + + **Incompatible Changes** + + **WORKSPACE setup** + + ``` + ${workspace_stanza} + ``` + + **Using the rules** + + See [the source](https://github.com/${org}/${repo}/tree/master). + ------------------------ snip ---------------------------- + + """).strip()) + print(relnotes_template.substitute({ + 'org': org, + 'repo': repo, + 'workspace_stanza': workspace_stanza, + })) + + +def main(args): + print_notes(repo=args[1], version=args[2], tarball_path=args[3]) + + +if __name__ == '__main__': + main(sys.argv)
diff --git a/distro/release_tools.py b/distro/release_tools.py new file mode 100644 index 0000000..6a8509b --- /dev/null +++ b/distro/release_tools.py
@@ -0,0 +1,49 @@ +# 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. +"""Utilities to help create a rule set release.""" + +import hashlib +import os +from string import Template +import textwrap + + +def package_basename(repo, version): + return '%s-%s.tar.gz' % (repo, version) + + +def get_package_sha256(tarball_path): + with open(tarball_path, 'rb') as pkg_content: + tar_sha256 = hashlib.sha256(pkg_content.read()).hexdigest() + return tar_sha256 + + +def workspace_content(url, repo, sha256): + # Set up a fresh Bazel workspace + workspace_stanza_template = Template(textwrap.dedent( + """ + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + http_archive( + name = "${repo}", + url = "${url}", + sha256 = "${sha256}", + ) + load("@${repo}//:deps.bzl", "${repo}_dependencies") + ${repo}_dependencies() + """).strip()) + return workspace_stanza_template.substitute({ + 'url': url, + 'sha256': sha256, + 'repo': repo, + })
diff --git a/java/defs.bzl b/java/defs.bzl index 1cb4d57..e77b1a9 100644 --- a/java/defs.bzl +++ b/java/defs.bzl
@@ -15,6 +15,8 @@ _MIGRATION_TAG = "__JAVA_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__" +version = "0.1.0" + def _add_tags(attrs): if "tags" in attrs and attrs["tags"] != None: attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG]