Skip to content

Fix generation of facts file when diagnostics are ignored#4422

Merged
fmeum merged 1 commit intobazel-contrib:masterfrom
lbcjbb:fix-nogo-facts-files
Aug 11, 2025
Merged

Fix generation of facts file when diagnostics are ignored#4422
fmeum merged 1 commit intobazel-contrib:masterfrom
lbcjbb:fix-nogo-facts-files

Conversation

@lbcjbb
Copy link
Copy Markdown
Contributor

@lbcjbb lbcjbb commented Aug 11, 2025

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

After #4402, it is no longer possible to use a custom analyzer without having to declare a new Fact type. The build of a Go library will fail if the library contains any external dependencies.

That's the case for executing gazelle by example (if we don't use a precompiled binary):

$ bazel run //:gazelle
ERROR: .../external/gazelle++go_deps+org_golang_x_sync/errgroup/BUILD.bazel:3:11: output 'external/gazelle++go_deps+org_golang_x_sync/errgroup/errgroup.facts' was not created
ERROR: .../external/gazelle++go_deps+org_golang_x_sync/errgroup/BUILD.bazel:3:11: Running nogo on @@gazelle++go_deps+org_golang_x_sync//errgroup:errgroup failed: not all outputs were created or valid
ERROR: .../external/gazelle++go_deps+com_github_bazelbuild_buildtools/labels/BUILD.bazel:3:11: output 'external/gazelle++go_deps+com_github_bazelbuild_buildtools/labels/labels.facts' was not created
ERROR: .../external/gazelle++go_deps+com_github_bazelbuild_buildtools/labels/BUILD.bazel:3:11: Running nogo on @@gazelle++go_deps+com_github_bazelbuild_buildtools//labels:labels failed: not all outputs were created or valid
ERROR: .../external/gazelle++go_deps+in_gopkg_yaml_v3/BUILD.bazel:5:11: output 'external/gazelle++go_deps+in_gopkg_yaml_v3/yaml_v3.facts' was not created
ERROR: .../external/gazelle++go_deps+in_gopkg_yaml_v3/BUILD.bazel:5:11: Running nogo on @@gazelle++go_deps+in_gopkg_yaml_v3//:yaml_v3 failed: not all outputs were created or valid
ERROR: .../external/gazelle++go_deps+org_golang_x_sys/execabs/BUILD.bazel:3:11: output 'external/gazelle++go_deps+org_golang_x_sys/execabs/execabs.facts' was not created
ERROR: .../external/gazelle++go_deps+org_golang_x_sys/execabs/BUILD.bazel:3:11: Running nogo on @@gazelle++go_deps+org_golang_x_sys//execabs:execabs failed: not all outputs were created or valid
...

Other notes for review

This review continue to skip analysers when ignoring diagnostics, but return a valid pkg to create the missing .facts file required by the validation action, and incidentally, fix a potential crash at line

if err := os.WriteFile(abs(*xPath), pkg.facts.Encode(), 0o666); err != nil {
.

@lbcjbb lbcjbb force-pushed the fix-nogo-facts-files branch from 13d3798 to 4f105fd Compare August 11, 2025 11:39
@fmeum fmeum merged commit 0154403 into bazel-contrib:master Aug 11, 2025
1 check passed
@lbcjbb lbcjbb deleted the fix-nogo-facts-files branch August 15, 2025 07:50
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