prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ResolveError: Directory '{mydir}' does not contain any BUILD files (when Dockerizing packages)
  **Describe the bug**
  
  Created a repo at https://github.com/sureshjoshi/pantsbuild-14031 to help illustrate this problem. 
  
  Essentially, I use custom output paths for my .pex files, and while testing out the `docker_image` target, I noticed some of my components fail with the error 
  
  > ResolveError: Directory 'backend' does not contain any BUILD files
  
  After a lot of debugging, I only ran into this problem when my output folders were common to multiple `pex_binary` targets. 
  
  For example, in the repo above, I have 3 identical projects (A, B, C) - where they only differ by the `pex_binary` `output_path` (and this location updated in the associated Dockerfile), and one of the projects refuses to compile.
  
  As per the README in the repo:
  
  ```bash
  # Should create a pex at dist/backend/projecta/projecta.pex
  # Docker image created successfully as projecta-container:latest
  ./pants package backend/projecta::
  
  # Should create a pex at dist/backend.projectc/projectc.pex
  # Docker image created successfully as projectc-container:latest
  ./pants package backend/projectc::
  ```
  
  ```bash
  # Should create a pex at dist/backend/projectb.pex
  ./pants package backend/projectb:projectb
  
  # FAILS: With ResolveError
  ./pants package backend/projectb:projectb-container 
  ```
  
  So, the difference above is that Project C uses no `output_path` and uses the dot-syntax for the dist folder. ProjectA places the pex file under a `backend/projecta` directory. The failing ProjectB places the pex file directly under `backend`.
  
  This isn't a big issue, and easily worked around, and I'm guessing it has to do with namespacing or module/package semantics, but it's just a weird problem that is difficult to debug based on the error message.
  
  **Pants version**
  
  - 2.8.0
  - 2.9.0rc1
  
  **OS**
  
  macOS 12.1
  Untested on Linux
  
  
  </issue>
  <code>
  [start of src/python/pants/backend/docker/util_rules/dependencies.py]
  1 # Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
  2 # Licensed under the Apache License, Version 2.0 (see LICENSE).
  3 
  4 from pants.backend.docker.subsystems.dockerfile_parser import DockerfileInfo, DockerfileInfoRequest
  5 from pants.backend.docker.target_types import DockerDependenciesField
  6 from pants.core.goals.package import PackageFieldSet
  7 from pants.engine.addresses import Addresses, UnparsedAddressInputs
  8 from pants.engine.rules import Get, collect_rules, rule
  9 from pants.engine.target import (
  10     FieldSetsPerTarget,
  11     FieldSetsPerTargetRequest,
  12     InjectDependenciesRequest,
  13     InjectedDependencies,
  14     Targets,
  15 )
  16 from pants.engine.unions import UnionRule
  17 
  18 
  19 class InjectDockerDependencies(InjectDependenciesRequest):
  20     inject_for = DockerDependenciesField
  21 
  22 
  23 @rule
  24 async def inject_docker_dependencies(request: InjectDockerDependencies) -> InjectedDependencies:
  25     """Inspects COPY instructions in the Dockerfile for references to known targets."""
  26     dockerfile_info = await Get(
  27         DockerfileInfo, DockerfileInfoRequest(request.dependencies_field.address)
  28     )
  29     targets = await Get(
  30         Targets,
  31         UnparsedAddressInputs(
  32             dockerfile_info.putative_target_addresses,
  33             owning_address=None,
  34         ),
  35     )
  36     package = await Get(FieldSetsPerTarget, FieldSetsPerTargetRequest(PackageFieldSet, targets))
  37     referenced_targets = (
  38         field_sets[0].address for field_sets in package.collection if len(field_sets) > 0
  39     )
  40     return InjectedDependencies(Addresses(referenced_targets))
  41 
  42 
  43 def rules():
  44     return [
  45         *collect_rules(),
  46         UnionRule(InjectDependenciesRequest, InjectDockerDependencies),
  47     ]
  48
  [end of src/python/pants/backend/docker/util_rules/dependencies.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/src/python/pants/backend/docker/util_rules/dependencies.py b/src/python/pants/backend/docker/util_rules/dependencies.py
  --- a/src/python/pants/backend/docker/util_rules/dependencies.py
  +++ b/src/python/pants/backend/docker/util_rules/dependencies.py
  @@ -3,6 +3,7 @@
   
   from pants.backend.docker.subsystems.dockerfile_parser import DockerfileInfo, DockerfileInfoRequest
   from pants.backend.docker.target_types import DockerDependenciesField
  +from pants.base.specs import AddressSpecs, MaybeEmptySiblingAddresses
   from pants.core.goals.package import PackageFieldSet
   from pants.engine.addresses import Addresses, UnparsedAddressInputs
   from pants.engine.rules import Get, collect_rules, rule
  @@ -22,17 +23,28 @@
   
   @rule
   async def inject_docker_dependencies(request: InjectDockerDependencies) -> InjectedDependencies:
  -    """Inspects COPY instructions in the Dockerfile for references to known targets."""
  +    """Inspects COPY instructions in the Dockerfile for references to known packagable targets."""
       dockerfile_info = await Get(
           DockerfileInfo, DockerfileInfoRequest(request.dependencies_field.address)
       )
  -    targets = await Get(
  -        Targets,
  +
  +    # Parse all putative target addresses.
  +    putative_addresses = await Get(
  +        Addresses,
           UnparsedAddressInputs(
               dockerfile_info.putative_target_addresses,
               owning_address=None,
           ),
       )
  +
  +    # Get the target for those addresses that are known.
  +    directories = {address.spec_path for address in putative_addresses}
  +    all_addresses = await Get(Addresses, AddressSpecs(map(MaybeEmptySiblingAddresses, directories)))
  +    targets = await Get(
  +        Targets, Addresses((address for address in putative_addresses if address in all_addresses))
  +    )
  +
  +    # Only keep those targets that we can "package".
       package = await Get(FieldSetsPerTarget, FieldSetsPerTargetRequest(PackageFieldSet, targets))
       referenced_targets = (
           field_sets[0].address for field_sets in package.collection if len(field_sets) > 0
  
verification_info: {"golden_diff": "diff --git a/src/python/pants/backend/docker/util_rules/dependencies.py b/src/python/pants/backend/docker/util_rules/dependencies.py\n--- a/src/python/pants/backend/docker/util_rules/dependencies.py\n+++ b/src/python/pants/backend/docker/util_rules/dependencies.py\n@@ -3,6 +3,7 @@\n \n from pants.backend.docker.subsystems.dockerfile_parser import DockerfileInfo, DockerfileInfoRequest\n from pants.backend.docker.target_types import DockerDependenciesField\n+from pants.base.specs import AddressSpecs, MaybeEmptySiblingAddresses\n from pants.core.goals.package import PackageFieldSet\n from pants.engine.addresses import Addresses, UnparsedAddressInputs\n from pants.engine.rules import Get, collect_rules, rule\n@@ -22,17 +23,28 @@\n \n @rule\n async def inject_docker_dependencies(request: InjectDockerDependencies) -> InjectedDependencies:\n-    \"\"\"Inspects COPY instructions in the Dockerfile for references to known targets.\"\"\"\n+    \"\"\"Inspects COPY instructions in the Dockerfile for references to known packagable targets.\"\"\"\n     dockerfile_info = await Get(\n         DockerfileInfo, DockerfileInfoRequest(request.dependencies_field.address)\n     )\n-    targets = await Get(\n-        Targets,\n+\n+    # Parse all putative target addresses.\n+    putative_addresses = await Get(\n+        Addresses,\n         UnparsedAddressInputs(\n             dockerfile_info.putative_target_addresses,\n             owning_address=None,\n         ),\n     )\n+\n+    # Get the target for those addresses that are known.\n+    directories = {address.spec_path for address in putative_addresses}\n+    all_addresses = await Get(Addresses, AddressSpecs(map(MaybeEmptySiblingAddresses, directories)))\n+    targets = await Get(\n+        Targets, Addresses((address for address in putative_addresses if address in all_addresses))\n+    )\n+\n+    # Only keep those targets that we can \"package\".\n     package = await Get(FieldSetsPerTarget, FieldSetsPerTargetRequest(PackageFieldSet, targets))\n     referenced_targets = (\n         field_sets[0].address for field_sets in package.collection if len(field_sets) > 0\n", "issue": "ResolveError: Directory '{mydir}' does not contain any BUILD files (when Dockerizing packages)\n**Describe the bug**\r\n\r\nCreated a repo at https://github.com/sureshjoshi/pantsbuild-14031 to help illustrate this problem. \r\n\r\nEssentially, I use custom output paths for my .pex files, and while testing out the `docker_image` target, I noticed some of my components fail with the error \r\n\r\n> ResolveError: Directory 'backend' does not contain any BUILD files\r\n\r\nAfter a lot of debugging, I only ran into this problem when my output folders were common to multiple `pex_binary` targets. \r\n\r\nFor example, in the repo above, I have 3 identical projects (A, B, C) - where they only differ by the `pex_binary` `output_path` (and this location updated in the associated Dockerfile), and one of the projects refuses to compile.\r\n\r\nAs per the README in the repo:\r\n\r\n```bash\r\n# Should create a pex at dist/backend/projecta/projecta.pex\r\n# Docker image created successfully as projecta-container:latest\r\n./pants package backend/projecta::\r\n\r\n# Should create a pex at dist/backend.projectc/projectc.pex\r\n# Docker image created successfully as projectc-container:latest\r\n./pants package backend/projectc::\r\n```\r\n\r\n```bash\r\n# Should create a pex at dist/backend/projectb.pex\r\n./pants package backend/projectb:projectb\r\n\r\n# FAILS: With ResolveError\r\n./pants package backend/projectb:projectb-container \r\n```\r\n\r\nSo, the difference above is that Project C uses no `output_path` and uses the dot-syntax for the dist folder. ProjectA places the pex file under a `backend/projecta` directory. The failing ProjectB places the pex file directly under `backend`.\r\n\r\nThis isn't a big issue, and easily worked around, and I'm guessing it has to do with namespacing or module/package semantics, but it's just a weird problem that is difficult to debug based on the error message.\r\n\r\n**Pants version**\r\n\r\n- 2.8.0\r\n- 2.9.0rc1\r\n\r\n**OS**\r\n\r\nmacOS 12.1\r\nUntested on Linux\r\n\n", "before_files": [{"content": "# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).\n# Licensed under the Apache License, Version 2.0 (see LICENSE).\n\nfrom pants.backend.docker.subsystems.dockerfile_parser import DockerfileInfo, DockerfileInfoRequest\nfrom pants.backend.docker.target_types import DockerDependenciesField\nfrom pants.core.goals.package import PackageFieldSet\nfrom pants.engine.addresses import Addresses, UnparsedAddressInputs\nfrom pants.engine.rules import Get, collect_rules, rule\nfrom pants.engine.target import (\n    FieldSetsPerTarget,\n    FieldSetsPerTargetRequest,\n    InjectDependenciesRequest,\n    InjectedDependencies,\n    Targets,\n)\nfrom pants.engine.unions import UnionRule\n\n\nclass InjectDockerDependencies(InjectDependenciesRequest):\n    inject_for = DockerDependenciesField\n\n\n@rule\nasync def inject_docker_dependencies(request: InjectDockerDependencies) -> InjectedDependencies:\n    \"\"\"Inspects COPY instructions in the Dockerfile for references to known targets.\"\"\"\n    dockerfile_info = await Get(\n        DockerfileInfo, DockerfileInfoRequest(request.dependencies_field.address)\n    )\n    targets = await Get(\n        Targets,\n        UnparsedAddressInputs(\n            dockerfile_info.putative_target_addresses,\n            owning_address=None,\n        ),\n    )\n    package = await Get(FieldSetsPerTarget, FieldSetsPerTargetRequest(PackageFieldSet, targets))\n    referenced_targets = (\n        field_sets[0].address for field_sets in package.collection if len(field_sets) > 0\n    )\n    return InjectedDependencies(Addresses(referenced_targets))\n\n\ndef rules():\n    return [\n        *collect_rules(),\n        UnionRule(InjectDependenciesRequest, InjectDockerDependencies),\n    ]\n", "path": "src/python/pants/backend/docker/util_rules/dependencies.py"}]}