Skip to content

Commit fe0a9c4

Browse files
authored
Merge pull request #20327 from Homebrew/download_queue_source_download
formula*: add source download support for download queue.
2 parents a947ad6 + 5d01b22 commit fe0a9c4

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Library/Homebrew/api/formula.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def self.fetch(name)
2828
Homebrew::API.fetch "formula/#{name}.json"
2929
end
3030

31-
sig { params(formula: ::Formula).returns(::Formula) }
32-
def self.source_download(formula)
31+
sig { params(formula: ::Formula, download_queue: T.nilable(Homebrew::DownloadQueue)).returns(Homebrew::API::SourceDownload) }
32+
def self.source_download(formula, download_queue: nil)
3333
path = formula.ruby_source_path || "Formula/#{formula.name}.rb"
3434
git_head = formula.tap_git_head || "HEAD"
3535
tap = formula.tap&.full_name || "Homebrew/homebrew-core"
@@ -39,7 +39,19 @@ def self.source_download(formula)
3939
formula.ruby_source_checksum,
4040
cache: HOMEBREW_CACHE_API_SOURCE/"#{tap}/#{git_head}/Formula",
4141
)
42-
download.fetch
42+
43+
if download_queue
44+
download_queue.enqueue(download)
45+
elsif !download.cache.exist?
46+
download.fetch
47+
end
48+
49+
download
50+
end
51+
52+
sig { params(formula: ::Formula).returns(::Formula) }
53+
def self.source_download_formula(formula)
54+
download = source_download(formula)
4355

4456
with_env(HOMEBREW_FORBID_PACKAGES_FROM_PATHS: nil) do
4557
Formulary.factory(download.symlink_location,

Library/Homebrew/formula_installer.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,12 @@ def prelude_fetch
317317
end
318318
end
319319

320-
# Needs to be done before expand_dependencies for compute_dependencies
321-
fetch_bottle_tab if pour_bottle?
320+
if pour_bottle?
321+
# Needs to be done before expand_dependencies for compute_dependencies
322+
fetch_bottle_tab
323+
elsif formula.loaded_from_api?
324+
Homebrew::API::Formula.source_download(formula, download_queue:)
325+
end
322326

323327
fetch_fetch_deps unless ignore_deps?
324328

@@ -1446,7 +1450,7 @@ def fetch
14461450

14471451
!downloadable_object.cached_download.exist?
14481452
else
1449-
@formula = Homebrew::API::Formula.source_download(formula) if formula.loaded_from_api?
1453+
@formula = Homebrew::API::Formula.source_download_formula(formula) if formula.loaded_from_api?
14501454

14511455
if (download_queue = self.download_queue)
14521456
formula.enqueue_resources_and_patches(download_queue:)

0 commit comments

Comments
 (0)