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