Skip to content

Commit

Permalink
Fixes the bug where pants doesn't recognize build targets on top-leve…
Browse files Browse the repository at this point in the history
…l directories.

The previous argument parser naively simply checked whether a command-line argument contained a slash (/) or a colon (:). This is a reasonable assumption most of the time, but in the case where a BUILD file is located only one directory deep, (eg, buildroot/folder/BUILD), this makes it impossible to run pants on the target simply by calling (eg) ./pants goal bundle folder.

See github issue for example: pantsbuild#159

This fixes it by actually checking to see if a phase with goals is defined by the command-line argument. It still checks before that whether the argument contains a slash or a colon, because that if an argument has those characters it can't mean a goal. But an argument not having those characters doesn't mean it is a goal.
  • Loading branch information
gmalmquist committed Jun 12, 2014
1 parent abdd8e1 commit 3b40809
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/python/pants/commands/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,22 @@ def parse_args(args):
explicit_multi = False

def is_spec(spec):
return os.sep in spec or ':' in spec
if os.sep in spec or ':' in spec:
return True # Definitely not a goal.
if Phase(spec).goals():
return False # Definitely is a goal.
# Here we're going to guess based on whether the BUILD file exists.
spec_dir = os.path.join(get_buildroot(), spec)
# Have to check for build files that have extensions, to support 'BUILD.gen', etc.
if os.path.exists(spec_dir) and os.path.isdir(spec_dir):
for file_name in os.listdir(spec_dir):
dot = file_name.find('.')
if dot >= 0:
file_name = file_name[:dot]
if file_name == 'BUILD':
return True
return False


for i, arg in enumerate(args):
if not arg.startswith('-'):
Expand Down
12 changes: 12 additions & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

# Yes, this is a weird place for this BUILD file. It's here to test if pants can handle targets that
# are only 1 directory deep, and thus might not have a ':' or '/' on the spec path. (which goal.py
# previously has been bad about.)
java_library(name='tests',
sources=[],
dependencies=[
'tests/java/com/pants/examples/hello/greet',
],
)

0 comments on commit 3b40809

Please sign in to comment.