create repository rule for loading and initializing (#62)

This commit is contained in:
irengrig 2018-08-27 14:54:04 +02:00 committed by GitHub
parent af0871023c
commit ccec08efd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

39
install_ws_dependency.bzl Normal file
View File

@ -0,0 +1,39 @@
def _generate_install_rule_impl(rctx):
rctx.download_and_extract(
url = rctx.attr.url,
stripPrefix = rctx.attr.stripPrefix,
output = ".",
)
text = """workspace(name='{ws_name}')
load("{init_file}", "{init_function}")
{init_expression}
""".format(ws_name = rctx.attr.name,
init_file = rctx.attr.init_file,
init_function = rctx.attr.init_function,
init_expression = rctx.attr.init_expression)
rctx.file("WORKSPACE", text)
rctx.file("BUILD", "")
_generate_install_rule = repository_rule(
local = True,
implementation = _generate_install_rule_impl,
attrs = {
"url": attr.string(mandatory = True),
"stripPrefix": attr.string(mandatory = False),
"init_file": attr.string(mandatory = True),
"init_function": attr.string(mandatory = True),
"init_expression": attr.string(mandatory = True),
},
)
def install_ws_dependency(repo_name, url, strip_prefix, init_file, init_function, init_expression = None):
init_expression = init_expression if init_expression else (init_function + "()")
_generate_install_rule(
name = repo_name,
url = url,
stripPrefix = strip_prefix,
init_file = init_file,
init_function = init_function,
init_expression = init_expression
)