-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathexamples.bzl
More file actions
90 lines (83 loc) · 2.69 KB
/
examples.bzl
File metadata and controls
90 lines (83 loc) · 2.69 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
def envoy_example(name, shared = ":shared_files", common_fun = ":verify-common.sh"):
native.filegroup(
name = "%s_files" % name,
srcs = native.glob(
["%s/**/*" % name],
exclude = [
"%s/**/node_modules/**" % name,
"%s/**/dist/**" % name,
],
),
)
native.genrule(
name = "%s_dir" % name,
outs = ["%s_dir.tar" % name],
cmd = """
read -ra SHARED_PATHS <<< "$(locations %s)"
SHARED_DIR=$$(echo $${SHARED_PATHS[0]} | cut -d/ -f1)
# This is a bit hacky and may not work in all bazel situations, but works for now
if [[ $$SHARED_DIR == "external" ]]; then
SHARED_DIR=$$(echo $${SHARED_PATHS[0]} | cut -d/ -f-3)
fi
EXAMPLE=%s
read -ra EXAMPLE_PATHS <<< "$(locations %s_files)"
EXAMPLE_DIR=$$(echo $${EXAMPLE_PATHS[0]} | cut -d/ -f1)
# This is a bit hacky and may not work in all bazel situations, but works for now
if [[ $$EXAMPLE_DIR == "external" ]]; then
EXAMPLE_DIR=$$(echo $$EXAMPLE_PATHS | cut -d/ -f-3)
fi
TARGET_DIR=$$(dirname $$EXAMPLE_DIR)
tar chf $@ -C $$TARGET_DIR --exclude="$$(basename "$@")" .
""" % (shared, name, name),
tools = [
common_fun,
shared,
"%s_files" % name,
],
)
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/**/*"],
exclude = [
"**/*~",
"**/.*",
"**/#*",
".*/**/*",
],
),
)
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))
sh_binary(
name = "verify_examples",
srcs = [":verify_examples.sh"],
args = RESULT_FILES,
data = RESULTS,
)