|
15 | 15 | package com.google.devtools.build.lib.rules.proto;
|
16 | 16 |
|
17 | 17 | import static com.google.common.truth.Truth.assertThat;
|
18 |
| -import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.prettyArtifactNames; |
19 | 18 |
|
20 | 19 | import com.google.common.truth.Correspondence;
|
21 | 20 | import com.google.devtools.build.lib.actions.ResourceSet;
|
22 | 21 | import com.google.devtools.build.lib.analysis.ConfiguredTarget;
|
23 |
| -import com.google.devtools.build.lib.analysis.FileProvider; |
24 | 22 | import com.google.devtools.build.lib.analysis.actions.SpawnAction;
|
25 | 23 | import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
|
26 | 24 | import com.google.devtools.build.lib.packages.util.MockProtoSupport;
|
@@ -93,7 +91,7 @@ public final void setup() throws Exception {
|
93 | 91 |
|
94 | 92 | scratch.file(
|
95 | 93 | "foo/generate.bzl",
|
96 |
| - """ |
| 94 | +""" |
97 | 95 | load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo")
|
98 | 96 | load("@com_google_protobuf//bazel/common:proto_common.bzl", "proto_common")
|
99 | 97 | load("@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
|
@@ -140,52 +138,9 @@ def _impl(ctx):
|
140 | 138 | })
|
141 | 139 | """);
|
142 | 140 |
|
143 |
| - scratch.file( |
144 |
| - "foo/should_generate.bzl", |
145 |
| - """ |
146 |
| -load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") |
147 |
| -load("@com_google_protobuf//bazel/common:proto_common.bzl", "proto_common") |
148 |
| -load("@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo") |
149 |
| -BoolProvider = provider() |
150 |
| -def _impl(ctx): |
151 |
| - result = proto_common.experimental_should_generate_code( |
152 |
| - ctx.attr.proto_dep[ProtoInfo], |
153 |
| - ctx.attr.toolchain[ProtoLangToolchainInfo], |
154 |
| - 'MyRule', |
155 |
| - ctx.attr.proto_dep.label) |
156 |
| - return [BoolProvider(value = result)] |
157 |
| -should_compile_rule = rule(_impl, |
158 |
| - attrs = { |
159 |
| - 'proto_dep': attr.label(), |
160 |
| - 'toolchain': attr.label(default = '//foo:toolchain'), |
161 |
| - }) |
162 |
| -"""); |
163 |
| - |
164 |
| - scratch.file( |
165 |
| - "foo/declare_generated_files.bzl", |
166 |
| - """ |
167 |
| - load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") |
168 |
| - load("@com_google_protobuf//bazel/common:proto_common.bzl", "proto_common") |
169 |
| - def _impl(ctx): |
170 |
| - files = proto_common.declare_generated_files( |
171 |
| - ctx.actions, |
172 |
| - ctx.attr.proto_dep[ProtoInfo], |
173 |
| - ctx.attr.extension, |
174 |
| - (lambda s: s.replace('-','_').replace('.','/')) if ctx.attr.python_names else None) |
175 |
| - for f in files: |
176 |
| - ctx.actions.write(f, '') |
177 |
| - return [DefaultInfo(files = depset(files))] |
178 |
| - declare_generated_files = rule(_impl, |
179 |
| - attrs = { |
180 |
| - 'proto_dep': attr.label(), |
181 |
| - 'extension': attr.string(), |
182 |
| - 'python_names': attr.bool(default = False), |
183 |
| - }) |
184 |
| - """); |
185 |
| - |
186 | 141 | scratch.file(
|
187 | 142 | "foo/check_collocated.bzl",
|
188 |
| - """ |
| 143 | +""" |
189 | 144 | load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo")
|
190 | 145 | load("@com_google_protobuf//bazel/common:proto_common.bzl", "proto_common")
|
191 | 146 | load("@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
|
@@ -308,38 +263,6 @@ public void protoCommonCompile_overrideProgressMessage() throws Exception {
|
308 | 263 | assertThat(spawnAction.getProgressMessage()).isEqualTo("My //bar:simple");
|
309 | 264 | }
|
310 | 265 |
|
311 |
| - /** Verifies <code>proto_common.declare_generated_files</code> call. */ |
312 |
| - @Test |
313 |
| - public void declareGenerateFiles_basic() throws Exception { |
314 |
| - scratch.file( |
315 |
| - "bar/BUILD", |
316 |
| - "load('@com_google_protobuf//bazel:proto_library.bzl', 'proto_library')", |
317 |
| - "load('//foo:declare_generated_files.bzl', 'declare_generated_files')", |
318 |
| - "proto_library(name = 'proto', srcs = ['A.proto', 'b/B.proto'])", |
319 |
| - "declare_generated_files(name = 'simple', proto_dep = ':proto', extension = '.cc')"); |
320 |
| - |
321 |
| - ConfiguredTarget target = getConfiguredTarget("//bar:simple"); |
322 |
| - |
323 |
| - assertThat(prettyArtifactNames(target.getProvider(FileProvider.class).getFilesToBuild())) |
324 |
| - .containsExactly("bar/A.cc", "bar/b/B.cc"); |
325 |
| - } |
326 |
| - |
327 |
| - /** Verifies <code>proto_common.declare_generated_files</code> call for Python. */ |
328 |
| - @Test |
329 |
| - public void declareGenerateFiles_pythonc() throws Exception { |
330 |
| - scratch.file( |
331 |
| - "bar/BUILD", |
332 |
| - "load('@com_google_protobuf//bazel:proto_library.bzl', 'proto_library')", |
333 |
| - "load('//foo:declare_generated_files.bzl', 'declare_generated_files')", |
334 |
| - "proto_library(name = 'proto', srcs = ['my-proto.gen.proto'])", |
335 |
| - "declare_generated_files(name = 'simple', proto_dep = ':proto', extension = '_pb2.py',", |
336 |
| - " python_names = True)"); |
337 |
| - |
338 |
| - ConfiguredTarget target = getConfiguredTarget("//bar:simple"); |
339 |
| - |
340 |
| - assertThat(prettyArtifactNames(target.getProvider(FileProvider.class).getFilesToBuild())) |
341 |
| - .containsExactly("bar/my_proto/gen_pb2.py"); |
342 |
| - } |
343 | 266 |
|
344 | 267 | @Test
|
345 | 268 | public void langProtoLibrary_inDifferentPackage_allowed() throws Exception {
|
|
0 commit comments