feat(third_party/bazel): Check in rules_haskell from Tweag

This commit is contained in:
Vincent Ambo 2019-07-04 11:18:12 +01:00
parent 2eb1dc26e4
commit f723b8b878
479 changed files with 51484 additions and 0 deletions

View file

@ -0,0 +1,125 @@
load(
":tests.bzl",
"create_rpath_entry_test",
"dedup_on_test",
"parent_dir_path_test",
)
parent_dir_path_test(
name = "parent_dir_just_file",
filename = "foo",
output = ["."],
)
parent_dir_path_test(
name = "parent_dir",
filename = "foo/",
output = ["foo"],
)
parent_dir_path_test(
name = "parent_dir_file",
filename = "foo/bar",
output = ["foo"],
)
parent_dir_path_test(
name = "parent_dir_file_dots",
filename = "foo/../bar",
output = [
"foo",
"..",
],
)
parent_dir_path_test(
name = "parent_dir_rooted",
filename = "/foo/bar",
output = [
"",
"foo",
],
)
create_rpath_entry_test(
name = "rpath_entry_simple",
binary_short_path = "foo/a.so",
dependency_short_path = "bar/b.so",
output = "../bar",
)
# checks that a binary in //:bin works properly
create_rpath_entry_test(
name = "rpath_entry_binary_root",
binary_short_path = "bin",
dependency_short_path = "xyz/b.so",
output = "xyz",
)
# same for dependency
create_rpath_entry_test(
name = "rpath_entry_dep_root",
binary_short_path = "lib/bin",
dependency_short_path = "b.so",
output = "..",
)
create_rpath_entry_test(
name = "rpath_entry_simple_filename",
binary_short_path = "foo/a.so",
dependency_short_path = "bar/b.so",
keep_filename = True,
output = "../bar/b.so",
)
create_rpath_entry_test(
name = "rpath_entry_prefix",
binary_short_path = "foo/a.so",
dependency_short_path = "bar/b.so",
output = "$ORIGIN/../bar",
prefix = "$ORIGIN",
)
# if the short-paths have leading dots, they are in `external`
create_rpath_entry_test(
name = "rpath_entry_binary_leading_dots_dep",
# non-external
binary_short_path = "foo/a.so",
# external dep
dependency_short_path = "../bar/b.so",
output = "../external/bar",
)
create_rpath_entry_test(
name = "rpath_entry_binary_leading_dots_bin",
# external dep
binary_short_path = "../foo/a.so",
# non-external
dependency_short_path = "bar/b.so",
# back through `external`
output = "../../bar",
)
create_rpath_entry_test(
name = "rpath_entry_binary_leading_dots_both",
# external dep
binary_short_path = "../foo/a.so",
# external dep
dependency_short_path = "../bar/b.so",
# stay in `external`
output = "../bar",
)
# we have no idea how to handle internal dots, should they arise
# create_rpath_entry_test(
# name = "rpath_entry_binary_internal_dots",
# binary_short_path = "foo/../../a.so",
# dependency_short_path = "../bar/../b.so",
# # but that doesnt change anything for the runpath
# output = "../bar",
# )
dedup_on_test(
name = "dedup_on_test",
)

View file

@ -0,0 +1,83 @@
load(
"@bazel_skylib//lib:unittest.bzl",
"asserts",
unit = "unittest",
)
load("//haskell:private/actions/link.bzl", "create_rpath_entry", "parent_dir_path")
load("//haskell:private/list.bzl", "list")
def parent_dir_path_test_impl(ctx):
env = unit.begin(ctx)
asserts.equals(
env,
expected = ctx.attr.output,
actual = parent_dir_path(ctx.attr.filename),
)
unit.end(env)
parent_dir_path_test = unit.make(
parent_dir_path_test_impl,
attrs = {
"filename": attr.string(),
"output": attr.string_list(),
},
)
def create_rpath_entry_test_impl(ctx):
env = unit.begin(ctx)
asserts.equals(
env,
expected = ctx.attr.output,
actual = create_rpath_entry(
struct(
short_path = ctx.attr.binary_short_path,
),
struct(
short_path = ctx.attr.dependency_short_path,
),
keep_filename = ctx.attr.keep_filename,
prefix = ctx.attr.prefix,
),
)
unit.end(env)
create_rpath_entry_test = unit.make(
create_rpath_entry_test_impl,
attrs = {
"binary_short_path": attr.string(),
"dependency_short_path": attr.string(),
"keep_filename": attr.bool(default = False, mandatory = False),
"prefix": attr.string(default = "", mandatory = False),
"output": attr.string(),
},
)
def compare_x(el):
return el.x
def dedup_on_test_impl(ctx):
env = unit.begin(ctx)
asserts.equals(
env,
expected = [],
actual = list.dedup_on(compare_x, []),
)
asserts.equals(
env,
expected = [struct(x = 3)],
actual = list.dedup_on(
compare_x,
[struct(x = 3), struct(x = 3), struct(x = 3)],
),
)
asserts.equals(
env,
expected = [struct(x = 3), struct(x = 4), struct(x = 5)],
actual = list.dedup_on(
compare_x,
[struct(x = 3), struct(x = 4), struct(x = 3), struct(x = 5), struct(x = 3)],
),
)
unit.end(env)
dedup_on_test = unit.make(dedup_on_test_impl)