pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.33k stars 638 forks source link

ResolveError: Directory '{mydir}' does not contain any BUILD files (when Dockerizing packages) #14031

Closed sureshjoshi closed 2 years ago

sureshjoshi commented 2 years ago

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:

# 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::
# 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

OS

macOS 12.1 Untested on Linux

stuhood commented 2 years ago

@kaos : Any thoughts here?

kaos commented 2 years ago

We had a holiday in Sweden yesterday, and I have another day off today, so will be a while before I can take a 👀 .

👍🏽 for the repro project, most excellent, thank you.