@@ -75,8 +75,7 @@ def run
75
75
version = Version . new ( formula . dig ( "versions" , "stable" ) )
76
76
pkg_version = PkgVersion . new ( version , formula [ "revision" ] )
77
77
rebuild = formula . dig ( "bottle" , "stable" , "rebuild" ) || 0
78
- sha256 = formula . dig ( "bottle" , "stable" , "files" , :all , "sha256" )
79
- sha256 ||= formula . dig ( "bottle" , "stable" , "files" , bottle_tag . to_sym , "sha256" )
78
+ sha256 = newest_bottle_sha256 ( formula , bottle_tag )
80
79
81
80
[ name , [ pkg_version . to_s , rebuild , sha256 ] ]
82
81
end
@@ -88,6 +87,35 @@ def run
88
87
end
89
88
end
90
89
90
+ sig {
91
+ params ( formula_json : T ::Hash [ String , T . untyped ] , bottle_tag : Utils ::Bottles ::Tag ) . returns ( T . nilable ( String ) )
92
+ }
93
+ def newest_bottle_sha256 ( formula_json , bottle_tag )
94
+ available_tags = formula_json . dig ( "bottle" , "stable" , "files" ) &.keys &.map ( &:to_sym )
95
+ return unless available_tags
96
+
97
+ return formula_json . dig ( "bottle" , "stable" , "files" , :all , "sha256" ) if available_tags . include? :all
98
+
99
+ if available_tags . include? bottle_tag . to_sym
100
+ return formula_json . dig ( "bottle" , "stable" , "files" , bottle_tag . to_sym , "sha256" )
101
+ end
102
+
103
+ return unless bottle_tag . macos?
104
+
105
+ # If the actual tag is not available, find the newest tag with matching arch that's older than the actual tag
106
+ newest_viable_macos_tag = available_tags . filter_map do |tag_sym |
107
+ tag = Utils ::Bottles ::Tag . from_symbol ( tag_sym )
108
+ next unless tag . macos?
109
+ next if tag . arch != bottle_tag . arch
110
+ next if tag . to_macos_version > bottle_tag . to_macos_version
111
+
112
+ tag
113
+ end . max_by ( &:to_macos_version )
114
+ return unless newest_viable_macos_tag
115
+
116
+ formula_json . dig ( "bottle" , "stable" , "files" , newest_viable_macos_tag . to_sym , "sha256" )
117
+ end
118
+
91
119
private
92
120
93
121
sig { params ( title : String ) . returns ( String ) }
0 commit comments