-
Notifications
You must be signed in to change notification settings - Fork 15
/
examples.bzl
76 lines (66 loc) · 2.27 KB
/
examples.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def envoy_example(name, shared = ":shared_files", common_fun = ":verify-common.sh"):
native.filegroup(
name = "%s_files" % name,
srcs = native.glob(["%s/**/*" % name]),
)
native.genrule(
name = "%s_dir" % name,
outs = ["%s_dir.tar" % name],
cmd = """
SHARED_PATHS="$(locations %s)"
SHARED=$$(echo $$SHARED_PATHS | cut -d/ -f1)
# This is a bit hacky and may not work in all bazel situations, but works for now
if [[ $$SHARED == "external" ]]; then
SHARED=$$(echo $$SHARED_PATHS | cut -d/ -f-3)
fi
EXAMPLE_PATHS="$(locations %s_files)"
EXAMPLE=$$(echo $$EXAMPLE_PATHS | cut -d/ -f1)
# This is a bit hacky and may not work in all bazel situations, but works for now
if [[ $$EXAMPLE == "external" ]]; then
EXAMPLE=$$(echo $$EXAMPLE_PATHS | cut -d/ -f-3)
fi
tar chf $@ -C . $$SHARED $(location %s) $$EXAMPLE
""" % (shared, name, common_fun),
tools = [
common_fun,
shared,
"%s_files" % name,
],
)
native.sh_binary(
name = "verify_%s" % name,
srcs = [":verify_example.sh"],
args = [
name,
"$(location :%s_dir)" % name,
],
data = [":%s_dir" % name],
)
def envoy_examples(examples):
RESULTS = []
RESULT_FILES = []
native.filegroup(
name = "shared_files",
srcs = native.glob(["shared/**/*"]),
)
for example in examples:
envoy_example(name = example, shared = ":shared_files")
native.genrule(
name = "%s_result" % example,
outs = ["%s_result.txt" % example],
cmd = """
./$(location :verify_%s) %s $(location :%s_dir) >> $@
""" % (example, example, example),
tools = [
"verify_%s" % example,
"%s_dir" % example,
],
)
RESULTS.append("%s_result" % example)
RESULT_FILES.append("$(location %s)" % ("%s_result" % example))
native.sh_binary(
name = "verify_examples",
srcs = [":verify_examples.sh"],
args = RESULT_FILES,
data = RESULTS,
)