Skip to content

Commit

Permalink
Align default output folder with Gradle best practices (#755)
Browse files Browse the repository at this point in the history
Use generated/sources/proto (plural) instead source.

Fixes #754
  • Loading branch information
holgerstolzenberg authored Nov 13, 2024
1 parent ecc9b97 commit 2810499
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ protobuf {

Generated files are under `task.outputBaseDir` with a subdirectory per
builtin and plugin. This produces a folder structure of
``$buildDir/generated/source/proto/$sourceSet/$builtinPluginName``.
``$buildDir/generated/sources/proto/$sourceSet/$builtinPluginName``.

The subdirectory name, which is by default ``$builtinPluginName``, can be
changed by setting the ``outputSubDir`` property in the ``builtins`` or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract class ProtobufExtension {
this.tasks = new GenerateProtoTaskCollection(project)
this.tools = new ToolsLocator(project)
this.taskConfigActions = []
this.defaultGeneratedFilesBaseDir = project.layout.buildDirectory.dir("generated/source/proto").map {
this.defaultGeneratedFilesBaseDir = project.layout.buildDirectory.dir("generated/sources/proto").map {
it.asFile.path
}
this.generatedFilesBaseDirProperty.convention(defaultGeneratedFilesBaseDir)
Expand Down Expand Up @@ -107,7 +107,7 @@ abstract class ProtobufExtension {

/**
* The base directory of generated files. The default is
* "${project.buildDir}/generated/source/proto".
* "${project.buildDir}/generated/sources/proto".
*/
@PackageScope
abstract Property<String> getGeneratedFilesBaseDirProperty()
Expand Down
26 changes: 13 additions & 13 deletions src/test/groovy/com/google/protobuf/gradle/IDESupportTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,28 @@ class IDESupportTest extends Specification {
'file://$MODULE_DIR$/build/extracted-protos/main',
'file://$MODULE_DIR$/build/extracted-include-protos/main',
'file://$MODULE_DIR$/build/extracted-protos/grpc',
'file://$MODULE_DIR$/build/generated/source/proto/grpc/java',
'file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output',
'file://$MODULE_DIR$/build/generated/source/proto/main/java',
'file://$MODULE_DIR$/build/generated/sources/proto/grpc/java',
'file://$MODULE_DIR$/build/generated/sources/proto/grpc/grpc_output',
'file://$MODULE_DIR$/build/generated/sources/proto/main/java',
]
Set<String> expectedTestSourceDir = [
'file://$MODULE_DIR$/src/test/java',
'file://$MODULE_DIR$/src/test/proto',
'file://$MODULE_DIR$/build/extracted-protos/test',
'file://$MODULE_DIR$/build/extracted-include-protos/test',
'file://$MODULE_DIR$/build/generated/source/proto/test/java',
'file://$MODULE_DIR$/build/generated/sources/proto/test/java',
]
Set<String> expectedGeneratedDirs = [
'file://$MODULE_DIR$/build/extracted-include-protos/grpc',
'file://$MODULE_DIR$/build/extracted-protos/main',
'file://$MODULE_DIR$/build/extracted-include-protos/main',
'file://$MODULE_DIR$/build/extracted-protos/grpc',
'file://$MODULE_DIR$/build/generated/source/proto/grpc/java',
'file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output',
'file://$MODULE_DIR$/build/generated/source/proto/main/java',
'file://$MODULE_DIR$/build/generated/sources/proto/grpc/java',
'file://$MODULE_DIR$/build/generated/sources/proto/grpc/grpc_output',
'file://$MODULE_DIR$/build/generated/sources/proto/main/java',
'file://$MODULE_DIR$/build/extracted-protos/test',
'file://$MODULE_DIR$/build/extracted-include-protos/test',
'file://$MODULE_DIR$/build/generated/source/proto/test/java',
'file://$MODULE_DIR$/build/generated/sources/proto/test/java',
]
assert Objects.equals(expectedSourceDir, sourceDir)
assert Objects.equals(expectedTestSourceDir, testSourceDir)
Expand Down Expand Up @@ -143,7 +143,7 @@ class IDESupportTest extends Specification {
srcEntries.each {
String path = it.@path
sourceDir.add(path)
if (path.startsWith("build/generated/source/proto")) {
if (path.startsWith("build/generated/sources/proto")) {
if (path.contains("test")) {
// test source path has one more attribute: ["test"="true"]
assert it.attributes.attribute.size() == 3
Expand All @@ -156,10 +156,10 @@ class IDESupportTest extends Specification {
Set<String> expectedSourceDir = [
'src/main/java',
'src/test/java',
'build/generated/source/proto/grpc/java',
'build/generated/source/proto/grpc/grpc_output',
'build/generated/source/proto/main/java',
'build/generated/source/proto/test/java',
'build/generated/sources/proto/grpc/java',
'build/generated/sources/proto/grpc/grpc_output',
'build/generated/sources/proto/main/java',
'build/generated/sources/proto/test/java',
]
assert Objects.equals(expectedSourceDir, sourceDir)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ProtobufKotlinDslCopySpecTest extends Specification {
}

private static void verifyProjectDir(File projectDir) {
File generatedSrcDir = new File(projectDir.path, "build/generated/source/proto/main/java")
File generatedSrcDir = new File(projectDir.path, "build/generated/sources/proto/main/java")
List<File> fileList = []
generatedSrcDir.eachFileRecurse { file ->
if (file.path.endsWith('.java')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ProtobufPluginTestHelper {

static void verifyProjectDir(File projectDir) {
['grpc', 'main', 'test'].each {
File generatedSrcDir = new File(projectDir.path, "build/generated/source/proto/$it")
File generatedSrcDir = new File(projectDir.path, "build/generated/sources/proto/$it")
List<File> fileList = []
generatedSrcDir.eachFileRecurse { file ->
if (file.path.endsWith('.java')) {
Expand Down
4 changes: 2 additions & 2 deletions testProjectAndroidKotlinDsl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ fun assertJavaCompileHasProtoGeneratedDir(
compileJavaTask: JavaCompile,
codegenPlugins: Collection<String>
) {
val baseDir = File("${project.buildDir}/generated/source/proto/$variant")
val baseDir = File("${project.buildDir}/generated/sources/protos/$variant")
// The expected direct subdirectories under baseDir
val expectedDirs = codegenPlugins.map { codegenPlugin ->
File("${project.buildDir}/generated/source/proto/$variant/$codegenPlugin")
File("${project.buildDir}/generated/sources/proto/$variant/$codegenPlugin")
}.toSet()

val actualDirs = mutableSetOf<File>()
Expand Down
8 changes: 4 additions & 4 deletions testProjectBase/build_base.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ test.doLast {

// Check generateDescriptorSet option has been honored
['main', 'test'].each { sourceSet ->
assertFileExists(false, "$buildDir/generated/source/proto/$sourceSet/descriptor_set.desc")
assertFileExists(false, "$buildDir/generated/sources/proto/$sourceSet/descriptor_set.desc")
}
assertFileExists(true, "$buildDir/generated/source/proto/grpc/descriptor_set.desc")
assertFileExists(true, "$buildDir/generated/sources/proto/grpc/descriptor_set.desc")
}

rootProject.ext {
Expand All @@ -108,10 +108,10 @@ rootProject.ext {
// not include any other dirs under the generated code base dir.
assertJavaCompileHasProtoGeneratedDir = {
Project project, String sourceSet, JavaCompile compileJavaTask, Collection<String> codegenPlugins ->
def baseDir = "${project.buildDir}/generated/source/proto/$sourceSet" as File
def baseDir = "${project.buildDir}/generated/sources/proto/$sourceSet" as File
// The expected direct subdirectories under baseDir
def expectedDirs = codegenPlugins.collect { codegenPlugin ->
"${project.buildDir}/generated/source/proto/$sourceSet/$codegenPlugin" as File
"${project.buildDir}/generated/sources/proto/$sourceSet/$codegenPlugin" as File
} as Set

def actualDirs = new HashSet()
Expand Down
8 changes: 4 additions & 4 deletions testProjectKotlinDslBase/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ tasks {
assertJavaCompileHasProtoGeneratedDir("grpc", listOf("java", "grpc_output"))

listOf("main", "test").forEach { sourceSet ->
assertFileExists(false, "$buildDir/generated/source/proto/$sourceSet/descriptor_set.desc")
assertFileExists(false, "$buildDir/generated/sources/proto/$sourceSet/descriptor_set.desc")
}
assertFileExists(true, "$buildDir/generated/source/proto/grpc/descriptor_set.desc")
assertFileExists(true, "$buildDir/generated/sources/proto/grpc/descriptor_set.desc")
}
}
}
Expand All @@ -123,10 +123,10 @@ fun assertJavaCompileHasProtoGeneratedDir(
compileJavaTask: JavaCompile,
codegenPlugins: Collection<String>
) {
val baseDir = File("${project.buildDir}/generated/source/proto/$sourceSet")
val baseDir = File("${project.buildDir}/generated/sources/proto/$sourceSet")
// The expected direct subdirectories under baseDir
val expectedDirs = codegenPlugins.map { codegenPlugin ->
File("${project.buildDir}/generated/source/proto/$sourceSet/$codegenPlugin")
File("${project.buildDir}/generated/sources/proto/$sourceSet/$codegenPlugin")
}.toSet()

val actualDirs = mutableSetOf<File>()
Expand Down

0 comments on commit 2810499

Please sign in to comment.