refactor(bazel): extract repository rule helpers
This commit is contained in:
2
MODULE.bazel.lock
generated
2
MODULE.bazel.lock
generated
@@ -93,7 +93,7 @@
|
|||||||
"moduleExtensions": {
|
"moduleExtensions": {
|
||||||
"//bazel:rust_toolchain.bzl%rust": {
|
"//bazel:rust_toolchain.bzl%rust": {
|
||||||
"general": {
|
"general": {
|
||||||
"bzlTransitiveDigest": "fQj9CTS2ItcWLOd4VcpBs75mepI/nRwLQOA3c7X5QG4=",
|
"bzlTransitiveDigest": "dVDpuhw0j4+nz6zvC0CHD8HwV8sSxepnzuFdoOftyBk=",
|
||||||
"usagesDigest": "SQP3kWaLgKBHOdfxAvAWSUMuSfW8zC/274pBGhq2FlQ=",
|
"usagesDigest": "SQP3kWaLgKBHOdfxAvAWSUMuSfW8zC/274pBGhq2FlQ=",
|
||||||
"recordedFileInputs": {},
|
"recordedFileInputs": {},
|
||||||
"recordedDirentsInputs": {},
|
"recordedDirentsInputs": {},
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
exports_files(["rust_toolchain.bzl"])
|
exports_files([
|
||||||
|
"rust_toolchain.bzl",
|
||||||
|
"utils.bzl",
|
||||||
|
])
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
load("//bazel:utils.bzl", _execute = "execute", _require = "require")
|
||||||
|
|
||||||
|
|
||||||
def _rust_repository_impl(repository_ctx):
|
def _rust_repository_impl(repository_ctx):
|
||||||
rustc = _require(repository_ctx, "rustc")
|
rustc = _require(repository_ctx, "rustc")
|
||||||
rustdoc = _require(repository_ctx, "rustdoc")
|
rustdoc = _require(repository_ctx, "rustdoc")
|
||||||
@@ -36,20 +39,6 @@ def _rust_repository_impl(repository_ctx):
|
|||||||
repository_ctx.file("BUILD.bazel", _build_file(host_triple, release))
|
repository_ctx.file("BUILD.bazel", _build_file(host_triple, release))
|
||||||
|
|
||||||
|
|
||||||
def _require(repository_ctx, executable):
|
|
||||||
path = repository_ctx.which(executable)
|
|
||||||
if path == None:
|
|
||||||
fail("{} must be available in PATH.".format(executable))
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def _execute(repository_ctx, arguments):
|
|
||||||
result = repository_ctx.execute(arguments)
|
|
||||||
if result.return_code != 0:
|
|
||||||
fail("command failed: {}\n{}".format(" ".join(arguments), result.stderr))
|
|
||||||
return result.stdout.strip()
|
|
||||||
|
|
||||||
|
|
||||||
def _build_file(host_triple, release):
|
def _build_file(host_triple, release):
|
||||||
return """
|
return """
|
||||||
filegroup(
|
filegroup(
|
||||||
|
|||||||
12
bazel/utils.bzl
Normal file
12
bazel/utils.bzl
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
def require(repository_ctx, executable):
|
||||||
|
path = repository_ctx.which(executable)
|
||||||
|
if path == None:
|
||||||
|
fail("{} must be available in PATH.".format(executable))
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def execute(repository_ctx, arguments):
|
||||||
|
result = repository_ctx.execute(arguments)
|
||||||
|
if result.return_code != 0:
|
||||||
|
fail("command failed: {}\n{}".format(" ".join(arguments), result.stderr))
|
||||||
|
return result.stdout.strip()
|
||||||
Reference in New Issue
Block a user