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

gazelle generates different load() order when generating a new BUILD file vs. regenerating an existing file. #257

Closed
treaster opened this issue Feb 2, 2017 · 1 comment

Comments

@treaster
Copy link

treaster commented Feb 2, 2017

Running gazelle to generate a new BUILD file results in a different load() vs regenerating an existing file.
When generating a new file, the load() order is determined by the order defined here:
https://github.com/bazelbuild/rules_go/blob/master/go/tools/gazelle/generator/generator.go#L165

When regenerating an existing file, the merge process sorts the entries before producing the output.
https://github.com/bazelbuild/rules_go/blob/master/go/tools/gazelle/merger/merger.go#L142

I would expect gazelle to produce consistent output given consistent input of the go source files.

One possible fix would be to sort the rules list in generator.go.

To reproduce:

mkdir -p gazelle_test/code
cd gazelle_test/
echo "package main\nfunc main() {}" > code/main.go
gazelle --repo_root=. --go_prefix=code
cp code/BUILD  code/BUILD.1
gazelle --repo_root=. --go_prefix=code
diff code/BUILD.1 code/BUILD

Produces

$ diff code/BUILD.1 code/BUILD
1c1
< load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_binary")
---
> load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
jmhodges added a commit to jmhodges/rules_go that referenced this issue Feb 3, 2017
pmbethe09 pushed a commit that referenced this issue Feb 3, 2017
@treaster
Copy link
Author

treaster commented Feb 3, 2017

Thanks for the quick fix!!

groodt pushed a commit to groodt/rules_go that referenced this issue Mar 14, 2022
* Minimal C bindings
* Fix version reporting in C bindings
* Apply suggestions about C bindings implementation
* Rename compat/ -> c-bindings/
* Add comment about indexing VMs in C bindings
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

No branches or pull requests

1 participant