2021-11-17 05:30:32 +00:00
|
|
|
"tests for copy_to_directory"
|
|
|
|
|
2022-04-05 20:38:54 +00:00
|
|
|
load("//lib:copy_directory.bzl", "copy_directory")
|
2021-11-17 05:30:32 +00:00
|
|
|
load("//lib:copy_to_directory.bzl", "copy_to_directory")
|
2023-09-29 21:42:33 +00:00
|
|
|
load("//lib:diff_test.bzl", "diff_test")
|
2022-03-04 00:40:32 +00:00
|
|
|
load("//lib:directory_path.bzl", "make_directory_paths")
|
2021-11-17 05:30:32 +00:00
|
|
|
|
|
|
|
[
|
2022-04-05 20:38:54 +00:00
|
|
|
copy_directory(
|
2021-11-17 05:30:32 +00:00
|
|
|
name = "%s" % d,
|
|
|
|
src = "dir_%s" % d,
|
|
|
|
out = "%s" % d,
|
|
|
|
)
|
|
|
|
for d in [
|
|
|
|
"a",
|
|
|
|
"b",
|
|
|
|
"expected_1",
|
|
|
|
"expected_2",
|
|
|
|
"expected_3",
|
|
|
|
"expected_4",
|
|
|
|
"expected_5",
|
2021-12-16 21:52:29 +00:00
|
|
|
"expected_7",
|
|
|
|
"expected_8",
|
2022-03-04 00:40:32 +00:00
|
|
|
"expected_9",
|
2022-05-20 03:30:25 +00:00
|
|
|
"expected_10",
|
2022-07-27 22:15:42 +00:00
|
|
|
"expected_13_14",
|
2022-07-29 23:16:33 +00:00
|
|
|
"expected_15",
|
|
|
|
"expected_16",
|
|
|
|
"expected_17",
|
|
|
|
"expected_18",
|
2022-07-30 01:46:34 +00:00
|
|
|
"expected_19",
|
2022-08-18 17:07:12 +00:00
|
|
|
"expected_20",
|
2022-11-08 02:28:04 +00:00
|
|
|
"expected_21",
|
2021-11-17 05:30:32 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
case_srcs = [
|
|
|
|
":a",
|
|
|
|
":b",
|
|
|
|
":c",
|
|
|
|
":d",
|
2022-07-27 22:15:42 +00:00
|
|
|
":e/e1",
|
2021-11-17 05:30:32 +00:00
|
|
|
":e/e2",
|
2022-07-27 22:15:42 +00:00
|
|
|
"//lib/tests/copy_to_directory/f/f2:f1",
|
2021-11-17 05:30:32 +00:00
|
|
|
"//lib/tests/copy_to_directory/f/f2:f2",
|
|
|
|
"@external_test_repo//:test_a",
|
|
|
|
"@external_test_repo//:test_b",
|
|
|
|
"@external_test_repo//:test_c",
|
|
|
|
"@external_test_repo//:test_d",
|
|
|
|
]
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 1: default settings (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_1",
|
|
|
|
srcs = case_srcs,
|
2022-07-29 23:16:33 +00:00
|
|
|
include_external_repositories = ["externa?_*_rep*"],
|
2021-11-17 05:30:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_1_test",
|
|
|
|
file1 = "case_1",
|
|
|
|
file2 = ":expected_1",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 2: replace_prefixes (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_2",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
replace_prefixes = {
|
|
|
|
# merge a, b, c, d into a new/abcd dest folder
|
|
|
|
"a": "new/abcd",
|
|
|
|
"b": "//new///abcd////",
|
|
|
|
"c": "new/abcd/c",
|
|
|
|
"d": "////new/////abcd////d",
|
|
|
|
# put e into new/e except for e/e2 which goes into new/e2
|
|
|
|
"e": "new/e",
|
|
|
|
"e/e2": "new/e2/e2",
|
2022-07-27 22:15:42 +00:00
|
|
|
# f/f2/f1 => new/ff1 and f/f2/f2 => new/f2/f2
|
2021-11-17 05:30:32 +00:00
|
|
|
"f/f2/": "////new/////f",
|
|
|
|
"f/f2/f2": "////new/////f2///f2",
|
|
|
|
# flatten test_a & test_b to the root
|
|
|
|
"test_a": "",
|
|
|
|
"test_b": "",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_2_test",
|
|
|
|
file1 = "case_2",
|
|
|
|
file2 = ":expected_2",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 3: no root_paths (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_3",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
root_paths = [],
|
2023-01-07 19:26:27 +00:00
|
|
|
verbose = True,
|
2021-11-17 05:30:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_3_test",
|
|
|
|
file1 = "case_3",
|
|
|
|
file2 = ":expected_3",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 4: no root_paths + replace_prefixes (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_4",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
replace_prefixes = {
|
|
|
|
# strip lib/tests from paths
|
|
|
|
"lib/tests/": "",
|
|
|
|
# except for a few which should match due to longest match wins
|
|
|
|
"lib/tests/copy_to_directory/a": "lib/other/copy_to_directory",
|
|
|
|
"lib/tests/copy_to_directory/c": "lib/other/copy_to_directory/c",
|
|
|
|
},
|
|
|
|
root_paths = [],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_4_test",
|
|
|
|
file1 = "case_4",
|
|
|
|
file2 = ":expected_4",
|
|
|
|
)
|
|
|
|
|
2021-12-16 21:52:29 +00:00
|
|
|
# Case 5: custom root packages (with external repo)
|
2021-11-17 05:30:32 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_5",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-11-17 05:30:32 +00:00
|
|
|
root_paths = [
|
|
|
|
package_name(),
|
|
|
|
"%s/e" % package_name(),
|
|
|
|
"%s/f" % package_name(),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_5_test",
|
|
|
|
file1 = "case_5",
|
|
|
|
file2 = ":expected_5",
|
|
|
|
)
|
2021-12-02 01:09:48 +00:00
|
|
|
|
|
|
|
# Case 6: directory used in a test's runfiles
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_6",
|
|
|
|
srcs = case_srcs,
|
2021-12-16 21:52:29 +00:00
|
|
|
include_external_repositories = ["external_test_repo"],
|
2021-12-02 01:09:48 +00:00
|
|
|
)
|
|
|
|
|
2024-09-19 01:16:14 +00:00
|
|
|
# TODO: This test is a false positive. sh_test always includes default
|
|
|
|
# outputs in runfiles, so even if copy_to_directory did not add its output
|
|
|
|
# to its runfiles this test would still pass.
|
|
|
|
# See https://github.com/bazelbuild/bazel/issues/4519.
|
2021-12-02 01:09:48 +00:00
|
|
|
sh_test(
|
|
|
|
name = "case_6_test",
|
2022-08-20 19:53:12 +00:00
|
|
|
timeout = "short",
|
2021-12-02 01:09:48 +00:00
|
|
|
srcs = ["case6.sh"],
|
|
|
|
data = ["case_6"],
|
|
|
|
)
|
2021-12-16 21:52:29 +00:00
|
|
|
|
|
|
|
# Case 7: default settings
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_7",
|
|
|
|
srcs = case_srcs,
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_7_test",
|
|
|
|
file1 = "case_7",
|
|
|
|
file2 = ":expected_7",
|
|
|
|
)
|
|
|
|
|
2022-07-28 19:50:41 +00:00
|
|
|
# Case 8: exclude_srcs_patterns
|
2021-12-16 21:52:29 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_8",
|
|
|
|
srcs = case_srcs,
|
2022-07-28 19:50:41 +00:00
|
|
|
exclude_srcs_patterns = [
|
2023-01-07 19:26:27 +00:00
|
|
|
"a/*",
|
|
|
|
"b/*",
|
2022-07-28 19:50:41 +00:00
|
|
|
"e/e*",
|
2021-12-16 21:52:29 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2023-01-07 19:26:27 +00:00
|
|
|
diff_test(
|
|
|
|
name = "case_8_test",
|
|
|
|
file1 = "case_8",
|
|
|
|
file2 = ":expected_8",
|
|
|
|
)
|
|
|
|
|
2022-03-04 00:40:32 +00:00
|
|
|
# Case 9: directory_path srcs & replace_prefixes (with external repo)
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_9",
|
|
|
|
srcs = [
|
|
|
|
":c",
|
|
|
|
":d",
|
2022-07-27 22:15:42 +00:00
|
|
|
":e/e1",
|
2022-03-04 00:40:32 +00:00
|
|
|
":e/e2",
|
2023-06-09 23:22:37 +00:00
|
|
|
"//lib/tests/copy_to_directory/f/f2",
|
2022-07-27 22:15:42 +00:00
|
|
|
"//lib/tests/copy_to_directory/f/f2:f1",
|
2022-03-04 00:40:32 +00:00
|
|
|
"@external_test_repo//:test_c",
|
|
|
|
"@external_test_repo//:test_d",
|
|
|
|
] + make_directory_paths(
|
|
|
|
"case_9_srcs",
|
|
|
|
{
|
|
|
|
":a": "a",
|
|
|
|
":b": [
|
|
|
|
"b",
|
|
|
|
"b2",
|
|
|
|
],
|
|
|
|
"@external_test_repo//:test_a": "test_a",
|
|
|
|
"@external_test_repo//:test_b": "test_b",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
include_external_repositories = ["external_test_repo"],
|
|
|
|
replace_prefixes = {
|
|
|
|
# merge a, b, c, d into a new/abcd dest folder
|
|
|
|
"a/a": "new/abcd/a",
|
|
|
|
"b": "//new///abcd////",
|
|
|
|
"c": "new/abcd/c",
|
|
|
|
"d": "////new/////abcd////d",
|
|
|
|
# put e into new/e except for e/e2 which goes into new/e2
|
|
|
|
"e": "new/e",
|
|
|
|
"e/e2": "new/e2/e2",
|
2022-07-27 22:15:42 +00:00
|
|
|
# f/f2/f1 => new/ff1 and f/f2/f2 => new/f2/f2
|
2022-03-04 00:40:32 +00:00
|
|
|
"f/f2/": "////new/////f",
|
|
|
|
"f/f2/f2": "////new/////f2///f2",
|
|
|
|
# flatten test_a & test_b to the root
|
|
|
|
"test_a": "",
|
|
|
|
"test_b": "",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_9_test",
|
|
|
|
file1 = "case_9",
|
|
|
|
file2 = ":expected_9",
|
|
|
|
)
|
|
|
|
|
2022-05-20 03:30:25 +00:00
|
|
|
# Case 10: copy folder containing hidden file
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_10",
|
|
|
|
srcs = [
|
|
|
|
":dir_g",
|
|
|
|
],
|
|
|
|
replace_prefixes = {
|
|
|
|
"dir_g": "",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_10_test",
|
|
|
|
file1 = "case_10",
|
|
|
|
file2 = ":expected_10",
|
|
|
|
)
|
2022-06-08 22:41:54 +00:00
|
|
|
|
|
|
|
copy_directory(
|
|
|
|
name = "g1_out",
|
|
|
|
src = "g1",
|
|
|
|
out = "g1_out",
|
|
|
|
)
|
|
|
|
|
2022-06-14 17:52:40 +00:00
|
|
|
copy_directory(
|
|
|
|
name = "g1'_out",
|
|
|
|
src = "g1'",
|
|
|
|
out = "g1'_out",
|
|
|
|
)
|
|
|
|
|
2022-06-08 22:41:54 +00:00
|
|
|
copy_directory(
|
|
|
|
name = "g2_out",
|
|
|
|
src = "g2",
|
|
|
|
out = "g2_out",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Case 11: two inputs with same subfolders
|
2024-09-18 00:05:35 +00:00
|
|
|
# regression test for https://github.com/bazel-contrib/bazel-lib/issues/133
|
2022-06-08 22:41:54 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_11",
|
|
|
|
srcs = [
|
|
|
|
"g1_out",
|
|
|
|
"g2_out",
|
|
|
|
],
|
|
|
|
root_paths = [
|
|
|
|
"{}/g1_out".format(package_name()),
|
|
|
|
"{}/g2_out".format(package_name()),
|
|
|
|
],
|
|
|
|
)
|
2022-06-14 17:52:40 +00:00
|
|
|
|
|
|
|
# Case 12: srcs with overwrites
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_12",
|
|
|
|
srcs = [
|
|
|
|
"g1",
|
|
|
|
"g1'",
|
|
|
|
"g1'_out",
|
|
|
|
"g1_out",
|
|
|
|
],
|
|
|
|
allow_overwrites = True,
|
|
|
|
root_paths = [
|
|
|
|
"{}/g1".format(package_name()),
|
|
|
|
"{}/g1'".format(package_name()),
|
|
|
|
"{}/g1_out".format(package_name()),
|
|
|
|
"{}/g1'_out".format(package_name()),
|
|
|
|
],
|
|
|
|
)
|
2022-07-27 22:15:42 +00:00
|
|
|
|
2022-07-28 19:50:41 +00:00
|
|
|
# Case 13: include_srcs_patterns
|
2022-07-27 22:15:42 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_13",
|
|
|
|
srcs = case_srcs,
|
2022-07-28 19:50:41 +00:00
|
|
|
include_srcs_patterns = [
|
2023-01-07 19:26:27 +00:00
|
|
|
"a/*",
|
|
|
|
"b/*",
|
2022-07-28 19:59:30 +00:00
|
|
|
"?/e*",
|
2022-07-27 22:15:42 +00:00
|
|
|
"f/f2/f2",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_13_test",
|
|
|
|
file1 = "case_13",
|
|
|
|
file2 = ":expected_13_14",
|
|
|
|
)
|
|
|
|
|
2022-07-28 19:50:41 +00:00
|
|
|
# Case 14: include_srcs_patterns & exclude_srcs_patterns
|
2022-07-27 22:15:42 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_14",
|
|
|
|
srcs = case_srcs,
|
2022-07-28 19:50:41 +00:00
|
|
|
exclude_srcs_patterns = [
|
2022-07-27 22:15:42 +00:00
|
|
|
"f/f2/f1",
|
|
|
|
],
|
2022-07-28 19:50:41 +00:00
|
|
|
include_srcs_patterns = [
|
2023-01-07 19:26:27 +00:00
|
|
|
"a/*",
|
|
|
|
"b/*",
|
2022-07-28 19:59:30 +00:00
|
|
|
"?/e*",
|
|
|
|
"f/f?/**",
|
2022-07-27 22:15:42 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_14_test",
|
|
|
|
file1 = "case_14",
|
|
|
|
file2 = ":expected_13_14",
|
|
|
|
)
|
2022-07-29 23:16:33 +00:00
|
|
|
|
|
|
|
# Case 15: include_srcs_packages
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_15",
|
|
|
|
srcs = case_srcs,
|
|
|
|
include_external_repositories = ["externa?_*_rep*"],
|
2022-07-30 01:46:34 +00:00
|
|
|
include_srcs_packages = ["."],
|
2022-07-29 23:16:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_15_test",
|
|
|
|
file1 = "case_15",
|
|
|
|
file2 = ":expected_15",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Case 16: include_srcs_packages multiple with root package
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_16",
|
|
|
|
srcs = case_srcs,
|
|
|
|
include_external_repositories = ["externa?_*_rep*"],
|
|
|
|
include_srcs_packages = [
|
2022-07-30 01:46:34 +00:00
|
|
|
".",
|
2022-07-29 23:16:33 +00:00
|
|
|
"",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_16_test",
|
|
|
|
file1 = "case_16",
|
|
|
|
file2 = ":expected_16",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Case 17: exclude_srcs_packages
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_17",
|
|
|
|
srcs = case_srcs,
|
2022-07-30 01:48:09 +00:00
|
|
|
exclude_srcs_packages = ["."],
|
2022-07-29 23:16:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_17_test",
|
|
|
|
file1 = "case_17",
|
|
|
|
file2 = ":expected_17",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Case 18: exclude_srcs_packages to exclude all subpackages
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_18",
|
|
|
|
srcs = case_srcs,
|
2023-01-07 19:26:27 +00:00
|
|
|
exclude_srcs_packages = ["./*/**"],
|
2022-07-29 23:16:33 +00:00
|
|
|
include_external_repositories = ["e?ter*_test_repo"],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_18_test",
|
|
|
|
file1 = "case_18",
|
|
|
|
file2 = ":expected_18",
|
|
|
|
)
|
2022-07-30 01:46:34 +00:00
|
|
|
|
2023-01-07 19:26:27 +00:00
|
|
|
# Case 19: include_srcs_packages with "./*/**" expansion
|
2022-07-30 01:46:34 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "case_19",
|
|
|
|
srcs = case_srcs,
|
|
|
|
include_external_repositories = ["externa?_*_rep*"],
|
2023-01-07 19:26:27 +00:00
|
|
|
include_srcs_packages = ["./*/**"],
|
2022-07-30 01:46:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_19_test",
|
|
|
|
file1 = "case_19",
|
|
|
|
file2 = ":expected_19",
|
|
|
|
)
|
2022-08-18 17:07:12 +00:00
|
|
|
|
|
|
|
# Case 20: handling of root_paths in the presence of globs in dependencies.
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_20_a",
|
|
|
|
srcs = glob(["dir_a/*"]),
|
|
|
|
)
|
|
|
|
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_20",
|
|
|
|
srcs = [
|
|
|
|
":case_20_a",
|
|
|
|
],
|
|
|
|
root_paths = [
|
|
|
|
"%s/case_20_a" % package_name(),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_20_test",
|
|
|
|
file1 = "case_20",
|
|
|
|
file2 = ":expected_20",
|
2022-08-20 19:53:12 +00:00
|
|
|
)
|
2022-11-08 02:28:04 +00:00
|
|
|
|
|
|
|
# Case 21: "**" root_paths
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_21",
|
|
|
|
srcs = case_srcs,
|
|
|
|
root_paths = ["**"],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_21_test",
|
|
|
|
file1 = "case_21",
|
|
|
|
file2 = ":expected_21",
|
|
|
|
)
|
2024-06-21 17:33:00 +00:00
|
|
|
|
|
|
|
# Case 22: empty sources creates an empty directory output
|
|
|
|
copy_to_directory(
|
|
|
|
name = "case_22",
|
|
|
|
srcs = [],
|
|
|
|
)
|
|
|
|
|
|
|
|
copy_to_directory(
|
|
|
|
name = "expected_22",
|
|
|
|
srcs = ["dir_expected_22"],
|
|
|
|
exclude_srcs_patterns = ["**/filter_me_out"],
|
|
|
|
)
|
|
|
|
|
|
|
|
diff_test(
|
|
|
|
name = "case_22_test",
|
|
|
|
file1 = "case_22",
|
|
|
|
file2 = ":expected_22",
|
|
|
|
tags = ["local"], # seems that the Bazel sandbox has trouble with empty directories
|
|
|
|
)
|