forked from googleapis/gapic-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILD.bazel
169 lines (154 loc) · 5.42 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
167
168
169
load(
"//:gapic_generator.bzl",
"gapic_generator_tests",
"google_java_format",
"google_java_format_verification",
)
_COMPILE_DEPS = [
"@cglib_cglib//jar",
"@com_atlassian_commonmark_commonmark//jar",
"@com_fasterxml_jackson_core_jackson_annotations//jar",
"@com_fasterxml_jackson_core_jackson_core//jar",
"@com_fasterxml_jackson_core_jackson_databind//jar",
"@com_google_api_api_common//jar",
"@com_google_api_api_compiler//jar",
"@com_google_api_api_compiler_testing//jar",
"@com_google_api_grpc_proto_google_common_protos__com_google_api_codegen//jar",
"@com_google_auto_value_auto_value//jar",
"@com_google_auto_value_auto_value_annotations//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_code_gson_gson//jar",
"@com_google_guava_guava__com_google_api_codegen//jar",
"@com_google_inject_guice//jar",
"@com_google_protobuf//:protobuf_java",
"@commons_cli_commons_cli//jar",
"@io_grpc_grpc_core//jar",
"@javax_inject_javax_inject//jar",
"@org_apache_commons_commons_lang3//jar",
"@org_ow2_asm_asm//jar",
"@org_threeten_threetenbp//jar",
"@org_yaml_snakeyaml//jar",
]
_TEST_COMPILE_DEPS = [
"@com_google_truth_truth//jar",
"@junit_junit//jar",
"@pl_pragmatists_JUnitParams//jar",
"@org_mockito_mockito_core//jar",
"@org_hamcrest_hamcrest_core//jar",
"@net_bytebuddy_byte_buddy//jar",
"@org_objenesis_objenesis//jar",
]
_JAVA_COPTS = [
"-source",
"1.8",
"-target",
"1.8",
]
java_plugin(
name = "auto_value_plugin",
processor_class = "com.google.auto.value.processor.AutoValueProcessor",
deps = ["@com_google_auto_value_auto_value//jar"],
)
proto_library(
name = "config_proto",
srcs = ["src/main/proto/com/google/api/codegen/config.proto"],
deps = ["@com_google_protobuf//:wrappers_proto"],
)
proto_library(
name = "config_v2_proto",
srcs = ["src/main/proto/com/google/api/codegen/v2/config_v2.proto"],
deps = ["@com_google_protobuf//:wrappers_proto"],
)
proto_library(
name = "sample_config_proto",
srcs = ["src/main/proto/com/google/api/codegen/samplegen/v1p2/sample_config_v1p2.proto"],
deps = ["@com_google_protobuf//:wrappers_proto"],
)
java_proto_library(
name = "config_java_proto",
deps = [":config_proto",
":config_v2_proto",
":sample_config_proto"],
)
java_binary(
name = "gapic_generator",
srcs = glob(["src/main/java/**/*.java"]),
create_executable = True,
javacopts = _JAVA_COPTS,
jvm_flags = ["-Xmx512m"],
main_class = "com.google.api.codegen.GeneratorMain",
resources = glob(["src/main/resources/**/*"]),
visibility = ["//visibility:public"],
plugins = [":auto_value_plugin"],
deps = [
":config_java_proto",
] + _COMPILE_DEPS,
)
# This is probably not the right way of doing it, but good enough for now.
# api-compiler module expects "protoc" binary to be accessible during tests execution, this genrule
# "puts" the "binary" in a proper location (the tests are still hermetic, even with this hack).
genrule(
name = "protoc_binary_hack_for_test",
outs = ["protoc"],
cmd = "echo 'external/com_google_protobuf/protoc \"$$@\"' > $@",
executable = True,
tools = ["@com_google_protobuf//:protoc"],
)
java_library(
name = "gapic_generator_testlib",
srcs = glob(["src/test/java/**/*.java"]),
data = glob([
"src/**/testdata/**/*",
"src/**/testsrc/**/*",
"src/main/resources/**/*",
]) + [":protoc_binary_hack_for_test"],
javacopts = _JAVA_COPTS,
resources = glob([
"src/**/testdata/**/*",
"src/**/testsrc/**/*",
"src/**/discoverytestdata/**/*",
"src/test/java/**/*.proto",
]) + ["@com_google_protobuf//:well_known_protos"],
visibility = ["//visibility:public"],
runtime_deps = ["@com_google_protobuf//:protoc"],
plugins = [":auto_value_plugin"],
deps = [
":config_java_proto",
":gapic_generator",
] + _COMPILE_DEPS + _TEST_COMPILE_DEPS,
)
# This will generate test targets, one for each test and put them in one big test_suite
# (with same name as this macros). The targets will be accessible by the corresponding tagets in the
# format `//:<fully.qualified.test.class.name>`.
# For example try running `bazel test //:com.google.api.codegen.config.ConfigGenerationTest`.
# To run all tests and see error details (if any) try:
# `bazel test //:all --test_output=errors`
# or
# `bazel test //:gapic_generator_tests --test_output=errors`
gapic_generator_tests(
name = "gapic_generator_tests",
size = "small",
srcs = glob(["src/test/java/**/*Test.java"]),
runtime_deps = [":gapic_generator_testlib"],
)
# google-java-format
java_binary(
name = "google_java_format_binary",
jvm_flags = ["-Xmx512m"],
main_class = "com.google.googlejavaformat.java.Main",
visibility = ["//visibility:public"],
runtime_deps = ["@google_java_format_all_deps//jar"],
)
# Run `bazel build //:google_java_format_verification` to verify that gapic-generator java sources
# are formatted correctly
google_java_format_verification(
name = "google_java_format_verification",
srcs = glob(["src/**/*.java"]),
formatter = "//:google_java_format_binary",
)
# Run `bazel run //:google_java_format` to format gapic-generator sources
google_java_format(
name = "google_java_format",
srcs = glob(["src/**/*.java"]),
formatter = "//:google_java_format_binary",
)