-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathgen_sample_targets.bzl
50 lines (42 loc) · 1.9 KB
/
gen_sample_targets.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
"""Build extensions to simplify generating sample build/test targets."""
load("//third_party/bazel_rules/rules_java/java:java_library.bzl", "java_library")
load("//tools/build_defs/build_test:build_test.bzl", "build_test")
COMMON_JAVA_SAMPLE_DEPS = [
"//java/com/google/api/client/auth/oauth2",
"//java/com/google/api/client/extensions/java6/auth/oauth2",
"//java/com/google/api/client/extensions/jetty/auth/oauth2",
"//java/com/google/api/client/googleapis/auth/oauth2",
"//java/com/google/api/client/googleapis/util",
"//java/com/google/api/client/http",
"//java/com/google/api/client/json",
"//java/com/google/api/client/util",
"//java/com/google/api/client/util/store",
"//java/com/google/common/base",
"//java/com/google/common/collect",
"//java/com/google/common/io",
]
def gen_java_targets(name):
"""Macro that defines build and test rules for all Java sample projects.
Generates <name>-<version>-build and <name>-<version>-build-test targets.
Ex: foo-v2.5-build, foo-v2.5-build-test
Args:
name: The prefix for all generated rules.
"""
for pom_file in native.glob(["**/pom.xml"]):
# Parse API version from the pom file path (ex: .../v2.5/pom.xml)
version = pom_file.rsplit("/", 2)[0]
# Generate internal Java client version (ex: v3p5)
java_client_version = version.replace(".", "p")
versioned_rule_name = "%s-%s-build" % (name, version)
library_args = {
"name": versioned_rule_name,
"srcs": native.glob(["%s/**/*.java" % version]),
"deps": COMMON_JAVA_SAMPLE_DEPS + [
"//google/ads/xfa/dfareporting/op:dfareporting-java-client-%s" % java_client_version,
],
}
java_library(**library_args)
build_test(
name = "%s-test" % versioned_rule_name,
targets = [":%s" % versioned_rule_name],
)