1717import static com .google .common .truth .Truth .assertThat ;
1818import static com .google .devtools .build .lib .actions .util .ActionsTestUtil .getFirstArtifactEndingWith ;
1919import static com .google .devtools .build .lib .actions .util .ActionsTestUtil .prettyArtifactNames ;
20+ import static com .google .devtools .build .lib .skyframe .BzlLoadValue .keyForBuiltins ;
2021
2122import com .google .common .collect .ImmutableList ;
2223import com .google .common .collect .Iterables ;
@@ -50,7 +51,8 @@ public class CcProtoLibraryTest extends BuildViewTestCase {
5051
5152 private final StarlarkAspectClass starlarkCcProtoAspect =
5253 new StarlarkAspectClass (
53- Label .parseCanonicalUnchecked ("@_builtins//:common/cc/cc_proto_library.bzl" ),
54+ keyForBuiltins (
55+ Label .parseCanonicalUnchecked ("@_builtins//:common/cc/cc_proto_library.bzl" )),
5456 "cc_proto_aspect" );
5557
5658 @ Before
@@ -61,7 +63,7 @@ public void setUp() throws Exception {
6163 "toolchain_type(name = 'toolchain_type', visibility = ['//visibility:public'])" );
6264 scratch .file ("protobuf/WORKSPACE" );
6365 scratch .overwriteFile (
64- "protobuf /BUILD" ,
66+ "protobuf_workspace /BUILD" ,
6567 TestConstants .LOAD_PROTO_LANG_TOOLCHAIN ,
6668 TestConstants .LOAD_PROTO_LIBRARY ,
6769 "package(default_visibility=['//visibility:public'])" ,
@@ -75,19 +77,22 @@ public void setUp() throws Exception {
7577 " command_line = '--cpp_out=$(OUT)'," ,
7678 " blacklisted_protos = [':any_proto']," ,
7779 " progress_message = 'Generating C++ proto_library %{label}'," ,
80+ " toolchain_type = '@rules_cc//cc/proto:toolchain_type'," ,
7881 ")" );
7982 scratch .appendFile (
8083 "WORKSPACE" ,
84+ "register_toolchains('@com_google_protobuf//:all')" ,
8185 "local_repository(" ,
8286 " name = 'com_google_protobuf'," ,
83- " path = 'protobuf '," ,
87+ " path = 'protobuf_workspace '," ,
8488 ")" );
8589 invalidatePackages (); // A dash of magic to re-evaluate the WORKSPACE file.
8690 }
8791
8892 @ Test
8993 public void protoToolchainResolution_enabled () throws Exception {
90- setBuildLanguageOptions ("--incompatible_enable_proto_toolchain_resolution" );
94+ setBuildLanguageOptions (
95+ "--incompatible_enable_proto_toolchain_resolution" , "--enable_workspace" );
9196 getAnalysisMock ()
9297 .ccSupport ()
9398 .setupCcToolchainConfig (
@@ -247,7 +252,8 @@ public void outputDirectoryForProtoCompileAction() throws Exception {
247252
248253 @ Test
249254 public void outputDirectoryForProtoCompileAction_externalRepos () throws Exception {
250- setBuildLanguageOptions ("--experimental_builtins_injection_override=+cc_proto_library" );
255+ setBuildLanguageOptions (
256+ "--experimental_builtins_injection_override=+cc_proto_library" , "--enable_workspace" );
251257 scratch .file (
252258 "x/BUILD" , "cc_proto_library(name = 'foo_cc_proto', deps = ['@bla//foo:bar_proto'])" );
253259
@@ -333,6 +339,7 @@ public void generatedSourcesNotCoverageInstrumented() throws Exception {
333339
334340 @ Test
335341 public void importPrefixWorksWithRepositories () throws Exception {
342+ setBuildLanguageOptions ("--enable_workspace" );
336343 FileSystemUtils .appendIsoLatin1 (
337344 scratch .resolve ("WORKSPACE" ), "local_repository(name = 'yolo_repo', path = '/yolo_repo')" );
338345 invalidatePackages ();
@@ -358,6 +365,7 @@ public void importPrefixWorksWithRepositories() throws Exception {
358365
359366 @ Test
360367 public void stripImportPrefixWorksWithRepositories () throws Exception {
368+ setBuildLanguageOptions ("--enable_workspace" );
361369 FileSystemUtils .appendIsoLatin1 (
362370 scratch .resolve ("WORKSPACE" ), "local_repository(name = 'yolo_repo', path = '/yolo_repo')" );
363371 invalidatePackages ();
@@ -382,6 +390,7 @@ public void stripImportPrefixWorksWithRepositories() throws Exception {
382390
383391 @ Test
384392 public void importPrefixAndStripImportPrefixWorksWithRepositories () throws Exception {
393+ setBuildLanguageOptions ("--enable_workspace" );
385394 FileSystemUtils .appendIsoLatin1 (
386395 scratch .resolve ("WORKSPACE" ), "local_repository(name = 'yolo_repo', path = '/yolo_repo')" );
387396 invalidatePackages ();
@@ -413,7 +422,9 @@ private String getProtoHeaderExecPath() throws LabelSyntaxException {
413422 CcInfo ccInfo = configuredTarget .get (CcInfo .PROVIDER );
414423 ImmutableList <Artifact > headers =
415424 ccInfo .getCcCompilationContext ().getDeclaredIncludeSrcs ().toList ();
416- return Iterables .getOnlyElement (headers ).getExecPathString ();
425+ // TODO(b/364873432): cc_proto_library returns headers in both _virtual_includes and
426+ // _virtual_imports
427+ return Iterables .getFirst (headers , null ).getExecPathString ();
417428 }
418429
419430 @ Test
0 commit comments