build/analysis/haslicense: only check for license existence
We previously checked if the license header is byte-identical but since we do have dual-licensed code which would require exceptions. This just checks if a header exists and has the required fields.
Change-Id: I19f17353c3ea6bafbff6fa79af68442d8b96ce64
Reviewed-on: https://review.monogon.dev/c/monogon/+/3840
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/build/analysis/haslicense/haslicense.go b/build/analysis/haslicense/haslicense.go
index ff76285..46a8d66 100644
--- a/build/analysis/haslicense/haslicense.go
+++ b/build/analysis/haslicense/haslicense.go
@@ -27,14 +27,18 @@
}
if len(file.Comments) > 0 {
- var sb strings.Builder
- for _, c := range file.Comments[0].List {
- sb.WriteString(c.Text)
- sb.WriteRune('\n')
+ var hasCopyright, hasSPDX bool
+ lines := strings.Split(file.Comments[0].Text(), "\n")
+ for _, line := range lines {
+ switch {
+ case strings.HasPrefix(line, "Copyright "):
+ hasCopyright = true
+ case strings.HasPrefix(line, "SPDX-License-Identifier"):
+ hasSPDX = true
+ }
}
- sb.WriteRune('\n')
- if strings.HasPrefix(sb.String(), header) {
+ if hasCopyright && hasSPDX {
continue
}
}