extend brew extract to support casks, sharding, --unversioned, and livecheck/deprecation handling#5
Draft
Copilot wants to merge 2 commits into
Conversation
Co-authored-by: toobuntu <674390+toobuntu@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Extend brew extract to support casks and new features
extend Feb 25, 2026
brew extract to support casks, sharding, --unversioned, and livecheck/deprecation handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
brew extractonly supported formulae, always wrote to flatFormula/directories, and never stripped livecheck blocks. This extends it to match current Homebrew conventions: cask support, default sharding, unversioned copies, and livecheck/deprecation control.New flags
--cask/--formula— explicit type selection; auto-detected when unambiguous--unversioned— copy as-is without@versionsuffix or class/token rename (keeps livecheck; conflicts with--version)--remove-deprecations— comment outdeprecate!/disable!stanzas--keep-livecheck— preserve livecheck block in versioned snapshots (default: strip it)--no-shard— write to flat directory instead of sharded subdirectorySharding (now default for all taps)
Output paths now mirror core tap layout applied to any destination tap:
lib*→lib/, else first charFormula/t/testball@0.2.rbfont-*→font/font-<char>, else first charCasks/f/firefox@1.2.rbCask extraction
Casks are extracted from git history without loading via DSL (avoids syntax incompatibilities with old revisions). Version is parsed from raw content via
version "..."regex. Token is rewrittencask "foo" do→cask "foo@1.2" do.Implementation notes
resolve_sourcehandlesuser/tap/namequalified args for both formulae and casks, falling back toCoreTap/CoreCaskTaprespectivelyapply_common_transformationscentralises bottle-block removal, livecheck stripping, and deprecation commentingBOTTLE_BLOCK_REGEXand newLIVECHECK_BLOCK_REGEXare bothprivate_constantnamed_args [:formula, :cask, :tap]updated accordinglyOriginal prompt
Summary
Extend
brew extractto support casks (in addition to formulae), add--unversionedcopying, default sharding, and livecheck block handling. This modernizes extract to match current Homebrew conventions.Context
brew extractcurrently only supports formulae, always creates versioned copies, and writes to flatFormula/directoriesFormula/w/wget.rb,Formula/lib/libxml2.rb) and casks (Casks/f/firefox.rb,Casks/font/font-hack-nerd-font.rb)brew version-install(PR cmd/version-install: add new command. Homebrew/brew#21418 by MikeMcQuaid) wrapsextractbut only supports formulaeformula_auditor.rbwarns whenformula.path != formula.tap.new_formula_path(formula.name)— unsharded output creates audit warningsKey patterns from PR Homebrew#21418 (version-install)
safe_system HOMEBREW_BREW_FILEto call sibling commandsprivate_constantfor implementation constants# typed: strictwith Sorbet sigs on all methodsCmd(notDevCmd) — but extract is a dev-cmd, which is correctKey patterns from
unpack.rb(formula+cask handling)However,
extracttakes TWO named args: the formula/cask name AND the destination tap. Soto_formulae_and_caskscan't process all named args. We need to manually resolve the first arg.Files to modify
1.
Library/Homebrew/dev-cmd/extract.rbRead the current file first: https://github.com/Homebrew/brew/blob/b09c0cc3be143156c7ca280ce24c511b23b9ec3e/Library/Homebrew/dev-cmd/extract.rb
New constants (with
private_constant)Both should be
private_constant.New CLI flags
Add to
cmd_args:Update
named_argsto accept casks:Resolution logic (replacing the current formula-only approach)
The current code uses
Tap.with_formula_nameto splituser/repo/formulainto[tap, name]. We need to handle casks similarly usingTap.with_cask_token. For resolution itself, useFormulary.factoryfor formulae andCask::CaskLoader.loadfor casks — but note that for extract's purposes, we primarily need the source tap and name to search git history, not a fully loaded object.For the first named arg resolution:
--caskflag: useTap.with_cask_token, fall back toCoreCaskTap.instance--formulaflag: useTap.with_formula_name, fall back toCoreTap.instance(current behavior)Sharding logic
For determining where to write extracted files, apply sharding by default:
Formula sharding (from
CoreTap#new_formula_subdirectory):lib→lib/subdirectoryw/for wget)Cask sharding (from
CoreCaskTap#new_cask_subdirectory):font-→font/subdirectoryApply to ALL destination taps (not just core taps). Use
--no-shardto write to flat directories.For versioned names like
foo@1.2:foo→f/), not the full versioned nameCask extraction from git history
Similar to formula extraction but:
Casks/<letter>/token.rb,Casks/font/token.rb,Casks/token.rb(historical flat), andCasks/<digit>/token.rbThis pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.