-
Notifications
You must be signed in to change notification settings - Fork 374
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
Allow some way to prioritise one file over another #237
Comments
I think this adds complexity without adding much value. I'd rather not implement it if the problem can be solved another way. Are you able to build this with What do you think about renaming files so the sorted order is the correct order? Something like If all else fails, you can mark the whole |
This does indeed work with I think perhaps this isnt so much an enhancement as much as it is a bug in that gazelle does not appear to apply the same load order to files that |
You're right, this is actually a bug. Gazelle uses buildifier internally to format build files before writing them out. One of the transformations buildifier applies is sorting string lists. The sorting algorithm is intended to work with labels as well as source files, so it's not strictly lexicographic. Buildifier has some functionality that lets you control this. Groups of strings in a list with an intervening blank line are sorted separately. And you can write "# do not sort" above a group to prevent it from being sorted. Not sure if that's documented anywhere, but the code is in rewrite.go. Unfortunately, when Gazelle uses buildifier through its library, we don't get that behavior. I'm not exactly sure why yet, but it is a bug. |
This allows user to attach comments like "# do not sort" to the assignment expressions maintained by rule.go. rule.Format() calls into buildtools/build.Format() which in turn calls Rewrite(). Rewrite() by default sorts certain label arguments like "deps" and "hdrs". To preventing this sorting it is possible to provide the comment "# do not sort". However this comment needs to be attached to the assignment expression. In rule.go the assignment expressions are not exposed to the user, making it impossible to attach the comment to it. See bazelbuild#237 (comment)
This allows user to attach comments like "# do not sort" to the assignment expressions maintained by rule.go. rule.Format() calls into buildtools/build.Format() which in turn calls Rewrite(). Rewrite() by default sorts certain label arguments like "deps" and "hdrs". To preventing this sorting it is possible to provide the comment "# do not sort". However this comment needs to be attached to the assignment expression. In rule.go the assignment expressions are not exposed to the user, making it impossible to attach the comment to it. See bazelbuild#237 (comment)
This allows user to attach comments like "# do not sort" to the assignment expressions maintained by rule.go. rule.Format() calls into buildtools/build.Format() which in turn calls Rewrite(). Rewrite() by default sorts certain label arguments like "deps" and "hdrs". To preventing this sorting it is possible to provide the comment "# do not sort". However this comment needs to be attached to the assignment expression. In rule.go the assignment expressions are not exposed to the user, making it impossible to attach the comment to it. See bazelbuild#237 (comment)
This allows user to attach comments like "# do not sort" to the assignment expressions maintained by rule.go. rule.Format() calls into buildtools/build.Format() which in turn calls Rewrite(). Rewrite() by default sorts certain label arguments like "deps" and "hdrs". To preventing this sorting it is possible to provide the comment "# do not sort". However this comment needs to be attached to the assignment expression. In rule.go the assignment expressions are not exposed to the user, making it impossible to attach the comment to it. See bazelbuild#237 (comment)
This allows user to attach comments like "# do not sort" to the assignment expressions maintained by rule.go. rule.Format() calls into buildtools/build.Format() which in turn calls Rewrite(). Rewrite() by default sorts certain label arguments like "deps" and "hdrs". To preventing this sorting it is possible to provide the comment "# do not sort". However this comment needs to be attached to the assignment expression. In rule.go the assignment expressions are not exposed to the user, making it impossible to attach the comment to it. See #237 (comment)
This allows user to attach comments like "# do not sort" to the assignment expressions maintained by rule.go. rule.Format() calls into buildtools/build.Format() which in turn calls Rewrite(). Rewrite() by default sorts certain label arguments like "deps" and "hdrs". To preventing this sorting it is possible to provide the comment "# do not sort". However this comment needs to be attached to the assignment expression. In rule.go the assignment expressions are not exposed to the user, making it impossible to attach the comment to it. See bazelbuild#237 (comment)
The
# keep
option is great, but unfortunately it does not have any effect on the order of the item. It seems gazelle will reordersrcs
values each time it is called. Problem is execution order sometimes matters in Go. I need a way to say "this file should be the first entry". At the moment the only option I see is to exclude the relevant directory from gazelle and manually define my rule.Example:
After I run gazelle the result is:
I need locale-packr.go to be first.
The text was updated successfully, but these errors were encountered: