• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("//rules:copy_file.bzl", "copy_file")
2load("//rules:native_binary.bzl", "native_binary", "native_test")
3load("@rules_cc//cc:defs.bzl", "cc_binary")
4
5package(
6    default_testonly = 1,
7    default_visibility = ["//visibility:private"],
8)
9
10cc_binary(
11    name = "assertarg",
12    srcs = ["assertarg.cc"],
13)
14
15cc_binary(
16    name = "assertdata",
17    srcs = ["assertdata.cc"],
18    deps = ["@bazel_tools//tools/cpp/runfiles"],
19    # Depends on the runfiles library but doesn't have data-dependencies, on
20    # purpose. We supplement the runfiles in the native_binary / native_test
21    # rule.
22)
23
24# A rule that copies "assertarg"'s output as an opaque executable, simulating a
25# binary that's not built from source and needs to be wrapped in native_binary.
26copy_file(
27    name = "copy_assertarg_exe",
28    src = ":assertarg",
29    # On Windows we need the ".exe" extension.
30    # On other platforms the extension doesn't matter.
31    # Therefore we can use ".exe" on every platform.
32    out = "assertarg_copy.exe",
33    is_executable = True,
34)
35
36# A rule that copies "assertdata"'s output as an opaque executable, simulating a
37# binary that's not built from source and needs to be wrapped in native_binary.
38copy_file(
39    name = "copy_assertdata_exe",
40    src = ":assertdata",
41    # On Windows we need the ".exe" extension.
42    # On other platforms the extension doesn't matter.
43    # Therefore we can use ".exe" on every platform.
44    out = "assertdata_copy.exe",
45    is_executable = True,
46)
47
48_ARGS = [
49    "'a b'",
50    "c\\ d",
51    "$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)",
52    "'$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)'",
53    "$$TEST_SRCDIR",
54
55    # TODO(laszlocsomor): uncomment this (and its counterpart in assertarg.cc)
56    # after https://github.com/bazelbuild/bazel/issues/6622 is resolved and the
57    # Bash-less test wrapper is the default on Windows.
58    # "$${TEST_SRCDIR}",
59]
60
61native_binary(
62    name = "args_bin",
63    src = ":copy_assertarg_exe",
64    # On Windows we need the ".exe" extension.
65    # On other platforms the extension doesn't matter.
66    # Therefore we can use ".exe" on every platform.
67    out = "args_bin.exe",
68    args = _ARGS,
69    # We only need the data-dependency for $(location) expansion.
70    data = ["testdata.txt"],
71)
72
73native_test(
74    name = "args_test",
75    src = ":copy_assertarg_exe",
76    # On Windows we need the ".exe" extension.
77    # On other platforms the extension doesn't matter.
78    # Therefore we can use ".exe" on every platform.
79    out = "args_test.exe",
80    args = _ARGS,
81    # We only need the data-dependency for $(location) expansion.
82    data = ["testdata.txt"],
83)
84
85native_binary(
86    name = "data_bin",
87    src = ":copy_assertdata_exe",
88    # On Windows we need the ".exe" extension.
89    # On other platforms the extension doesn't matter.
90    # Therefore we can use ".exe" on every platform.
91    out = "data_bin.exe",
92    data = ["testdata.txt"],
93)
94
95native_test(
96    name = "data_test",
97    src = ":copy_assertdata_exe",
98    # On Windows we need the ".exe" extension.
99    # On other platforms the extension doesn't matter.
100    # Therefore we can use ".exe" on every platform.
101    out = "data_test.exe",
102    data = ["testdata.txt"],
103)
104