Repository: pantsbuild/pants

Issue:
python-binary-create task maps all product directories to the same target
An example, from my project, wherein two targets, `docker/monitoring_sidecar:monitoring_sidecar` and `tools/templating:configure` are supposed to produce two pex files, `monitoring_sidecar.pex` and `configure.pex` (accordingly). Instead, the product mapping has both of them mapped to the first target, instead of each mapped to its own target.

```
ProductMapping(pex_archives) {
  PythonBinary(BuildFileAddress(BuildFile(docker/monitoring_sidecar/BUILD, FileSystemProjectTree(/Users/kyle.derr/Repositories/allclearid/odin/mono)), monitoring_sidecar)) => /Users/kyle.derr/Repositories/allclearid/odin/mono/.pants.d/binary/python-binary-create/0550b754d96b/docker.monitoring_sidecar.monitoring_sidecar/current
    [u'monitoring_sidecar.pex']
  PythonBinary(BuildFileAddress(BuildFile(docker/monitoring_sidecar/BUILD, FileSystemProjectTree(/Users/kyle.derr/Repositories/allclearid/odin/mono)), monitoring_sidecar)) => /Users/kyle.derr/Repositories/allclearid/odin/mono/.pants.d/binary/python-binary-create/0550b754d96b/tools.templating.configure/current
    [u'configure.pex']
}
```

This breaks a pants plugin I've written that assembles docker images by depending on python_binary and jvm_binary targets. It creates docker's workspace dynamically based on its dependencies' product mappings.


Discussion:

Resolving patch:
diff --git a/src/python/pants/backend/python/tasks/python_binary_create.py b/src/python/pants/backend/python/tasks/python_binary_create.py
--- a/src/python/pants/backend/python/tasks/python_binary_create.py
+++ b/src/python/pants/backend/python/tasks/python_binary_create.py
@@ -61,8 +61,8 @@ def execute(self):
         else:
           self.context.log.debug('using cache for {}'.format(vt.target))
 
-        python_pex_product.add(binary, os.path.dirname(pex_path)).append(os.path.basename(pex_path))
-        python_deployable_archive.add(binary, os.path.dirname(pex_path)).append(os.path.basename(pex_path))
+        python_pex_product.add(vt.target, os.path.dirname(pex_path)).append(os.path.basename(pex_path))
+        python_deployable_archive.add(vt.target, os.path.dirname(pex_path)).append(os.path.basename(pex_path))
         self.context.log.debug('created {}'.format(os.path.relpath(pex_path, get_buildroot())))
 
         # Create a copy for pex.
diff --git a/src/python/pants/backend/python/tasks2/python_binary_create.py b/src/python/pants/backend/python/tasks2/python_binary_create.py
--- a/src/python/pants/backend/python/tasks2/python_binary_create.py
+++ b/src/python/pants/backend/python/tasks2/python_binary_create.py
@@ -76,8 +76,8 @@ def execute(self):
           self.context.log.debug('using cache for {}'.format(vt.target))
 
         basename = os.path.basename(pex_path)
-        python_pex_product.add(binary, os.path.dirname(pex_path)).append(basename)
-        python_deployable_archive.add(binary, os.path.dirname(pex_path)).append(basename)
+        python_pex_product.add(vt.target, os.path.dirname(pex_path)).append(basename)
+        python_deployable_archive.add(vt.target, os.path.dirname(pex_path)).append(basename)
         self.context.log.debug('created {}'.format(os.path.relpath(pex_path, get_buildroot())))
 
         # Create a copy for pex.


Test patch: