Skip to content

Commit

Permalink
Do not resolve source prefixes before checking against java sources
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 577988802
  • Loading branch information
Googler authored and copybara-github committed Oct 30, 2023
1 parent 27bf3aa commit 8ee60ff
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ public ProjectProto.Project createProject(BuildGraphData graph) throws BuildExce
}
for (Path protoDirPath : rootToProtoSource.get(dir)) {
if (rootToPrefix.get(dir).keySet().stream()
.map(protoDirPath::resolve)
.noneMatch(protoDirPath::startsWith)) {
Path path = dir.resolve(protoDirPath);
// TODO(b/305743519): make java source properties like package prefix specific to java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,33 @@ public void testProtoSourceFolders_whenDirectoryIsExcluded_returnsEmpty() throws
ImmutableSet.of(Path.of("myproject/excluded/protos/excluded.proto")));
assertThat(additionalProtoSourceFolders).isEmpty();
}

@Test
public void testProtoSourceFolders_whenSubfolderOfJavaRoot_notCreated() throws Exception {

ImmutableMap<Path, String> sourcePackages =
ImmutableMap.of(
TestData.ROOT.resolve(
"nestedproto/java/com/testdata/nestedproto/NestedProtoConsumer.java"),
"com.testdata.nestedproto");

GraphToProjectConverter converter =
GraphToProjectConverters.builder()
.setPackageReader(sourcePackages::get)
.setProjectIncludes(ImmutableSet.of(TestData.ROOT.resolve("nestedproto")))
.setLanguageClasses(ImmutableSet.of(LanguageClass.JAVA))
.build();
BuildGraphData buildGraphData = BuildGraphs.forTestProject(TestData.NESTED_PROTO_QUERY);

ProjectProto.Project projectProto = converter.createProject(buildGraphData);
assertThat(projectProto.getModulesCount()).isEqualTo(1);
ProjectProto.Module workspaceModule = projectProto.getModules(0);

ProjectProto.ContentEntry contentEntry = workspaceModule.getContentEntries(0);
assertThat(contentEntry.getSourcesList())
.containsExactly(
ProjectProto.SourceFolder.newBuilder()
.setPath(TestData.ROOT.resolve("nestedproto/java").toString())
.build());
}
}
11 changes: 11 additions & 0 deletions querysync/javatests/com/google/idea/blaze/qsync/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ genquery(
],
)

genquery(
name = "nested_proto_query",
expression = "//querysync/javatests/com/google/idea/blaze/qsync/testdata/nestedproto:*",
opts = ["--output=streamed_proto"],
scope = scopeForJavaPackage("//querysync/javatests/com/google/idea/blaze/qsync/testdata/nestedproto:consumer") + [
"//querysync/javatests/com/google/idea/blaze/qsync/testdata/nestedproto:nested_proto",
"//querysync/javatests/com/google/idea/blaze/qsync/testdata/nestedproto:nested_java_proto_lite",
],
)

java_library(
name = "testdata",
srcs = ["TestData.java"],
Expand All @@ -173,6 +183,7 @@ java_library(
":java_library_proto_dep_query",
":java_library_transitive_dep_query",
":java_library_transitive_internal_dep_query",
":nested_proto_query",
":proto_only_query",
],
deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public enum TestData {
FILEGROUP_QUERY("filegroup"),
CC_LIBRARY_QUERY("cc"),
CC_MULTISRC_QUERY("cc_multisrc"),
PROTO_ONLY_QUERY("protoonly");
PROTO_ONLY_QUERY("protoonly"),
NESTED_PROTO_QUERY("nestedproto");

public final ImmutableList<Path> srcPaths;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
proto_library(
name = "nested_proto",
srcs = ["java/com/testdata/nestedproto/proto/nested.proto"],
)

java_lite_proto_library(
name = "nested_java_proto_lite",
deps = [":nested_proto"],
)

java_library(
name = "consumer",
srcs = ["java/com/testdata/nestedproto/NestedProtoConsumer.java"],
deps = [":nested_java_proto_lite"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.testdata.nestedproto;

import com.google.idea.blaze.qsync.testdata.nestedproto.proto.Nested.NestedProtoTest;

public class NestedProtoConsumer {
private NestedProtoConsumer() {}

public static String getMessage(NestedProtoTest testProto) {
return testProto.getMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package buildgraph;

option java_package = "com.google.idea.blaze.qsync.testdata.nestedproto.proto";

message NestedProtoTest {
optional string message = 1;
}

0 comments on commit 8ee60ff

Please sign in to comment.