2022-09-16 18:51:48 +00:00
|
|
|
load("@aspect_bazel_lib_host//:defs.bzl", "host")
|
2023-09-29 21:42:33 +00:00
|
|
|
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
|
|
|
|
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
|
|
|
load("@bazel_skylib//rules:write_file.bzl", "write_file")
|
2023-06-09 22:26:34 +00:00
|
|
|
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
|
2024-08-20 18:20:51 +00:00
|
|
|
load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
|
2022-07-06 10:46:51 +00:00
|
|
|
load("//lib:diff_test.bzl", "diff_test")
|
2024-07-02 16:27:06 +00:00
|
|
|
load("//lib:tar.bzl", "mtree_spec")
|
2022-09-16 18:51:48 +00:00
|
|
|
load("//lib:testing.bzl", "assert_contains")
|
2023-09-29 21:42:33 +00:00
|
|
|
load("//lib:write_source_files.bzl", "write_source_files")
|
|
|
|
load("//lib:yq.bzl", "yq")
|
2021-11-08 14:20:26 +00:00
|
|
|
|
2023-01-01 23:37:00 +00:00
|
|
|
# gazelle:prefix github.com/aspect-build/bazel-lib
|
|
|
|
|
2021-11-08 14:20:26 +00:00
|
|
|
gazelle_binary(
|
|
|
|
name = "gazelle_bin",
|
2023-11-15 23:07:03 +00:00
|
|
|
languages = select({
|
|
|
|
# TODO: under bzlmod we get go linking errors when adding
|
|
|
|
# the skylib gazelle plugin.
|
|
|
|
# https://github.com/bazelbuild/rules_go/issues/1877
|
|
|
|
"@aspect_bazel_lib//lib:bzlmod": DEFAULT_LANGUAGES,
|
|
|
|
"//conditions:default": DEFAULT_LANGUAGES + [
|
|
|
|
"@bazel_skylib_gazelle_plugin//bzl",
|
|
|
|
],
|
|
|
|
}),
|
2021-11-08 14:20:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
gazelle(
|
|
|
|
name = "gazelle",
|
|
|
|
gazelle = "gazelle_bin",
|
2023-10-05 22:50:42 +00:00
|
|
|
mode = "fix",
|
|
|
|
)
|
|
|
|
|
|
|
|
gazelle(
|
|
|
|
name = "gazelle.check",
|
|
|
|
gazelle = "gazelle_bin",
|
|
|
|
mode = "diff",
|
2021-11-08 14:20:26 +00:00
|
|
|
)
|
|
|
|
|
2023-01-03 17:42:20 +00:00
|
|
|
gazelle(
|
|
|
|
name = "gazelle_update_repos",
|
|
|
|
args = [
|
|
|
|
"-build_file_proto_mode=disable_global",
|
|
|
|
"-from_file=go.mod",
|
|
|
|
"-to_macro=deps.bzl%go_dependencies",
|
|
|
|
"-prune",
|
|
|
|
],
|
|
|
|
command = "update-repos",
|
|
|
|
)
|
|
|
|
|
2023-10-18 22:49:34 +00:00
|
|
|
buildifier(
|
|
|
|
name = "buildifier",
|
|
|
|
exclude_patterns = ["./.git/*"],
|
|
|
|
lint_mode = "fix",
|
|
|
|
mode = "fix",
|
|
|
|
tags = ["manual"], # tag as manual so windows ci does not build it by default
|
|
|
|
)
|
|
|
|
|
2023-06-09 22:26:34 +00:00
|
|
|
buildifier(
|
|
|
|
name = "buildifier.check",
|
2023-10-18 22:49:34 +00:00
|
|
|
exclude_patterns = ["./.git/*"],
|
2023-06-09 22:26:34 +00:00
|
|
|
lint_mode = "warn",
|
|
|
|
mode = "diff",
|
2023-06-14 01:10:36 +00:00
|
|
|
tags = ["manual"], # tag as manual so windows ci does not build it by default
|
2023-06-09 22:26:34 +00:00
|
|
|
)
|
|
|
|
|
2023-12-08 07:34:24 +00:00
|
|
|
alias(
|
|
|
|
name = "format",
|
2023-12-11 15:34:26 +00:00
|
|
|
actual = "//tools/format",
|
2023-12-21 22:27:21 +00:00
|
|
|
tags = ["manual"], # tag as manual so windows ci does not build it by default
|
2023-12-08 07:34:24 +00:00
|
|
|
)
|
|
|
|
|
2022-03-31 00:04:35 +00:00
|
|
|
# write_source_files() to a git ignored subdirectory of the root
|
|
|
|
genrule(
|
|
|
|
name = "write_source_file_root",
|
2023-02-17 00:59:21 +00:00
|
|
|
outs = ["write_source_file-root_directory/test.txt"],
|
|
|
|
cmd = "mkdir -p $$(dirname $@) && echo 'test' > $@",
|
2022-03-31 00:04:35 +00:00
|
|
|
visibility = ["//visibility:private"],
|
|
|
|
)
|
2022-04-01 17:49:16 +00:00
|
|
|
|
2022-03-31 00:04:35 +00:00
|
|
|
write_source_files(
|
|
|
|
name = "write_source_file_root-test",
|
|
|
|
diff_test = False,
|
2022-08-16 18:00:33 +00:00
|
|
|
files = {
|
2023-02-17 00:59:21 +00:00
|
|
|
"test-out/dist/write_source_file_root-test/test.txt": ":write_source_file_root",
|
|
|
|
"test-out/dist/write_source_file_root-test_b/test.txt": ":write_source_file_root",
|
2022-08-16 18:00:33 +00:00
|
|
|
},
|
2022-03-31 00:04:35 +00:00
|
|
|
)
|
2022-05-02 22:41:06 +00:00
|
|
|
|
|
|
|
# Test that yq works in the root package
|
|
|
|
yq(
|
|
|
|
name = "yq_root-test",
|
|
|
|
srcs = ["//lib/tests/yq:a.yaml"],
|
|
|
|
expression = ".",
|
|
|
|
)
|
2022-07-06 10:46:51 +00:00
|
|
|
|
|
|
|
# Test case: diff_test with a file in a directory prefixed with "external"
|
|
|
|
# stamped in the root package
|
|
|
|
write_file(
|
|
|
|
name = "file_in_external_prefixed_dir",
|
|
|
|
out = "external-dir/foo.txt",
|
|
|
|
content = ["foo"],
|
|
|
|
)
|
|
|
|
|
|
|
|
copy_file(
|
|
|
|
name = "copy_of_file_in_external_prefixed_dir",
|
|
|
|
src = "external-dir/foo.txt",
|
|
|
|
out = "foo_copy.txt",
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_file_has_external_prefix",
|
|
|
|
file1 = "external-dir/foo.txt",
|
|
|
|
file2 = "foo_copy.txt",
|
|
|
|
)
|
2022-09-16 18:51:48 +00:00
|
|
|
|
|
|
|
assert_contains(
|
|
|
|
name = "bazel_version_test",
|
|
|
|
actual = ".bazelversion",
|
|
|
|
expected = str(host.bazel_version),
|
|
|
|
)
|
2023-09-21 17:12:47 +00:00
|
|
|
|
|
|
|
bzl_library(
|
|
|
|
name = "deps",
|
|
|
|
srcs = ["deps.bzl"],
|
|
|
|
visibility = ["//visibility:public"],
|
2024-08-20 18:20:51 +00:00
|
|
|
deps = ["@gazelle//:deps"],
|
2023-09-21 17:12:47 +00:00
|
|
|
)
|
2024-07-02 16:27:06 +00:00
|
|
|
|
|
|
|
# Test case for mtree_spec: Ensure that multiple entries at the root directory are handled correctly (bug #851)
|
|
|
|
# See lib/tests/tar/BUILD.bazel for why this is here.
|
|
|
|
write_file(
|
|
|
|
name = "tar_test13_main",
|
|
|
|
out = "13project/__main__.py",
|
|
|
|
content = ["__main__.py"],
|
|
|
|
)
|
|
|
|
|
|
|
|
write_file(
|
|
|
|
name = "tar_test13_bin",
|
|
|
|
out = "13project_bin",
|
|
|
|
content = ["project_bin"],
|
|
|
|
)
|
|
|
|
|
|
|
|
mtree_spec(
|
|
|
|
name = "tar_test13_mtree_unsorted",
|
|
|
|
srcs = [
|
|
|
|
":tar_test13_bin",
|
|
|
|
":tar_test13_main",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# NOTE: On some systems, the mtree_spec output can have a different order.
|
|
|
|
# To make the test less brittle, we sort the mtree output and replace the BINDIR with a constant placeholder
|
|
|
|
genrule(
|
|
|
|
name = "tar_test13_mtree",
|
|
|
|
srcs = [":tar_test13_mtree_unsorted"],
|
|
|
|
outs = ["actual13.mtree"],
|
|
|
|
cmd = "sort $< | sed 's#$(BINDIR)#{BINDIR}#' >$@",
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "tar_test13",
|
|
|
|
file1 = "tar_test13_mtree",
|
|
|
|
file2 = "//lib/tests/tar:expected13.mtree",
|
|
|
|
)
|