summaryrefslogtreecommitdiffhomepage
path: root/tools/nogo/findings.go
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2021-04-23 17:31:18 -0700
committergVisor bot <gvisor-bot@google.com>2021-04-23 17:33:32 -0700
commitf373f67048e2566af7fb5eaa68c3bec11607010a (patch)
tree6b921fac7f838b8e5c9be9f4a84a5709cdc5f8db /tools/nogo/findings.go
parent80cd26c2f43e78d43e2ff769cf0449e67254e673 (diff)
Improve nogo action cache-ability.
Presently, the standard library facts are not serialized in a deterministic order. This means that they have the possibility to change on each iteration, requiring a large scale re-analysis of all downstream actions, which includes all packages. Improve cache-ability of nogo actions by improving the determinism of the both facts and findings. Internally, default facts should be serialized as a sorted list for this reason already. PiperOrigin-RevId: 370188259
Diffstat (limited to 'tools/nogo/findings.go')
-rw-r--r--tools/nogo/findings.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/nogo/findings.go b/tools/nogo/findings.go
index 5bd850269..a00cfe813 100644
--- a/tools/nogo/findings.go
+++ b/tools/nogo/findings.go
@@ -19,6 +19,7 @@ import (
"fmt"
"go/token"
"io/ioutil"
+ "sort"
)
// Finding is a single finding.
@@ -44,6 +45,33 @@ func WriteFindingsToFile(findings []Finding, filename string) error {
// WriteFindingsToBytes serializes findings as bytes.
func WriteFindingsToBytes(findings []Finding) ([]byte, error) {
+ // N.B. Sort all the findings in order to maximize cacheability.
+ sort.Slice(findings, func(i, j int) bool {
+ switch {
+ case findings[i].Position.Filename < findings[j].Position.Filename:
+ return true
+ case findings[i].Position.Filename > findings[j].Position.Filename:
+ return false
+ case findings[i].Position.Line < findings[j].Position.Line:
+ return true
+ case findings[i].Position.Line > findings[j].Position.Line:
+ return false
+ case findings[i].Position.Column < findings[j].Position.Column:
+ return true
+ case findings[i].Position.Column > findings[j].Position.Column:
+ return false
+ case findings[i].Category < findings[j].Category:
+ return true
+ case findings[i].Category > findings[j].Category:
+ return false
+ case findings[i].Message < findings[j].Message:
+ return true
+ case findings[i].Message > findings[j].Message:
+ return false
+ default:
+ return false
+ }
+ })
return json.Marshal(findings)
}