| 1 |
"""This module defines the download_config_files rule. |
| 2 |
|
| 3 |
This allows external clients to get the configuration files that our custom |
| 4 |
Bazel rules for repos like Freetype depend on. |
| 5 |
|
| 6 |
Clients don't have to use this rule if they build those libraries their own |
| 7 |
way or want to use their own custom configurations. |
| 8 |
|
| 9 |
Skia doesn't use this rule directly, instead it uses a local_repository rule |
| 10 |
to make those configs available while still being defined in the same repo. |
| 11 |
Clients cannot use local_repository to refer to something in the Skia source |
| 12 |
code though, thus the need for a way for them to get those independently. |
| 13 |
|
| 14 |
TODO(kjlubick) Make this more hermetic by having a place to download (and verify) |
| 15 |
the files from that is more robust. |
| 16 |
""" |
| 17 |
|
| 18 |
def _download_config_files_impl(repo_ctx): |
| 19 |
# This will create one or more files in the [bazel sandbox]/external/[name] folder. |
| 20 |
for dst, src in repo_ctx.attr.files.items(): |
| 21 |
# I'd prefer to download a single zip that we can verify with sha256, |
| 22 |
# or at least download from https://skia.googlesource.com/skia, however |
| 23 |
# the latter only lets one download base64-encoded files and I would prefer |
| 24 |
# not to depend on something like https://docs.aspect.build/rulesets/aspect_bazel_lib/docs/base64 |
| 25 |
url = "https://raw.githubusercontent.com/google/skia/{}/{}".format(repo_ctx.attr.skia_revision, src) |
| 26 |
|
| 27 |
# https://bazel.build/rules/lib/builtins/repository_ctx#download |
| 28 |
repo_ctx.download(url, output = dst) |
| 29 |
|
| 30 |
# https://bazel.build/rules/lib/globals/bzl#repository_rule |
| 31 |
download_config_files = repository_rule( |
| 32 |
implementation = _download_config_files_impl, |
| 33 |
local = False, |
| 34 |
attrs = { |
| 35 |
# Maps dst (in this created repo) to src (relative to the Skia root). |
| 36 |
"files": attr.string_dict(mandatory = True), |
| 37 |
# The git version of the Skia repo from which to extract files. |
| 38 |
"skia_revision": attr.string(mandatory = True), |
| 39 |
}, |
| 40 |
) |