feat: add bazel_version value to host_repo repository rule (#246)

This commit is contained in:
Greg Magolan 2022-09-16 11:51:48 -07:00 committed by GitHub
parent 0450c0c652
commit 8e230b0721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -1,8 +1,10 @@
load("@aspect_bazel_lib_host//:defs.bzl", "host")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("//lib:write_source_files.bzl", "write_source_files")
load("//lib:yq.bzl", "yq")
load("//lib:diff_test.bzl", "diff_test")
load("//lib:testing.bzl", "assert_contains")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
@ -69,3 +71,9 @@ diff_test(
file1 = "external-dir/foo.txt",
file2 = "foo_copy.txt",
)
assert_contains(
name = "bazel_version_test",
actual = ".bazelversion",
expected = str(host.bazel_version),
)

View File

@ -25,6 +25,10 @@ local_repository(
path = "./lib/tests/external_test_repo",
)
load("//lib:host_repo.bzl", "host_repo")
host_repo(name = "aspect_bazel_lib_host")
############################################
# Gazelle, for generating bzl_library targets
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

View File

@ -147,7 +147,10 @@ bzl_library(
bzl_library(
name = "host_repo",
srcs = ["host_repo.bzl"],
deps = ["//lib/private:host_repo"],
deps = [
"//lib/private:host_repo",
"@bazel_skylib//lib:versions",
],
)
bzl_library(

View File

@ -1,5 +1,6 @@
"A repository that exposes information about the host platform"
load("@bazel_skylib//lib:versions.bzl", "versions")
load(":repo_utils.bzl", "repo_utils")
def _impl(rctx):
@ -17,6 +18,7 @@ bzl_library(
rctx.file("defs.bzl", content = """# @generated by @aspect_bazel_lib//lib/private:host_repo.bzl
# Information about the host platform
host = struct(
bazel_version = "{bazel_version}",
is_darwin = {is_darwin},
is_linux = {is_linux},
is_windows = {is_windows},
@ -24,6 +26,7 @@ host = struct(
platform = "{platform}",
)
""".format(
bazel_version = versions.get(),
is_darwin = repo_utils.is_darwin(rctx),
is_linux = repo_utils.is_linux(rctx),
is_windows = repo_utils.is_windows(rctx),