Skip to content

Commit

Permalink
Add dist_http_archive() to make it easier to synchronize distdir with…
Browse files Browse the repository at this point in the history
… http_archive

More for #12081

For dependencies specified in distdir.bzl, we can now include them in Bazel's WORKSPACE with a simpler invocation that can not go out of sync.  For example, this

```
dist_http_archive(
  name = "io_bazel_rules_sass",
)
```
instead of
```
http_archive(
  name = "io_bazel_rules_sass",
  sha256 = "c78be58f5e0a29a04686b628cf54faaee0094322ae0ac99da5a8a8afca59a647",
  strip_prefix = "rules_sass-1.25.0",
  urls = [
    "https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
    "https://github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
  ],
)
```

Also, convert two more packages only used at Bazel build time to the new style.
Next steps:
- convert other repositories which are not needed at run time to this format
- add ability to generate WORKSPACE files used by tests from DISTDIR #12734
- convert rules libraries to this format

Closes #12722.

PiperOrigin-RevId: 350140996
  • Loading branch information
aiuto authored and copybara-github committed Jan 5, 2021
1 parent 069b718 commit 1c9e7ca
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 37 deletions.
40 changes: 5 additions & 35 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
workspace(name = "io_bazel")

load("//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("//:distdir.bzl", "distdir_tar")
load("//:distdir_deps.bzl", "DIST_DEPS", "dist_http_archive")

# These can be used as values for the patch_cmds and patch_cmds_win attributes
# of http_archive, in order to export the WORKSPACE file from the BUILD or
Expand Down Expand Up @@ -139,9 +141,6 @@ http_archive(
],
)

load("//:distdir.bzl", "distdir_tar")
load("//:distdir_deps.bzl", "DIST_DEPS")

distdir_tar(
name = "additional_distfiles",
# Keep in sync with the archives fetched as part of building bazel.
Expand All @@ -154,10 +153,6 @@ distdir_tar(
"coverage_output_generator-v2.5.zip",
# bazelbuid/stardoc
"1ef781ced3b1443dca3ed05dec1989eca1a4e1cd.tar.gz",
# rules_sass
"1.25.0.zip",
# rules_nodejs
"rules_nodejs-2.2.2.tar.gz",
"android_tools_pkg-0.19.0rc3.tar.gz",
# bazelbuild/bazel-skylib
"bazel-skylib-1.0.3.tar.gz",
Expand Down Expand Up @@ -193,10 +188,6 @@ distdir_tar(
"coverage_output_generator-v2.5.zip": "cd14f1cb4559e4723e63b7e7b06d09fcc3bd7ba58d03f354cdff1439bd936a7d",
# bazelbuild/stardoc
"1ef781ced3b1443dca3ed05dec1989eca1a4e1cd.tar.gz": "5a725b777976b77aa122b707d1b6f0f39b6020f66cd427bb111a585599c857b1",
# rules_sass
"1.25.0.zip": "c78be58f5e0a29a04686b628cf54faaee0094322ae0ac99da5a8a8afca59a647",
# rules_nodejs
"rules_nodejs-2.2.2.tar.gz": "f2194102720e662dbf193546585d705e645314319554c6ce7e47d8b59f459e9c",
"android_tools_pkg-0.19.0rc3.tar.gz": "ea5c0589a01e2a9f43c20e5c145d3530e3b3bdbe7322789bc5da38d0ca49b837",
# bazelbuild/bazel-skylib
"bazel-skylib-1.0.3.tar.gz": "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
Expand Down Expand Up @@ -245,14 +236,6 @@ distdir_tar(
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/archive/1ef781ced3b1443dca3ed05dec1989eca1a4e1cd.tar.gz",
"https://github.com/bazelbuild/stardoc/archive/1ef781ced3b1443dca3ed05dec1989eca1a4e1cd.tar.gz",
],
"1.25.0.zip": [
"https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
"https://github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
],
"rules_nodejs-2.2.2.tar.gz": [
"https://mirror.bazel.build/github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz",
"https://github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz",
],
"android_tools_pkg-0.19.0rc3.tar.gz": [
"https://mirror.bazel.build/bazel_android_tools/android_tools_pkg-0.19.0rc3.tar.gz",
],
Expand Down Expand Up @@ -691,23 +674,12 @@ exports_files(["_sass/style.scss"])
# fetched unconditionally for everything (including just building bazel!), so
# provide them as http_archives that can be shiped in the distdir, to keep the
# distribution archive self-contained.
http_archive(
dist_http_archive(
name = "io_bazel_rules_sass",
sha256 = "c78be58f5e0a29a04686b628cf54faaee0094322ae0ac99da5a8a8afca59a647",
strip_prefix = "rules_sass-1.25.0",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
"https://github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
],
)

http_archive(
dist_http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "f2194102720e662dbf193546585d705e645314319554c6ce7e47d8b59f459e9c",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz",
"https://github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz",
],
)

http_archive(
Expand Down Expand Up @@ -1122,12 +1094,10 @@ sass_repositories()
register_execution_platforms("//:default_host_platform") # buildozer: disable=positional-args

# Tools for building deb, rpm and tar files.
http_archive(
dist_http_archive(
name = "rules_pkg",
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
sha256 = DIST_DEPS["rules_pkg"]["sha256"],
urls = DIST_DEPS["rules_pkg"]["urls"],
)

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
Expand Down
60 changes: 58 additions & 2 deletions distdir_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,41 @@
# limitations under the License.
"""List the distribution dependencies we need to build Bazel."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def dist_http_archive(name, **kwargs):
"""Wraps http_archive but takes sha and urls from DIST_DEPS.
dist_http_archive wraps an http_archive invocation, but looks up relevant
information from DIST_DEPS so the user does not have to specify it. It
always strips sha256 and urls from kwargs.
Args:
name: repo name
**kwargs: see http_archive for allowed args.
"""
info = DIST_DEPS[name]
if "patches" not in kwargs:
kwargs["patches"] = info.get("patches")
if "strip_prefix" not in kwargs:
kwargs["strip_prefix"] = info.get("strip_prefix")
http_archive(
name = name,
sha256 = info["sha256"],
urls = info["urls"],
**kwargs
)

DIST_DEPS = {
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/cc_configure.WORKSPACE.
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
########################################
#
# Runtime language dependencies
#
########################################
# Keep in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/cc_configure.WORKSPACE.
# Keep in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
# Note: This is not in sync with src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java.
# Perhaps it should be.
"rules_cc": {
"archive": "b1c40e1de81913a3c40e5948f78719c28152486d.zip",
"sha256": "d0c573b94a6ef20ef6ff20154a23d0efcb409fb0e1ff0979cec318dfe42f0cdd",
Expand All @@ -26,6 +58,11 @@ DIST_DEPS = {
],
"need_in_test_WORKSPACE": True,
},
########################################
#
# Build time dependencies
#
########################################
"rules_pkg": {
"archive": "rules_pkg-0.2.4.tar.gz",
"sha256": "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
Expand All @@ -34,4 +71,23 @@ DIST_DEPS = {
"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
],
},
# for Stardoc
"io_bazel_rules_sass": {
"archive": "1.25.0.zip",
"sha256": "c78be58f5e0a29a04686b628cf54faaee0094322ae0ac99da5a8a8afca59a647",
"strip_prefix": "rules_sass-1.25.0",
"urls": [
"https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
"https://github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
],
},
# for Stardoc
"build_bazel_rules_nodejs": {
"archive": "rules_nodejs-2.2.2.tar.gz",
"sha256": "f2194102720e662dbf193546585d705e645314319554c6ce7e47d8b59f459e9c",
"urls": [
"https://mirror.bazel.build/github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz",
"https://github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz",
],
},
}

0 comments on commit 1c9e7ca

Please sign in to comment.