google / protobuf-gradle-plugin

Protobuf Plugin for Gradle
Other
1.77k stars 273 forks source link

Wire proto sources/outputs/etc through ProtoSourceSet #637

Closed rougsig closed 2 years ago

rougsig commented 2 years ago

Background To compile proto sources or java/kotlin sources, we need to combine many different tasks together.

Java examples:

  1. generateProtos sources: from sourceSet + extractProtosTask includes: extractIncludeProtosTask

  2. generateTestProtos sources: from testSourceSet + extractTestProtosTask includes: from mainSourceSet + extractProtosTask + extractIncludeProtosTask + extractIncludeTestProtosTask

Android examples: android part is more complicated than java. Each android variant can contains more than one sourceSet. Let's name that sourceSet amount as c.

  1. generateProtos sources: from c * sourceSet + c * extractProtosTask includes: extractIncludeProtosTask

  2. generateTestProtos sources: from c * testSourceSet + c * extractTestProtosTask includes: from c * mainSourceSet + c * extractTestProtosTask + extractIncludeProtosTask + extractIncludeTestProtosTask

It's difficult to manipulate without any structure to mix them up.

Changes Added ProtoSourceSet structure. That structure contains all information about proto: sources, includes, outputs, tasks depends on, etc. We can easily mix source sets between. That case we need in test compilation (test sourceSet contains main sourceSet). All tasks that depend on ProtoSourceSet will inherit all dependent task declarations.

Test plan Green pipelines.

ejona86 commented 2 years ago

I don't understand https://github.com/google/protobuf-gradle-plugin/pull/637/commits/387c422a43ae2a0295ab69eaa78c74d6f015d676 . "KotlinCompile configuration block can be executed before generateTask lazy configuration" shouldn't matter at all, as generateTask lazy configuration doesn't change global state and it.outputSourceDirectories in output is run after configuration. Is this another problem caused by map {} ? Or maybe we don't fully understand what is wrong?