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

Misleading error message when glob expands to empty list of files #1507

Closed
ittaiz opened this issue Jul 12, 2016 · 7 comments
Closed

Misleading error message when glob expands to empty list of files #1507

ittaiz opened this issue Jul 12, 2016 · 7 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request
Milestone

Comments

@ittaiz
Copy link
Member

ittaiz commented Jul 12, 2016

I moved a test target from the root of my project to a sub package and forgot to update the glob expression of my sources (was glob(["src/test/java/com/example/*.java"]) and should have been changed to glob(["*.java"]) after the move).

When I ran the build I got an error message which IMHO is somewhat misleading.
The error message says that deps is not allowed without srcs and suggests to move them to runtime_deps. Only after a bit of digging I realized that the glob expanded to an empty list and so Bazel thinks I did not declare any sources. Problem is that when you "statically" look at the target you see that srcs is defined.

ERROR: /Users/ittaiz/workspace/bazel-playground/java-getting-started/src/test/java/com/example/BUILD:5:12: in deps attribute of java_test rule //src/test/java/com/example:hola: deps not allowed without srcs; move to runtime_deps?

WDYT about adding to the error message something which says that maybe the srcs is defined but is actually empty?

@kchodorow kchodorow added type: feature request P2 We'll consider working on this in future. (Assignee optional) category: rules > java labels Jul 12, 2016
@kchodorow
Copy link
Contributor

Good idea.

@kchodorow kchodorow added this to the 0.5 milestone Jul 12, 2016
@ittaiz
Copy link
Member Author

ittaiz commented Jul 12, 2016

If you want a PR I'd be happy to give it a try given a pointer to the relevant place.
In any case this isn't in a hurry for me.

@kchodorow
Copy link
Contributor

@ittaiz
Copy link
Member Author

ittaiz commented Jul 12, 2016

So you're talking about changing the implementation and not the error message, right?
replace
&& ruleContext.attributes().get("srcs", BuildType.LABEL_LIST).isEmpty()
with
&& !ruleContext.getRule().isAttributeValueExplicitlySpecified("srcs")?

@kchodorow
Copy link
Contributor

I think you'd need to add the && !ruleContext.getRule().isAttributeValueExplicitlySpecified("srcs") clause, you still need the isEmpty() check. I haven't tested it or anything, though.

@ittaiz
Copy link
Member Author

ittaiz commented Jul 12, 2016

ok, will handle it from here.
Thanks!

@lberki lberki added category: misc > misc P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed category: rules > java P2 We'll consider working on this in future. (Assignee optional) labels Dec 9, 2016
@damienmg damienmg modified the milestones: 0.7, 0.5 Feb 16, 2017
@laurentlb
Copy link
Contributor

This will change with #8195

In the future, the glob function will fail if the pattern doesn't match anything. This will help you find the bug quickly in this case (the attribute allow_empty lets you opt in the old behavior).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants