xref: /aosp_15_r20/external/bazel-skylib/tests/native_binary/BUILD (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1*bcb5dc79SHONG Yifanload("//rules:copy_file.bzl", "copy_file")
2*bcb5dc79SHONG Yifanload("//rules:native_binary.bzl", "native_binary", "native_test")
3*bcb5dc79SHONG Yifan
4*bcb5dc79SHONG Yifanpackage(
5*bcb5dc79SHONG Yifan    default_applicable_licenses = ["//:license"],
6*bcb5dc79SHONG Yifan    default_testonly = 1,
7*bcb5dc79SHONG Yifan    default_visibility = ["//visibility:private"],
8*bcb5dc79SHONG Yifan)
9*bcb5dc79SHONG Yifan
10*bcb5dc79SHONG Yifancc_binary(
11*bcb5dc79SHONG Yifan    name = "assertarg",
12*bcb5dc79SHONG Yifan    srcs = ["assertarg.cc"],
13*bcb5dc79SHONG Yifan)
14*bcb5dc79SHONG Yifan
15*bcb5dc79SHONG Yifancc_binary(
16*bcb5dc79SHONG Yifan    name = "assertdata",
17*bcb5dc79SHONG Yifan    srcs = ["assertdata.cc"],
18*bcb5dc79SHONG Yifan    deps = ["@bazel_tools//tools/cpp/runfiles"],
19*bcb5dc79SHONG Yifan    # Depends on the runfiles library but doesn't have data-dependencies, on
20*bcb5dc79SHONG Yifan    # purpose. We supplement the runfiles in the native_binary / native_test
21*bcb5dc79SHONG Yifan    # rule.
22*bcb5dc79SHONG Yifan)
23*bcb5dc79SHONG Yifan
24*bcb5dc79SHONG Yifancc_binary(
25*bcb5dc79SHONG Yifan    name = "assertdata_with_runfiles",
26*bcb5dc79SHONG Yifan    srcs = ["assertdata.cc"],
27*bcb5dc79SHONG Yifan    # This version depends on runfiles directly, to ensure runfiles from the
28*bcb5dc79SHONG Yifan    # binary are picked up by native_test/native_binary
29*bcb5dc79SHONG Yifan    data = ["testdata.txt"],
30*bcb5dc79SHONG Yifan    deps = ["@bazel_tools//tools/cpp/runfiles"],
31*bcb5dc79SHONG Yifan)
32*bcb5dc79SHONG Yifan
33*bcb5dc79SHONG Yifan# A rule that copies "assertarg"'s output as an opaque executable, simulating a
34*bcb5dc79SHONG Yifan# binary that's not built from source and needs to be wrapped in native_binary.
35*bcb5dc79SHONG Yifancopy_file(
36*bcb5dc79SHONG Yifan    name = "copy_assertarg_exe",
37*bcb5dc79SHONG Yifan    src = ":assertarg",
38*bcb5dc79SHONG Yifan    # On Windows we need the ".exe" extension.
39*bcb5dc79SHONG Yifan    # On other platforms the extension doesn't matter.
40*bcb5dc79SHONG Yifan    # Therefore we can use ".exe" on every platform.
41*bcb5dc79SHONG Yifan    out = "assertarg_copy.exe",
42*bcb5dc79SHONG Yifan    is_executable = True,
43*bcb5dc79SHONG Yifan)
44*bcb5dc79SHONG Yifan
45*bcb5dc79SHONG Yifan# A rule that copies "assertdata"'s output as an opaque executable, simulating a
46*bcb5dc79SHONG Yifan# binary that's not built from source and needs to be wrapped in native_binary.
47*bcb5dc79SHONG Yifancopy_file(
48*bcb5dc79SHONG Yifan    name = "copy_assertdata_exe",
49*bcb5dc79SHONG Yifan    src = ":assertdata",
50*bcb5dc79SHONG Yifan    # On Windows we need the ".exe" extension.
51*bcb5dc79SHONG Yifan    # On other platforms the extension doesn't matter.
52*bcb5dc79SHONG Yifan    # Therefore we can use ".exe" on every platform.
53*bcb5dc79SHONG Yifan    out = "assertdata_copy.exe",
54*bcb5dc79SHONG Yifan    is_executable = True,
55*bcb5dc79SHONG Yifan)
56*bcb5dc79SHONG Yifan
57*bcb5dc79SHONG Yifan_ARGS = [
58*bcb5dc79SHONG Yifan    "'a b'",
59*bcb5dc79SHONG Yifan    "c\\ d",
60*bcb5dc79SHONG Yifan    "$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)",
61*bcb5dc79SHONG Yifan    "'$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)'",
62*bcb5dc79SHONG Yifan    "$$TEST_SRCDIR",
63*bcb5dc79SHONG Yifan    "$${TEST_SRCDIR}",
64*bcb5dc79SHONG Yifan]
65*bcb5dc79SHONG Yifan
66*bcb5dc79SHONG Yifannative_binary(
67*bcb5dc79SHONG Yifan    name = "args_bin",
68*bcb5dc79SHONG Yifan    src = ":copy_assertarg_exe",
69*bcb5dc79SHONG Yifan    # On Windows we need the ".exe" extension.
70*bcb5dc79SHONG Yifan    # On other platforms the extension doesn't matter.
71*bcb5dc79SHONG Yifan    # Therefore we can use ".exe" on every platform.
72*bcb5dc79SHONG Yifan    out = "args_bin.exe",
73*bcb5dc79SHONG Yifan    args = _ARGS,
74*bcb5dc79SHONG Yifan    # We only need the data-dependency for $(location) expansion.
75*bcb5dc79SHONG Yifan    data = ["testdata.txt"],
76*bcb5dc79SHONG Yifan)
77*bcb5dc79SHONG Yifan
78*bcb5dc79SHONG Yifannative_test(
79*bcb5dc79SHONG Yifan    name = "args_test",
80*bcb5dc79SHONG Yifan    src = ":copy_assertarg_exe",
81*bcb5dc79SHONG Yifan    # On Windows we need the ".exe" extension.
82*bcb5dc79SHONG Yifan    # On other platforms the extension doesn't matter.
83*bcb5dc79SHONG Yifan    # Therefore we can use ".exe" on every platform.
84*bcb5dc79SHONG Yifan    out = "args_test.exe",
85*bcb5dc79SHONG Yifan    args = _ARGS,
86*bcb5dc79SHONG Yifan    # We only need the data-dependency for $(location) expansion.
87*bcb5dc79SHONG Yifan    data = ["testdata.txt"],
88*bcb5dc79SHONG Yifan)
89*bcb5dc79SHONG Yifan
90*bcb5dc79SHONG Yifannative_binary(
91*bcb5dc79SHONG Yifan    name = "data_bin",
92*bcb5dc79SHONG Yifan    src = ":copy_assertdata_exe",
93*bcb5dc79SHONG Yifan    # On Windows we need the ".exe" extension.
94*bcb5dc79SHONG Yifan    # On other platforms the extension doesn't matter.
95*bcb5dc79SHONG Yifan    # Therefore we can use ".exe" on every platform.
96*bcb5dc79SHONG Yifan    out = "data_bin.exe",
97*bcb5dc79SHONG Yifan    data = ["testdata.txt"],
98*bcb5dc79SHONG Yifan)
99*bcb5dc79SHONG Yifan
100*bcb5dc79SHONG Yifannative_binary(
101*bcb5dc79SHONG Yifan    name = "no_out_bin",
102*bcb5dc79SHONG Yifan    src = ":copy_assertdata_exe",
103*bcb5dc79SHONG Yifan    data = ["testdata.txt"],
104*bcb5dc79SHONG Yifan)
105*bcb5dc79SHONG Yifan
106*bcb5dc79SHONG Yifannative_test(
107*bcb5dc79SHONG Yifan    name = "data_test",
108*bcb5dc79SHONG Yifan    src = ":copy_assertdata_exe",
109*bcb5dc79SHONG Yifan    # On Windows we need the ".exe" extension.
110*bcb5dc79SHONG Yifan    # On other platforms the extension doesn't matter.
111*bcb5dc79SHONG Yifan    # Therefore we can use ".exe" on every platform.
112*bcb5dc79SHONG Yifan    out = "data_test.exe",
113*bcb5dc79SHONG Yifan    data = ["testdata.txt"],
114*bcb5dc79SHONG Yifan)
115*bcb5dc79SHONG Yifan
116*bcb5dc79SHONG Yifannative_test(
117*bcb5dc79SHONG Yifan    name = "data_from_binary_test",
118*bcb5dc79SHONG Yifan    src = ":assertdata_with_runfiles",
119*bcb5dc79SHONG Yifan    # On Windows we need the ".exe" extension.
120*bcb5dc79SHONG Yifan    # On other platforms the extension doesn't matter.
121*bcb5dc79SHONG Yifan    # Therefore we can use ".exe" on every platform.
122*bcb5dc79SHONG Yifan    out = "data_from_binary_test.exe",
123*bcb5dc79SHONG Yifan)
124