Skip to content

Commit 0387ed1

Browse files
authored
fix(spdx): Only warn when the same LicenseIDs have different text (#2053)
A lot of packages that exist in Wolfi and Chainguard OS have the same LicenseIDs but different license text. Until we've updated all references across the OS to be unique when the text differs, only throw a warning Signed-off-by: RJ Sampson <rj.sampson@chainguard.dev>
1 parent 300620e commit 0387ed1

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

pkg/sbom/generator/spdx/spdx.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (sx *SPDX) Generate(ctx context.Context, opts *options.Options, path string
151151

152152
for _, pkg := range opts.Packages {
153153
// Check to see if the apk contains an sbom describing itself
154-
if err := sx.ProcessInternalApkSBOM(opts, doc, pkg); err != nil {
154+
if err := sx.ProcessInternalApkSBOM(ctx, opts, doc, pkg); err != nil {
155155
return fmt.Errorf("parsing internal apk SBOM: %w", err)
156156
}
157157
}
@@ -201,7 +201,7 @@ func locateApkSBOM(fsys apkfs.ReaderFS, ipkg *apk.InstalledPackage) (string, err
201201
return "", nil
202202
}
203203

204-
func (sx *SPDX) ProcessInternalApkSBOM(opts *options.Options, doc *Document, ipkg *apk.InstalledPackage) error {
204+
func (sx *SPDX) ProcessInternalApkSBOM(ctx context.Context, opts *options.Options, doc *Document, ipkg *apk.InstalledPackage) error {
205205
// Check if apk installed an SBOM
206206
path, err := locateApkSBOM(opts.FS, ipkg)
207207
if err != nil {
@@ -260,9 +260,7 @@ func (sx *SPDX) ProcessInternalApkSBOM(opts *options.Options, doc *Document, ipk
260260
return fmt.Errorf("copying element: %w", err)
261261
}
262262

263-
if err := mergeLicensingInfos(apkSBOMDoc, doc); err != nil {
264-
return fmt.Errorf("merging LicensingInfos: %w", err)
265-
}
263+
mergeLicensingInfos(ctx, apkSBOMDoc, doc)
266264

267265
// Add CONTAINS relationships from the document root package to all top-level elements from the internal SBOM.
268266
// This ensures they are reachable from the document root for tools that traverse the SBOM graph.
@@ -328,14 +326,14 @@ func copySBOMElements(sourceDoc, targetDoc *Document, todo map[string]struct{})
328326
return nil
329327
}
330328

331-
func mergeLicensingInfos(sourceDoc, targetDoc *Document) error {
329+
func mergeLicensingInfos(ctx context.Context, sourceDoc, targetDoc *Document) {
332330
var found bool
333331
for _, sourceinfo := range sourceDoc.LicensingInfos {
334332
found = false
335333
for _, targetinfo := range targetDoc.LicensingInfos {
336334
if targetinfo.LicenseID == sourceinfo.LicenseID {
337335
if targetinfo.ExtractedText != sourceinfo.ExtractedText {
338-
return fmt.Errorf("source & target LicenseID %s differ in Text; perhaps multiple versions of the package have different contents of files provided in license-path", targetinfo.LicenseID)
336+
clog.FromContext(ctx).Warnf("source & target LicenseID %s differ in Text; please either update the package's license-path or use the correct LicenseID", targetinfo.LicenseID)
339337
}
340338
found = true
341339
break
@@ -345,7 +343,6 @@ func mergeLicensingInfos(sourceDoc, targetDoc *Document) error {
345343
targetDoc.LicensingInfos = append(targetDoc.LicensingInfos, sourceinfo)
346344
}
347345
}
348-
return nil
349346
}
350347

351348
// ParseInternalSBOM opens an SBOM inside apks and

0 commit comments

Comments
 (0)