fix: bzlmod toolchain registration for copy_directory & copy_to_directory (#336)

This commit is contained in:
Greg Magolan 2023-01-16 19:37:36 -08:00 committed by GitHub
parent 63f5aff803
commit 497409b15b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 9 deletions

View File

@ -12,12 +12,14 @@ bazel_dep(name = "stardoc", repo_name = "io_bazel_stardoc", version = "0.5.0")
ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "ext")
use_repo(ext, "copy_directory_toolchains")
use_repo(ext, "copy_to_directory_toolchains")
use_repo(ext, "jq_toolchains")
use_repo(ext, "yq_toolchains")
register_toolchains(
"@copy_directory_toolchains//:all",
"@copy_to_directory_toolchains//:all",
"@jq_toolchains//:all",
"@yq_toolchains//:all",
)

View File

@ -6,8 +6,11 @@ You can manually verify this after testing this repo with
You'll see a aspect_bazel_lib.ext.yq_toolchains repo, but no downloaded yq binary.
"""
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@aspect_bazel_lib//lib:copy_directory.bzl", "copy_directory")
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test")
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@aspect_bazel_lib//lib:yq.bzl", "yq")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
bzl_library(
@ -29,13 +32,57 @@ bzl_library(
# Validate that JQ works and resolves its toolchain
jq(
name = "case_no_sources",
name = "jq_case_no_sources",
srcs = [],
filter = ".",
)
diff_test(
name = "test",
file1 = "case_no_sources",
file2 = "expected",
name = "jq_test",
file1 = "jq_case_no_sources",
file2 = "expected_jq",
)
# Validate that YQ works and resolves its toolchain
yq(
name = "yq_case_no_sources",
srcs = [],
expression = ".",
)
diff_test(
name = "yq_test",
file1 = "yq_case_no_sources",
file2 = "expected_yq",
)
# Validate that copy_directory works and resolves its toolchain
copy_directory(
name = "copy_directory_case",
src = "d",
out = "d_out",
)
diff_test(
name = "copy_directory_test",
file1 = "d",
file2 = "copy_directory_case",
# Source directories are not support on remote execution.
tags = ["no-remote-exec"],
)
# Validate that copy_to_directory works and resolves its toolchain
copy_to_directory(
name = "copy_to_directory_case",
srcs = ["d"],
out = "d2_out",
replace_prefixes = {"d/": ""},
)
diff_test(
name = "copy_to_directory_test",
file1 = "d",
file2 = "copy_to_directory_case",
# Source directories are not support on remote execution.
tags = ["no-remote-exec"],
)

1
e2e/bzlmod/d/1 Normal file
View File

@ -0,0 +1 @@
1

1
e2e/bzlmod/expected_yq Normal file
View File

@ -0,0 +1 @@

View File

@ -9,10 +9,10 @@ load(
)
def _toolchain_extension(_):
register_yq_toolchains(register = False)
register_jq_toolchains(register = False)
register_copy_directory_toolchains(register = False)
register_copy_to_directory_toolchains(register = False)
register_jq_toolchains(register = False)
register_yq_toolchains(register = False)
# TODO: some way for users to control repo name/version of the tools installed
ext = module_extension(