-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Expand file tree
/
Copy pathinternal.rb
More file actions
200 lines (159 loc) · 6.6 KB
/
Copy pathinternal.rb
File metadata and controls
200 lines (159 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# typed: strict
# frozen_string_literal: true
require "cachable"
require "api"
require "api/source_download"
require "download_queue"
module Homebrew
module API
# Helper functions for using the JSON internal API.
module Internal
extend T::Generic
extend Cachable
# Sorbet type members are mutable by design and cannot be frozen.
# rubocop:disable Style/MutableConstant
Cache = type_template { { fixed: T::Hash[String, T.untyped] } }
# rubocop:enable Style/MutableConstant
private_class_method :cache
sig { returns(String) }
def self.packages_endpoint
"internal/packages.#{SimulateSystem.current_tag}.jws.json"
end
sig { params(name: String).returns(Homebrew::API::FormulaStruct) }
def self.formula_struct(name)
return cache["formula_structs"][name] if cache.key?("formula_structs") && cache["formula_structs"].key?(name)
hash = formula_hashes[name]
raise "No formula found for #{name}" unless hash
struct = Homebrew::API::FormulaStruct.deserialize(hash, bottle_tag: SimulateSystem.current_tag)
cache["formula_structs"] ||= {}
cache["formula_structs"][name] = struct
struct
end
sig { params(name: String).returns(Homebrew::API::CaskStruct) }
def self.cask_struct(name)
return cache["cask_structs"][name] if cache.key?("cask_structs") && cache["cask_structs"].key?(name)
hash = cask_hashes[name]
raise "No cask found for #{name}" unless hash
struct = Homebrew::API::CaskStruct.deserialize(hash)
cache["cask_structs"] ||= {}
cache["cask_structs"][name] = struct
struct
end
sig { returns(Pathname) }
def self.cached_packages_json_file_path
HOMEBREW_CACHE_API/packages_endpoint
end
sig {
params(download_queue: Homebrew::DownloadQueue, stale_seconds: T.nilable(Integer), enqueue: T::Boolean)
.returns([T::Hash[String, T.untyped], T::Boolean])
}
def self.fetch_packages_api!(download_queue: Homebrew.default_download_queue, stale_seconds: nil,
enqueue: false)
json_contents, updated = Homebrew::API.fetch_json_api_file(packages_endpoint, stale_seconds:, download_queue:,
enqueue:)
[T.cast(json_contents, T::Hash[String, T.untyped]), updated]
end
sig { returns(T::Boolean) }
def self.download_and_cache_data!
json_contents, updated = fetch_packages_api!
cache["formula_structs"] = {}
cache["cask_structs"] = {}
cache["formula_aliases"] = json_contents["formula_aliases"]
cache["formula_renames"] = json_contents["formula_renames"]
cache["cask_renames"] = json_contents["cask_renames"]
cache["formula_tap_git_head"] = json_contents["formula_tap_git_head"]
cache["cask_tap_git_head"] = json_contents["cask_tap_git_head"]
cache["formula_tap_migrations"] = json_contents["formula_tap_migrations"]
cache["cask_tap_migrations"] = json_contents["cask_tap_migrations"]
cache["formula_hashes"] = json_contents["formulae"]
cache["cask_hashes"] = json_contents["casks"]
updated
end
private_class_method :download_and_cache_data!
sig { params(regenerate: T::Boolean, legacy_executables_fallback: T::Boolean).void }
def self.write_formula_names_and_aliases(regenerate: false, legacy_executables_fallback: false)
download_and_cache_data! unless cache.key?("formula_hashes")
Homebrew::API.write_names_file!(formula_hashes.keys, "formula", regenerate:)
Homebrew::API.write_aliases_file!(formula_aliases, "formula", regenerate:)
Homebrew::API.write_executables_file!(formula_hashes, regenerate:, legacy_executables_fallback:)
end
sig { params(regenerate: T::Boolean).void }
def self.write_cask_names(regenerate: false)
download_and_cache_data! unless cache.key?("cask_hashes")
Homebrew::API.write_names_file!(cask_hashes.keys, "cask", regenerate:)
end
sig { returns(T::Hash[String, T::Hash[String, T.untyped]]) }
def self.formula_hashes
unless cache.key?("formula_hashes")
updated = download_and_cache_data!
write_formula_names_and_aliases(regenerate: updated)
end
cache["formula_hashes"]
end
sig { returns(T::Hash[String, String]) }
def self.formula_aliases
unless cache.key?("formula_aliases")
updated = download_and_cache_data!
write_formula_names_and_aliases(regenerate: updated)
end
cache["formula_aliases"]
end
sig { returns(T::Hash[String, String]) }
def self.formula_renames
unless cache.key?("formula_renames")
updated = download_and_cache_data!
write_formula_names_and_aliases(regenerate: updated)
end
cache["formula_renames"]
end
sig { returns(T::Hash[String, String]) }
def self.formula_tap_migrations
unless cache.key?("formula_tap_migrations")
updated = download_and_cache_data!
write_formula_names_and_aliases(regenerate: updated)
end
cache["formula_tap_migrations"]
end
sig { returns(String) }
def self.formula_tap_git_head
unless cache.key?("formula_tap_git_head")
updated = download_and_cache_data!
write_formula_names_and_aliases(regenerate: updated)
end
cache["formula_tap_git_head"]
end
sig { returns(T::Hash[String, T::Hash[String, T.untyped]]) }
def self.cask_hashes
unless cache.key?("cask_hashes")
updated = download_and_cache_data!
write_cask_names(regenerate: updated)
end
cache["cask_hashes"]
end
sig { returns(T::Hash[String, String]) }
def self.cask_renames
unless cache.key?("cask_renames")
updated = download_and_cache_data!
write_cask_names(regenerate: updated)
end
cache["cask_renames"]
end
sig { returns(T::Hash[String, String]) }
def self.cask_tap_migrations
unless cache.key?("cask_tap_migrations")
updated = download_and_cache_data!
write_cask_names(regenerate: updated)
end
cache["cask_tap_migrations"]
end
sig { returns(String) }
def self.cask_tap_git_head
unless cache.key?("cask_tap_git_head")
updated = download_and_cache_data!
write_cask_names(regenerate: updated)
end
cache["cask_tap_git_head"]
end
end
end
end