I want to implement a starlark repository rule that takes a tar.gz from the WORKSPACE directory (I'm putting files in git LFS there) and extracts it, then uses the extracted contents as an external repository (i.e., extracts the file, then does the equivalent of local_repository()
on that directory).
I've tried the following:
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "workspace_and_buildfile", "patch")
def _local_archive_impl(repository_ctx):
if repository_ctx.attr.build_file and repository_ctx.attr.build_file_content:
fail("Only one of build_file and build_file_content can be provided.")
repository_ctx.extract(repository_ctx.path(repository_ctx.attr.archive).basename, "", repository_ctx.attr.strip_prefix)
patch(repository_ctx)
workspace_and_buildfile(repository_ctx)
but it appears that this approach won't work since Starlark repository rules don't appear to be able to access the WORKSPACE directory(?!?).
I also tried the approach referred to in https://groups.google.com/forum/m/#!topic/bazel-discuss/UXvp0rksRMM, namely:
def _impl(ctx):
ctx.execute(["tar", "zxf", ctx.attr.archive)
local_archive = repository_rule(
implementation = _impl,
local = True,
attrs = {'archive': attr.string()}
)
but that doesn't work either :(.