• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Analysis tests for debug info in cdylib and bin targets."""
2
3load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
4load("//rust:defs.bzl", "rust_binary", "rust_shared_library", "rust_test")
5
6def _pdb_file_test_impl(ctx):
7    env = analysistest.begin(ctx)
8    target = analysistest.target_under_test(env)
9
10    files = target[DefaultInfo].files.to_list()
11    asserts.equals(env, len(files), 1)
12    file = files[0]
13    asserts.equals(env, file.extension, "pdb")
14
15    return analysistest.end(env)
16
17pdb_file_test = analysistest.make(_pdb_file_test_impl)
18
19def _dsym_folder_test_impl(ctx):
20    env = analysistest.begin(ctx)
21    target = analysistest.target_under_test(env)
22
23    files = target[DefaultInfo].files.to_list()
24    asserts.equals(env, len(files), 1)
25    file = files[0]
26    asserts.equals(env, file.extension, "dSYM")
27
28    return analysistest.end(env)
29
30dsym_folder_test = analysistest.make(_dsym_folder_test_impl)
31
32def debug_info_analysis_test_suite(name):
33    """Analysis tests for debug info in cdylib and bin targets.
34
35    Args:
36        name: the test suite name
37    """
38    rust_shared_library(
39        name = "mylib",
40        srcs = ["lib.rs"],
41        edition = "2018",
42    )
43
44    native.filegroup(
45        name = "mylib.pdb",
46        srcs = [":mylib"],
47        output_group = "pdb_file",
48    )
49
50    pdb_file_test(
51        name = "lib_pdb_test",
52        target_under_test = ":mylib.pdb",
53        target_compatible_with = ["@platforms//os:windows"],
54    )
55
56    native.filegroup(
57        name = "mylib.dSYM",
58        srcs = [":mylib"],
59        output_group = "dsym_folder",
60    )
61
62    dsym_folder_test(
63        name = "lib_dsym_test",
64        target_under_test = ":mylib.dSYM",
65        target_compatible_with = ["@platforms//os:macos"],
66    )
67
68    rust_binary(
69        name = "myrustbin",
70        srcs = ["main.rs"],
71        edition = "2018",
72    )
73
74    native.filegroup(
75        name = "mybin.pdb",
76        srcs = [":myrustbin"],
77        output_group = "pdb_file",
78    )
79
80    pdb_file_test(
81        name = "bin_pdb_test",
82        target_under_test = ":mybin.pdb",
83        target_compatible_with = ["@platforms//os:windows"],
84    )
85
86    native.filegroup(
87        name = "mybin.dSYM",
88        srcs = [":myrustbin"],
89        output_group = "dsym_folder",
90    )
91
92    dsym_folder_test(
93        name = "bin_dsym_test",
94        target_under_test = ":mybin.dSYM",
95        target_compatible_with = ["@platforms//os:macos"],
96    )
97
98    rust_test(
99        name = "myrusttest",
100        srcs = ["test.rs"],
101        edition = "2018",
102    )
103
104    native.filegroup(
105        name = "mytest.pdb",
106        srcs = [":myrusttest"],
107        output_group = "pdb_file",
108        testonly = True,
109    )
110
111    pdb_file_test(
112        name = "test_pdb_test",
113        target_under_test = ":mytest.pdb",
114        target_compatible_with = ["@platforms//os:windows"],
115    )
116
117    native.filegroup(
118        name = "mytest.dSYM",
119        srcs = [":myrusttest"],
120        output_group = "dsym_folder",
121        testonly = True,
122    )
123
124    dsym_folder_test(
125        name = "test_dsym_test",
126        target_under_test = ":mytest.dSYM",
127        target_compatible_with = ["@platforms//os:macos"],
128    )
129
130    native.test_suite(
131        name = name,
132        tests = [
133            ":lib_pdb_test",
134            ":lib_dsym_test",
135            ":bin_pdb_test",
136            ":bin_dsym_test",
137            ":test_pdb_test",
138            ":test_dsym_test",
139        ],
140    )
141