Repository: pantsbuild/pants

Issue:
codegen: JVM targets and protobuf_sources target not working
Having a `scala_sources` target depend on a `protobuf_sources` target does not appear to work. I used example-codegen with https://github.com/pantsbuild/example-codegen/pull/10 to test compilation of Scala Protobuf code. 

Running `./pants_from_sources check src/jvm/org/pantsbuild/example/codegen/scala::` results in: 

```
  ClasspathSourceMissing: No JVM classpath providers (from: CompileJavaSourceRequest, CompileScalaSourceRequest, CoursierFetchRequest, DeployJarClasspathEntryRequest, JvmResourcesRequest) were compatible with the combination of inputs:
  * src/protobuf/simple_example:simple_example	(protobuf_sources)
```


Discussion:

Resolving patch:
diff --git a/src/python/pants/jvm/compile.py b/src/python/pants/jvm/compile.py
--- a/src/python/pants/jvm/compile.py
+++ b/src/python/pants/jvm/compile.py
@@ -23,6 +23,7 @@
     FieldSet,
     GenerateSourcesRequest,
     SourcesField,
+    TargetFilesGenerator,
 )
 from pants.engine.unions import UnionMembership, union
 from pants.jvm.resolve.key import CoursierResolveKey
@@ -153,9 +154,15 @@ def classify_impl(
         generator_sources = self.generator_sources.get(impl) or frozenset()
 
         compatible_direct = sum(1 for t in targets for fs in impl.field_sets if fs.is_applicable(t))
-        compatible_generated = sum(1 for t in targets for g in generator_sources if t.has_field(g))
+        compatible_codegen = sum(1 for t in targets for g in generator_sources if t.has_field(g))
+        compatible_codegen_target_generator = sum(
+            1
+            for t in targets
+            if isinstance(t, TargetFilesGenerator)
+            and any(field in t.generated_target_cls.core_fields for field in generator_sources)
+        )
 
-        compatible = compatible_direct + compatible_generated
+        compatible = compatible_direct + compatible_codegen + compatible_codegen_target_generator
         if compatible == 0:
             return _ClasspathEntryRequestClassification.INCOMPATIBLE
         if compatible == len(targets):


Test patch:
diff --git a/src/python/pants/jvm/compile_test.py b/src/python/pants/jvm/compile_test.py
--- a/src/python/pants/jvm/compile_test.py
+++ b/src/python/pants/jvm/compile_test.py
@@ -20,7 +20,11 @@
 
 from pants.backend.codegen.protobuf.java.rules import GenerateJavaFromProtobufRequest
 from pants.backend.codegen.protobuf.java.rules import rules as protobuf_rules
-from pants.backend.codegen.protobuf.target_types import ProtobufSourceField, ProtobufSourceTarget
+from pants.backend.codegen.protobuf.target_types import (
+    ProtobufSourceField,
+    ProtobufSourcesGeneratorTarget,
+    ProtobufSourceTarget,
+)
 from pants.backend.codegen.protobuf.target_types import rules as protobuf_target_types_rules
 from pants.backend.java.compile.javac import CompileJavaSourceRequest
 from pants.backend.java.compile.javac import rules as javac_rules
@@ -151,6 +155,7 @@ def rule_runner() -> RuleRunner:
             JavaSourcesGeneratorTarget,
             JvmArtifactTarget,
             ProtobufSourceTarget,
+            ProtobufSourcesGeneratorTarget,
             ScalaSourcesGeneratorTarget,
         ],
     )
@@ -249,6 +254,7 @@ def classify(
                 java_sources(name='java')
                 jvm_artifact(name='jvm_artifact', group='ex', artifact='ex', version='0.0.0')
                 protobuf_source(name='proto', source="f.proto")
+                protobuf_sources(name='protos')
                 {DEFAULT_SCALA_LIBRARY_TARGET}
                 """
             ),
@@ -256,7 +262,7 @@ def classify(
             "3rdparty/jvm/default.lock": DEFAULT_LOCKFILE,
         }
     )
-    scala, java, jvm_artifact, proto = rule_runner.request(
+    scala, java, jvm_artifact, proto, protos = rule_runner.request(
         UnexpandedTargets,
         [
             Addresses(
@@ -265,6 +271,7 @@ def classify(
                     Address("", target_name="java"),
                     Address("", target_name="jvm_artifact"),
                     Address("", target_name="proto"),
+                    Address("", target_name="protos"),
                 ]
             )
         ],
@@ -282,6 +289,7 @@ def classify(
     assert (CompileScalaSourceRequest, None) == classify([scala], all_members, generators)
     assert (CoursierFetchRequest, None) == classify([jvm_artifact], all_members, generators)
     assert (CompileJavaSourceRequest, None) == classify([proto], all_members, generators)
+    assert (CompileJavaSourceRequest, None) == classify([protos], all_members, generators)
 
     # Partially compatible.
     assert (CompileJavaSourceRequest, CompileScalaSourceRequest) == classify(