-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILD.bazel
166 lines (146 loc) · 4.08 KB
/
BUILD.bazel
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load(
"//flag:defs.bzl",
"edition_binary",
"edition_files",
"editions_files",
"editions_test_suite",
)
# ----------------------------------------------------------
# Example of edition specific libraries.
#
# We define dedicated targets for each library and define an alias to switch
# between the two depending on the configured edition.
cc_library(
name = "community_lib",
srcs = ["community_lib.cc"],
)
cc_library(
name = "enterprise_lib",
srcs = ["enterprise_lib.cc"],
)
alias(
name = "lib",
actual = select({
"//config:community_edition": "community_lib",
"//config:enterprise_edition": "enterprise_lib",
}),
)
# ----------------------------------------------------------
# Example of edition specific data files.
#
# We include both edition's raw source files and copy the appropriate file to
# the expected name.
copy_file(
name = "data",
src = select({
"//config:community_edition": "community_data.txt",
"//config:enterprise_edition": "enterprise_data.txt",
}),
out = "data.txt",
)
# ----------------------------------------------------------
# Example of a binary depending on edition specific targets.
#
# The target itself does not explicitly depend on the edition.
cc_binary(
name = "bin",
srcs = ["main.cc"],
data = ["data"],
deps = [
":lib",
"@bazel_tools//tools/cpp/runfiles",
],
)
# ----------------------------------------------------------
# Example of a test depending on edition specific sources.
#
# The test executes the binary above that has edition specific dependencies.
#
# Uses editions_test_suite to generate a test suite covering all editions.
sh_test(
name = "test",
srcs = select({
"//config:community_edition": ["test_community.sh"],
"//config:enterprise_edition": ["test_enterprise.sh"],
}),
args = ["$(rootpath :bin)"],
data = ["bin"],
)
editions_test_suite(
name = "test-all",
tests = ["test"],
)
# ----------------------------------------------------------
# Explicitly configured edition binaries.
edition_binary(
name = "bin-ce",
edition = "community",
executable = "bin",
)
edition_binary(
name = "bin-ee",
edition = "enterprise",
executable = "bin",
)
# ----------------------------------------------------------
# Example of a gotcha.
#
# This will see the different editions as duplicates. It warns
#
# > Duplicate file in archive: ./bin, picking first occurrence
# > Duplicate file in archive: ./data.txt, picking first occurrence
#
# and produces the following archive.
#
# > ./bin
# > ./bin-ce
# > ./bin-ee
# > ./data.txt
#
# I.e. data.txt and bin will correspond to one of the editions and the other
# will be missing. Note that the `edition_binary` symlinks are converted to
# copies.
pkg_tar(
name = "gotcha",
srcs = [
"bin-ce",
"bin-ee",
],
include_runfiles = True,
)
# ----------------------------------------------------------
# Example bundling both editions into one artifact.
#
# First, create a pkg_tar for each edition based on the configuration.
# Then multiplex it into multiple files using the editions_files rule.
# Finally, bundle the multiplexed version into a combined pkg_tar.
pkg_tar(
name = "bundle-config",
srcs = [
"bin",
],
include_runfiles = True,
package_dir = select({
"//config:community_edition": "community",
"//config:enterprise_edition": "enterprise",
}),
# pkg_tar doesn't reconstruct runfiles trees, so we do it manually.
symlinks = select({
"//config:community_edition": {"community/bin.runfiles/transitions-demo/app/data.txt": "../../../data.txt"},
"//config:enterprise_edition": {"enterprise/bin.runfiles/transitions-demo/app/data.txt": "../../../data.txt"},
}),
)
editions_files(
name = "bundle-each",
srcs = ["bundle-config"],
editions = [
"community",
"enterprise",
],
)
pkg_tar(
name = "bundle-all",
deps = ["bundle-each"],
)