Use rules_pkg 2.1 for a release.
diff --git a/BUILD b/BUILD index 4ab8e13..9e1ee65 100644 --- a/BUILD +++ b/BUILD
@@ -3,10 +3,9 @@ exports_files(["LICENSE"]) filegroup( - name = "standard_package", + name = "distribution", srcs = glob([ "LICENSE", - "java/**", ]), visibility = ["@//distro:__pkg__"], )
diff --git a/WORKSPACE b/WORKSPACE index 0bc9cf1..20ae0dc 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -11,8 +11,8 @@ 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", + url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.1/rules_pkg-0.2.1.tar.gz", + sha256 = "04c1eab736f508e94c297455915b6371432cbc4106765b5252b444d1656db051", ) load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies()
diff --git a/distro/BUILD b/distro/BUILD index 619c4fd..0e09212 100644 --- a/distro/BUILD +++ b/distro/BUILD
@@ -4,12 +4,14 @@ load("@rules_java//java: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_java-%s" % version, srcs = [ - "@rules_java//:standard_package", + "//:distribution", + "//java:distribution", ], extension = "tar.gz", # It is all source code, so make it read-only. @@ -17,49 +19,12 @@ # Make it owned by root so it does not have the uid of the CI robot. owner = "0.0", package_dir = ".", + strip_prefix = ".", ) -# TODO(aiuto): Package print_rel_notes as a rule so this is easier to write. -genrule( +print_rel_notes( 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", - ], + repo = "rules_java", + version = version, )
diff --git a/distro/README.md b/distro/README.md index 0c832c7..ffd6473 100644 --- a/distro/README.md +++ b/distro/README.md
@@ -1,5 +1,11 @@ # Package rules_java ``` -bazel run :print_rel_notes +bazel build :print_rel_notes +cat ../bazel-bin/distro/relnotes.txt +tar tzf ../bazel-bin/distro/rules_java-*.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/distro/__init__.py b/distro/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/distro/__init__.py +++ /dev/null
diff --git a/distro/print_rel_notes.py b/distro/print_rel_notes.py deleted file mode 100644 index 521301b..0000000 --- a/distro/print_rel_notes.py +++ /dev/null
@@ -1,63 +0,0 @@ -# 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 deleted file mode 100644 index 6a8509b..0000000 --- a/distro/release_tools.py +++ /dev/null
@@ -1,49 +0,0 @@ -# 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/BUILD b/java/BUILD index 9a01f92..c799b9b 100644 --- a/java/BUILD +++ b/java/BUILD
@@ -1 +1,14 @@ -# Intentionally left empty +package(default_visibility = ["//visibility:public"]) + +# TODO(aiuto): Find a way to strip this rule from the distribution tarball. +filegroup( + name = "distribution", + srcs = glob([ + "**", + ]) + [ + "//java/constraints:srcs", + ], + visibility = [ + "@//distro:__pkg__", + ], +)