@@ -17,6 +17,13 @@ class SBOM
17
17
# Instantiates a {SBOM} for a new installation of a formula.
18
18
sig { params ( formula : Formula , tab : Tab ) . returns ( T . attached_class ) }
19
19
def self . create ( formula , tab )
20
+ active_spec = if formula . stable?
21
+ T . must ( formula . stable )
22
+ else
23
+ T . must ( formula . head )
24
+ end
25
+ active_spec_sym = formula . active_spec_sym
26
+
20
27
attributes = {
21
28
name : formula . name ,
22
29
homebrew_version : HOMEBREW_VERSION ,
@@ -32,13 +39,13 @@ def self.create(formula, tab)
32
39
path : formula . specified_path . to_s ,
33
40
tap : formula . tap &.name ,
34
41
tap_git_head : nil , # Filled in later if possible
35
- spec : formula . active_spec_sym . to_s ,
36
- patches : formula . stable & .patches ,
42
+ spec : active_spec_sym . to_s ,
43
+ patches : active_spec . patches ,
37
44
bottle : formula . bottle_hash ,
38
- stable : {
39
- version : formula . stable & .version ,
40
- url : formula . stable & .url ,
41
- checksum : formula . stable & .checksum ,
45
+ active_spec_sym => {
46
+ version : active_spec . version ,
47
+ url : active_spec . url ,
48
+ checksum : active_spec . checksum ,
42
49
} ,
43
50
} ,
44
51
}
@@ -230,7 +237,8 @@ def generate_relations_json(runtime_dependency_declaration, compiler_declaration
230
237
}
231
238
def generate_packages_json ( runtime_dependency_declaration , compiler_declaration , bottling :)
232
239
bottle = [ ]
233
- if !bottling && ( bottle_info = get_bottle_info ( source [ :bottle ] ) )
240
+ if !bottling && ( bottle_info = get_bottle_info ( source [ :bottle ] ) ) &&
241
+ ( stable_version = source . dig ( :stable , :version ) )
234
242
bottle << {
235
243
SPDXID : "SPDXRef-Bottle-#{ name } " ,
236
244
name : name . to_s ,
@@ -267,18 +275,18 @@ def generate_packages_json(runtime_dependency_declaration, compiler_declaration,
267
275
{
268
276
SPDXID : "SPDXRef-Archive-#{ name } -src" ,
269
277
name : name . to_s ,
270
- versionInfo : stable_version . to_s ,
278
+ versionInfo : spec_version . to_s ,
271
279
filesAnalyzed : false ,
272
280
licenseDeclared : assert_value ( nil ) ,
273
281
builtDate : source_modified_time . to_s ,
274
282
licenseConcluded : assert_value ( license ) ,
275
- downloadLocation : source [ :stable ] [ :url ] ,
283
+ downloadLocation : source [ spec_symbol ] [ :url ] ,
276
284
copyrightText : assert_value ( nil ) ,
277
285
externalRefs : [ ] ,
278
286
checksums : [
279
287
{
280
288
algorithm : "SHA256" ,
281
- checksumValue : source [ :stable ] [ :checksum ] . to_s ,
289
+ checksumValue : source [ spec_symbol ] [ :checksum ] . to_s ,
282
290
} ,
283
291
] ,
284
292
} ,
@@ -362,13 +370,13 @@ def to_spdx_sbom(bottling:)
362
370
{
363
371
SPDXID : "SPDXRef-DOCUMENT" ,
364
372
spdxVersion : "SPDX-2.3" ,
365
- name : "SBOM-SPDX-#{ name } -#{ stable_version } " ,
373
+ name : "SBOM-SPDX-#{ name } -#{ spec_version } " ,
366
374
creationInfo : {
367
375
created : ( Time . at ( time ) . utc if time . present? && !bottling ) ,
368
376
creators : [ "Tool: https://github.com/homebrew/brew@#{ homebrew_version } " ] ,
369
377
} ,
370
378
dataLicense : "CC0-1.0" ,
371
- documentNamespace : "https://formulae.brew.sh/spdx/#{ name } -#{ stable_version } .json" ,
379
+ documentNamespace : "https://formulae.brew.sh/spdx/#{ name } -#{ spec_version } .json" ,
372
380
documentDescribes : packages . map { |dependency | dependency [ :SPDXID ] } ,
373
381
files : [ ] ,
374
382
packages :,
@@ -397,9 +405,14 @@ def tap
397
405
Tap . fetch ( tap_name ) if tap_name
398
406
end
399
407
408
+ sig { returns ( Symbol ) }
409
+ def spec_symbol
410
+ source . fetch ( :spec ) . to_sym
411
+ end
412
+
400
413
sig { returns ( T . nilable ( Version ) ) }
401
- def stable_version
402
- source [ :stable ] [ :version ]
414
+ def spec_version
415
+ source . fetch ( spec_symbol ) [ :version ]
403
416
end
404
417
405
418
sig { returns ( Time ) }
0 commit comments