Skip to content

Commit 3bc8130

Browse files
committed
basic test
1 parent add0c26 commit 3bc8130

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

tests/venv_site_packages_libs/app_files_building/app_files_building_tests.bzl

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,25 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
44
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
55
load("@rules_testing//lib:test_suite.bzl", "test_suite")
66
load("//python/private:py_info.bzl", "VenvSymlinkEntry", "VenvSymlinkKind") # buildifier: disable=bzl-visibility
7-
load("//python/private:venv_runfiles.bzl", "build_link_map") # buildifier: disable=bzl-visibility
7+
load("//python/private:venv_runfiles.bzl", "build_link_map", "get_venv_symlinks") # buildifier: disable=bzl-visibility
8+
9+
def _empty_files_impl(ctx):
10+
files = []
11+
for p in ctx.attr.paths:
12+
f = ctx.actions.declare_file(p)
13+
ctx.actions.write(output = f, content = "")
14+
files.append(f)
15+
return [DefaultInfo(files = depset(files))]
16+
17+
empty_files = rule(
18+
implementation = _empty_files_impl,
19+
attrs = {
20+
"paths": attr.string_list(
21+
doc = "A list of paths to create as files.",
22+
mandatory = True,
23+
),
24+
},
25+
)
826

927
_tests = []
1028

@@ -240,6 +258,62 @@ def _test_multiple_venv_symlink_kinds_impl(env, _):
240258
VenvSymlinkKind.INCLUDE,
241259
])
242260

261+
def _test_shared_library_symlinking(name):
262+
empty_files(
263+
name = name + "_files",
264+
# NOTE: Test relies upon order
265+
paths = [
266+
"site-packages/bar/libs/liby.so",
267+
"site-packages/bar/x.py",
268+
"site-packages/bar/y.so",
269+
"site-packages/foo.libs/libx.so",
270+
"site-packages/foo/a.py",
271+
"site-packages/foo/b.so",
272+
],
273+
)
274+
analysis_test(
275+
name = name,
276+
impl = _test_shared_library_symlinking_impl,
277+
target = name + "_files",
278+
)
279+
280+
_tests.append(_test_shared_library_symlinking)
281+
282+
def _test_shared_library_symlinking_impl(env, target):
283+
srcs = target.files.to_list()
284+
actual_entries = get_venv_symlinks(
285+
_ctx(),
286+
srcs,
287+
package = "foo",
288+
version_str = "1.0",
289+
site_packages_root = env.ctx.label.package + "/site-packages",
290+
)
291+
292+
actual = [e for e in actual_entries if e.venv_path == "foo.libs/libx.so"]
293+
if not actual:
294+
fail("Did not find VenvSymlinkEntry with venv_path equal to foo.libs/libx.so. " +
295+
"Found: {}".format(actual_entries))
296+
elif len(actual) > 1:
297+
fail("Found multiple entries with venv_path=foo.libs/libx.so. " +
298+
"Found: {}".format(actual_entries))
299+
actual = actual[0]
300+
301+
actual_files = actual.files.to_list()
302+
expected_lib_dso = [f for f in srcs if f.basename == "libx.so"]
303+
env.expect.that_collection(actual_files).contains_exactly(expected_lib_dso)
304+
305+
entries = actual_entries
306+
actual = build_link_map(_ctx(), entries)
307+
308+
expected_libs = {
309+
"bar/libs/liby.so": srcs[0],
310+
"bar/x.py": srcs[1],
311+
"bar/y.so": srcs[2],
312+
"foo": "_main/tests/venv_site_packages_libs/app_files_building/site-packages/foo",
313+
"foo.libs/libx.so": srcs[3],
314+
}
315+
env.expect.that_dict(actual[VenvSymlinkKind.LIB]).contains_exactly(expected_libs)
316+
243317
def app_files_building_test_suite(name):
244318
test_suite(
245319
name = name,

0 commit comments

Comments
 (0)