Repository: pantsbuild/pants

Issue:
`protobuf_sources` interacts badly with multiple Python resolves
**Describe the bug**

I found two issues while trying to get a few protobuf sources to be part of multiple resolves. I'm not sure if it's a setup-specific thing, haven't set up a full repro yet.

The base setup is the following: We have a set of resolves that apply to the exact same set of code. To solve this we have the following snippet in the root:
```python
__defaults__(
    {
        python_source: dict(resolve=parametrize("cpu", "gpu", "reqs")),
        python_sources: dict(resolve=parametrize("cpu", "gpu", "reqs")),
        pex_binary: dict(resolve=parametrize("cpu", "gpu", "reqs")),
    }
)
```
However; parametrizing `protobuf_sources.python_resolve`  here fails with the following error:

https://github.com/pantsbuild/pants/blob/a34feabef5400eb52472c34900ed39438dfa1d55/src/python/pants/engine/internals/graph.py#L437-L441

Then; I tried to simply generate all the variants in a loop:
```python3
for resolve in ['reqs', 'cpu', 'gpu']:
    protobuf_sources(
        name=f'proto_{resolve}',
        python_resolve=resolve,
        ...,
    )
```
However; we have two files in our set: `foo_v2`, which imports `foo_v1`. Thus, this approach to ambiguity of *which* `foo_v1.proto` it would be importing.

Thus, I had to expand to two `protobuf_source` statements with explicit dependencies:
```python3
for resolve in ['reqs', 'cpu', 'gpu']:
    protobuf_source(
        name=f"foo_v1_{resolve}",
        source="foo_v1.proto",
        grpc=True,
        python_resolve=resolve,
    )

    protobuf_source(
        name=f"foo_v2_{resolve}",
        source="foo_v2.proto",
        grpc=True,
        python_resolve=resolve,
        dependencies=[f":foo_v1_{resolve}"],
    )
```

**Pants version**
Stable, 2.15.0

**OS**
Linux

**Additional info**
Will try to isolate a repro soon!


Discussion:
@tgolsson thank you for opening this issue. It affects me as well and would be great to solve.

Resolving patch:
diff --git a/src/python/pants/backend/codegen/protobuf/python/additional_fields.py b/src/python/pants/backend/codegen/protobuf/python/additional_fields.py
--- a/src/python/pants/backend/codegen/protobuf/python/additional_fields.py
+++ b/src/python/pants/backend/codegen/protobuf/python/additional_fields.py
@@ -33,10 +33,15 @@ def rules():
     return [
         ProtobufSourceTarget.register_plugin_field(ProtobufPythonInterpreterConstraintsField),
         ProtobufSourcesGeneratorTarget.register_plugin_field(
-            ProtobufPythonInterpreterConstraintsField
+            ProtobufPythonInterpreterConstraintsField,
+            as_moved_field=True,
         ),
         ProtobufSourceTarget.register_plugin_field(ProtobufPythonResolveField),
-        ProtobufSourcesGeneratorTarget.register_plugin_field(ProtobufPythonResolveField),
+        ProtobufSourcesGeneratorTarget.register_plugin_field(
+            ProtobufPythonResolveField, as_moved_field=True
+        ),
         ProtobufSourceTarget.register_plugin_field(PythonSourceRootField),
-        ProtobufSourcesGeneratorTarget.register_plugin_field(PythonSourceRootField),
+        ProtobufSourcesGeneratorTarget.register_plugin_field(
+            PythonSourceRootField, as_moved_field=True
+        ),
     ]


Test patch: