2022-03-15 00:33:52 +00:00
|
|
|
load("//lib/tests/write_source_files:write_source_file_test.bzl", "write_source_file_test")
|
2022-03-16 00:36:22 +00:00
|
|
|
load("//lib/tests:generate_outputs.bzl", "generate_outputs")
|
2022-01-28 02:15:28 +00:00
|
|
|
load("//lib:write_source_files.bzl", "write_source_files")
|
2022-12-03 07:23:57 +00:00
|
|
|
load("//lib/private:write_source_file.bzl", "write_source_file")
|
2022-03-02 20:58:36 +00:00
|
|
|
load("//lib:copy_to_directory.bzl", "copy_to_directory")
|
2022-03-15 00:33:52 +00:00
|
|
|
load("//lib:directory_path.bzl", "directory_path")
|
2022-03-16 00:36:22 +00:00
|
|
|
load("//lib:output_files.bzl", "output_files")
|
2022-10-31 22:07:37 +00:00
|
|
|
load("//lib:testing.bzl", "assert_outputs")
|
2022-01-28 02:15:28 +00:00
|
|
|
|
|
|
|
genrule(
|
|
|
|
name = "a-desired",
|
|
|
|
outs = ["a-desired.js"],
|
2022-03-15 00:33:52 +00:00
|
|
|
cmd = "echo 'console.log(\"a*\");' > $@",
|
2022-01-28 02:15:28 +00:00
|
|
|
)
|
|
|
|
|
2022-03-16 00:36:22 +00:00
|
|
|
generate_outputs(
|
2022-03-15 00:33:52 +00:00
|
|
|
name = "b_c-desired",
|
2022-03-16 00:36:22 +00:00
|
|
|
output_contents = [
|
2022-03-15 00:33:52 +00:00
|
|
|
"""console.log(\"b*\");
|
|
|
|
""",
|
|
|
|
"not used!",
|
|
|
|
],
|
2022-03-16 00:36:22 +00:00
|
|
|
output_files = [
|
2022-03-15 00:33:52 +00:00
|
|
|
"b-desired.js",
|
|
|
|
"c-desired.js",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2022-10-31 22:07:37 +00:00
|
|
|
assert_outputs(
|
|
|
|
name = "test_assert_outputs",
|
|
|
|
actual = "b_c-desired",
|
|
|
|
expected = [
|
|
|
|
"lib/tests/write_source_files/b-desired.js",
|
|
|
|
"lib/tests/write_source_files/c-desired.js",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2022-03-16 00:36:22 +00:00
|
|
|
output_files(
|
2022-01-28 02:15:28 +00:00
|
|
|
name = "b-desired",
|
2022-03-15 00:33:52 +00:00
|
|
|
paths = ["%s/b-desired.js" % package_name()],
|
|
|
|
target = ":b_c-desired",
|
2022-01-28 02:15:28 +00:00
|
|
|
)
|
|
|
|
|
2022-03-02 20:58:36 +00:00
|
|
|
genrule(
|
2022-03-15 00:33:52 +00:00
|
|
|
name = "e-contained",
|
|
|
|
outs = ["e-contained.js"],
|
|
|
|
cmd = "echo 'console.log(\"e*\");' > $@",
|
2022-03-02 20:58:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
copy_to_directory(
|
|
|
|
name = "e_dir-desired",
|
2022-03-15 00:33:52 +00:00
|
|
|
srcs = [":e-contained"],
|
2022-03-02 20:58:36 +00:00
|
|
|
)
|
|
|
|
|
2022-12-03 07:23:57 +00:00
|
|
|
copy_to_directory(
|
|
|
|
name = "es_dir-desired",
|
|
|
|
srcs = [":e-contained"],
|
|
|
|
replace_prefixes = {
|
|
|
|
"e-contained.js": "subdir/e-contained.js",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2022-03-15 00:33:52 +00:00
|
|
|
genrule(
|
|
|
|
name = "f-contained",
|
|
|
|
outs = ["f-contained.js"],
|
|
|
|
cmd = "echo 'console.log(\"f*\");' > $@",
|
|
|
|
)
|
|
|
|
|
|
|
|
copy_to_directory(
|
|
|
|
name = "e_f_dir-desired",
|
|
|
|
srcs = [
|
|
|
|
":e-contained",
|
|
|
|
":f-contained",
|
2022-01-28 02:15:28 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2022-03-15 00:33:52 +00:00
|
|
|
directory_path(
|
|
|
|
name = "f-desired",
|
|
|
|
directory = ":e_f_dir-desired",
|
|
|
|
path = "f-contained.js",
|
|
|
|
)
|
|
|
|
|
2022-03-16 00:36:22 +00:00
|
|
|
generate_outputs(
|
|
|
|
name = "g_h-desired",
|
|
|
|
output_contents = [
|
|
|
|
"""console.log(\"g*\");
|
|
|
|
""",
|
|
|
|
"not used!",
|
|
|
|
],
|
|
|
|
output_files = [
|
|
|
|
"g-desired.js",
|
|
|
|
"h-desired.js",
|
|
|
|
],
|
|
|
|
output_group = "gh_output_group",
|
|
|
|
)
|
|
|
|
|
|
|
|
output_files(
|
|
|
|
name = "g-desired",
|
|
|
|
output_group = "gh_output_group",
|
|
|
|
paths = ["%s/g-desired.js" % package_name()],
|
|
|
|
target = ":g_h-desired",
|
|
|
|
)
|
|
|
|
|
2022-03-15 00:33:52 +00:00
|
|
|
write_source_file_test(
|
2022-12-03 07:23:57 +00:00
|
|
|
name = "a_test",
|
2022-03-15 00:33:52 +00:00
|
|
|
in_file = ":a-desired",
|
|
|
|
out_file = "a.js",
|
|
|
|
)
|
|
|
|
|
|
|
|
write_source_file_test(
|
2022-12-03 07:23:57 +00:00
|
|
|
name = "b_test",
|
2022-03-15 00:33:52 +00:00
|
|
|
in_file = ":b-desired",
|
|
|
|
out_file = "b.js",
|
|
|
|
)
|
|
|
|
|
2022-12-03 07:23:57 +00:00
|
|
|
write_source_file(
|
|
|
|
name = "e_dir_test",
|
|
|
|
in_file = ":e_dir-desired",
|
|
|
|
out_file = "e_dir",
|
|
|
|
# The diff_test that is contained within this macro takes `out_file` which is a source directory
|
|
|
|
# as an input but source directories are not supported on remote execution so we must tag that
|
|
|
|
# rule with "no-remote-exec".
|
|
|
|
# ERROR: cannot compare a directory "lib/tests/write_source_files/e_dir-desired" against a file "lib/tests/write_source_files/e_dir"
|
|
|
|
tags = ["no-remote-exec"],
|
|
|
|
)
|
|
|
|
|
|
|
|
write_source_file(
|
|
|
|
name = "es_dir_test",
|
|
|
|
in_file = ":es_dir-desired",
|
|
|
|
out_file = "es_dir",
|
|
|
|
# The diff_test that is contained within this macro takes `out_file` which is a source directory
|
|
|
|
# as an input but source directories are not supported on remote execution so we must tag that
|
|
|
|
# rule with "no-remote-exec".
|
|
|
|
# ERROR: cannot compare a directory "lib/tests/write_source_files/es_dir-desired" against a file "lib/tests/write_source_files/es_dir"
|
|
|
|
tags = ["no-remote-exec"],
|
|
|
|
)
|
|
|
|
|
2022-03-15 00:33:52 +00:00
|
|
|
write_source_file_test(
|
2022-12-03 07:23:57 +00:00
|
|
|
name = "f_test",
|
2022-03-15 00:33:52 +00:00
|
|
|
in_file = ":f-desired",
|
|
|
|
out_file = "f.js",
|
|
|
|
)
|
|
|
|
|
2022-03-16 00:36:22 +00:00
|
|
|
write_source_file_test(
|
2022-12-03 07:23:57 +00:00
|
|
|
name = "g_test",
|
2022-03-16 00:36:22 +00:00
|
|
|
in_file = ":g-desired",
|
|
|
|
out_file = "g.js",
|
|
|
|
)
|
|
|
|
|
2022-01-28 02:15:28 +00:00
|
|
|
write_source_files(
|
|
|
|
name = "macro_smoke_test",
|
2022-03-02 20:58:36 +00:00
|
|
|
additional_update_targets = [
|
|
|
|
"//lib/tests/write_source_files/subdir:macro_smoke_test",
|
|
|
|
],
|
2022-01-28 02:15:28 +00:00
|
|
|
files = {
|
|
|
|
"a2.js": ":a-desired",
|
|
|
|
"b2.js": ":b-desired",
|
2022-03-15 00:33:52 +00:00
|
|
|
"e2_dir": ":e_dir-desired",
|
2022-12-03 07:23:57 +00:00
|
|
|
"es2_dir": ":es_dir-desired",
|
2022-03-15 00:33:52 +00:00
|
|
|
"f2.js": ":f-desired",
|
2022-03-16 00:36:22 +00:00
|
|
|
"g2.js": ":g-desired",
|
2022-01-28 02:15:28 +00:00
|
|
|
},
|
2022-12-03 07:23:57 +00:00
|
|
|
# The diff_test that is contained within this macro takes output directories `es_dir` and
|
|
|
|
# `es2dir` which are source directories as inputs but source directories are not supported on
|
|
|
|
# remote execution so we must tag that rule with "no-remote-exec".
|
2022-08-18 21:18:33 +00:00
|
|
|
tags = ["no-remote-exec"],
|
2022-02-28 23:42:20 +00:00
|
|
|
)
|
2022-03-28 21:53:58 +00:00
|
|
|
|
|
|
|
genrule(
|
|
|
|
name = "dist",
|
|
|
|
outs = ["dist.js"],
|
|
|
|
cmd = "echo 'dist' > $@",
|
|
|
|
)
|
|
|
|
|
2022-12-03 07:23:57 +00:00
|
|
|
# See e2e/write_source_files
|
2022-03-28 21:53:58 +00:00
|
|
|
write_source_files(
|
|
|
|
name = "write_dist",
|
|
|
|
diff_test = False,
|
|
|
|
files = {"dist.js": ":dist"},
|
|
|
|
)
|
2022-04-06 18:25:17 +00:00
|
|
|
|
2022-12-03 07:23:57 +00:00
|
|
|
# See e2e/write_source_files
|
|
|
|
write_source_files(
|
|
|
|
name = "write_dist_executable",
|
|
|
|
diff_test = False,
|
|
|
|
executable = True,
|
|
|
|
files = {"dist_executable.js": ":dist"},
|
|
|
|
)
|
|
|
|
|
|
|
|
# Generate a file in nested directories
|
2022-04-06 18:25:17 +00:00
|
|
|
genrule(
|
|
|
|
name = "subdir",
|
|
|
|
outs = ["subdir_test"],
|
|
|
|
cmd = ";".join([
|
|
|
|
"mkdir -p $@/a/b/c",
|
|
|
|
"echo 'test' > $@/a/b/c/test.txt",
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Write nested subdirectories to source
|
|
|
|
# See e2e/write_source_files_subdir_multiple_runs
|
|
|
|
write_source_files(
|
|
|
|
name = "write_subdir",
|
|
|
|
diff_test = False,
|
|
|
|
files = {"subdir_test": ":subdir"},
|
|
|
|
)
|
|
|
|
|
2022-12-03 07:23:57 +00:00
|
|
|
# Write nested subdirectories to source
|
|
|
|
# See e2e/write_source_files_subdir_multiple_runs
|
|
|
|
write_source_files(
|
|
|
|
name = "write_subdir_executable",
|
|
|
|
diff_test = False,
|
|
|
|
executable = True,
|
|
|
|
files = {"subdir_executable_test": ":subdir"},
|
|
|
|
)
|
|
|
|
|
2022-04-06 18:25:17 +00:00
|
|
|
# Generate some directories including symlinks
|
|
|
|
genrule(
|
|
|
|
name = "symlinks",
|
|
|
|
outs = ["symlink_test"],
|
|
|
|
cmd = ";".join([
|
|
|
|
"mkdir -p $@/a $@/b",
|
|
|
|
"echo 'test' > $@/a/test.txt",
|
|
|
|
"pushd $@/b",
|
|
|
|
"ln -s ../a/test.txt",
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Write symlinks to source
|
|
|
|
# See e2e/write_source_files_symlinks
|
|
|
|
write_source_files(
|
|
|
|
name = "write_symlinks",
|
|
|
|
diff_test = False,
|
|
|
|
files = {"symlink_test": ":symlinks"},
|
2022-04-15 20:17:58 +00:00
|
|
|
)
|
2022-06-15 20:53:35 +00:00
|
|
|
|
|
|
|
write_source_files(
|
|
|
|
name = "write_from_external_repo",
|
|
|
|
files = {
|
2022-08-18 21:18:33 +00:00
|
|
|
"skylib_LICENSE": "@bazel_skylib//:LICENSE",
|
|
|
|
},
|
2022-06-15 20:53:35 +00:00
|
|
|
)
|