1load("//rules:copy_file.bzl", "copy_file") 2load("//rules:native_binary.bzl", "native_binary", "native_test") 3 4package( 5 default_applicable_licenses = ["//:license"], 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 24cc_binary( 25 name = "assertdata_with_runfiles", 26 srcs = ["assertdata.cc"], 27 # This version depends on runfiles directly, to ensure runfiles from the 28 # binary are picked up by native_test/native_binary 29 data = ["testdata.txt"], 30 deps = ["@bazel_tools//tools/cpp/runfiles"], 31) 32 33# A rule that copies "assertarg"'s output as an opaque executable, simulating a 34# binary that's not built from source and needs to be wrapped in native_binary. 35copy_file( 36 name = "copy_assertarg_exe", 37 src = ":assertarg", 38 # On Windows we need the ".exe" extension. 39 # On other platforms the extension doesn't matter. 40 # Therefore we can use ".exe" on every platform. 41 out = "assertarg_copy.exe", 42 is_executable = True, 43) 44 45# A rule that copies "assertdata"'s output as an opaque executable, simulating a 46# binary that's not built from source and needs to be wrapped in native_binary. 47copy_file( 48 name = "copy_assertdata_exe", 49 src = ":assertdata", 50 # On Windows we need the ".exe" extension. 51 # On other platforms the extension doesn't matter. 52 # Therefore we can use ".exe" on every platform. 53 out = "assertdata_copy.exe", 54 is_executable = True, 55) 56 57_ARGS = [ 58 "'a b'", 59 "c\\ d", 60 "$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)", 61 "'$(location testdata.txt) $$(location testdata.txt) $(location testdata.txt)'", 62 "$$TEST_SRCDIR", 63 "$${TEST_SRCDIR}", 64] 65 66native_binary( 67 name = "args_bin", 68 src = ":copy_assertarg_exe", 69 # On Windows we need the ".exe" extension. 70 # On other platforms the extension doesn't matter. 71 # Therefore we can use ".exe" on every platform. 72 out = "args_bin.exe", 73 args = _ARGS, 74 # We only need the data-dependency for $(location) expansion. 75 data = ["testdata.txt"], 76) 77 78native_test( 79 name = "args_test", 80 src = ":copy_assertarg_exe", 81 # On Windows we need the ".exe" extension. 82 # On other platforms the extension doesn't matter. 83 # Therefore we can use ".exe" on every platform. 84 out = "args_test.exe", 85 args = _ARGS, 86 # We only need the data-dependency for $(location) expansion. 87 data = ["testdata.txt"], 88) 89 90native_binary( 91 name = "data_bin", 92 src = ":copy_assertdata_exe", 93 # On Windows we need the ".exe" extension. 94 # On other platforms the extension doesn't matter. 95 # Therefore we can use ".exe" on every platform. 96 out = "data_bin.exe", 97 data = ["testdata.txt"], 98) 99 100native_binary( 101 name = "no_out_bin", 102 src = ":copy_assertdata_exe", 103 data = ["testdata.txt"], 104) 105 106native_test( 107 name = "data_test", 108 src = ":copy_assertdata_exe", 109 # On Windows we need the ".exe" extension. 110 # On other platforms the extension doesn't matter. 111 # Therefore we can use ".exe" on every platform. 112 out = "data_test.exe", 113 data = ["testdata.txt"], 114) 115 116native_test( 117 name = "data_from_binary_test", 118 src = ":assertdata_with_runfiles", 119 # On Windows we need the ".exe" extension. 120 # On other platforms the extension doesn't matter. 121 # Therefore we can use ".exe" on every platform. 122 out = "data_from_binary_test.exe", 123) 124