Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the bug where pants doesn't recognize build targets on top-level d... #218

Closed
wants to merge 1 commit into from

Conversation

gmalmquist
Copy link
Contributor

...irectories.

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

This fixes it by actually checking to see if a phase with goals is defined by the command-line argument, and whether a BUILD file associated with the spec actually exists. 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.

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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help says:

./pants goal [option ...] [goal ...] [target...] Attempt the specified goals.

This implies that once you get a target, there can be no more goals. I don't see this reflected in the existing logic.

I'm thinking that the shorthand usage is not correct. Maybe something more like this correctly expresses it:

./pants goal [option ...] [ goal [target ...] ] [ goal [target ...]] ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see down lower ( elif '--' == arg: ) that there is mention of intermixing targets and goals. so it looks like this is supposed to be legal?

pants goal binary foo compile bar server
pants goal

I wonder if we can get some background on this because this parsing looks pretty fragile trying to handle all these cases.

For example, the code for enforcing that specs appear on the right doesn't enforce that goals appear only on the left. This is important because if we have a one directory deep BUILD file that conflicts with any goal name, it will always be considered a goal, so we need a testcase like:

binary/BUILD # contains a definition named 'binary' for a default target.
pants goal binary -- binary

In this case, would we want

pants goal binary binary

to work? It isn't ambiguous when you think about it (binary must have a spec following)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it does look like pants goal binary -- binary would work - there is a break out of the 'enumerate(args):' loop and every non dashed argument is added to specs.

@ericzundel
Copy link
Member

Looks good, please rebase and post to RBCommons for pants-devel to review.

…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.

In a completely ambiguous situation (eg, given a command argument 'bundle', and there is a valid BUILD file at bundle/BUILD), we err on the side of the goal, and print out a warning. This makes sense, because it allows the user to disambiguate the situation using the '--' syntax.
@ericzundel ericzundel closed this Jun 26, 2014
@ericzundel ericzundel deleted the garrett/slashes branch June 26, 2014 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants