• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Unittests for rust rules."""
2
3load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
4load("//cargo:defs.bzl", "cargo_build_script")
5load("//rust:defs.bzl", "rust_common", "rust_library", "rust_proc_macro")
6
7def _transitive_link_search_paths_test_impl(ctx):
8    env = analysistest.begin(ctx)
9    tut = analysistest.target_under_test(env)
10    link_search_path_files = tut[rust_common.dep_info].link_search_path_files.to_list()
11    link_search_path_basenames = [f.basename for f in link_search_path_files]
12
13    # Checks that this contains the dep build script, but not the build script
14    # of the dep of the proc_macro.
15    asserts.equals(env, link_search_path_basenames, ["dep_build_script.linksearchpaths"])
16
17    return analysistest.end(env)
18
19transitive_link_search_paths_test = analysistest.make(_transitive_link_search_paths_test_impl)
20
21def _transitive_link_search_paths_test():
22    cargo_build_script(
23        name = "proc_macro_build_script",
24        srcs = ["proc_macro_build.rs"],
25        edition = "2018",
26    )
27
28    rust_proc_macro(
29        name = "proc_macro",
30        srcs = ["proc_macro.rs"],
31        edition = "2018",
32        deps = [":proc_macro_build_script"],
33    )
34
35    cargo_build_script(
36        name = "dep_build_script",
37        srcs = ["dep_build.rs"],
38        edition = "2018",
39    )
40
41    rust_library(
42        name = "dep",
43        srcs = ["dep.rs"],
44        edition = "2018",
45        proc_macro_deps = [":proc_macro"],
46        deps = [":dep_build_script"],
47    )
48
49    transitive_link_search_paths_test(
50        name = "transitive_link_search_paths_test",
51        target_under_test = ":dep",
52    )
53
54def transitive_link_search_paths_test_suite(name):
55    """Entry-point macro called from the BUILD file.
56
57    Args:
58        name: Name of the macro.
59    """
60    _transitive_link_search_paths_test()
61
62    native.test_suite(
63        name = name,
64        tests = [
65            ":transitive_link_search_paths_test",
66        ],
67    )
68