-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from Homebrew/abstract_command
cmd/portable-package: migrate to AbstractCommand
- Loading branch information
Showing
1 changed file
with
54 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cli/parser" | ||
require "abstract_command" | ||
|
||
module Homebrew | ||
def self.portable_package_args | ||
Homebrew::CLI::Parser.new do | ||
usage_banner <<~EOS | ||
`portable-package` <formulae> | ||
module Cmd | ||
class PortablePackageCmd < AbstractCommand | ||
cmd_args do | ||
usage_banner <<~EOS | ||
`portable-package` <formulae> | ||
Build and package portable formulae. | ||
EOS | ||
switch "--no-uninstall-deps", | ||
description: "Don't uninstall all dependencies of portable formulae before testing." | ||
switch "-v", "--verbose", | ||
description: "Pass `--verbose` to `brew` commands." | ||
named_args :formula, min: 1 | ||
end | ||
end | ||
|
||
def self.portable_package | ||
args = portable_package_args.parse | ||
Build and package portable formulae. | ||
EOS | ||
switch "--no-uninstall-deps", | ||
description: "Don't uninstall all dependencies of portable formulae before testing." | ||
switch "-v", "--verbose", | ||
description: "Pass `--verbose` to `brew` commands." | ||
named_args :formula, min: 1 | ||
end | ||
|
||
ENV["HOMEBREW_DEVELOPER"] = "1" | ||
def run | ||
ENV["HOMEBREW_DEVELOPER"] = "1" | ||
|
||
verbose = [] | ||
verbose << "--verbose" if args.verbose? | ||
verbose << "--debug" if args.debug? | ||
verbose = [] | ||
verbose << "--verbose" if args.verbose? | ||
verbose << "--debug" if args.debug? | ||
|
||
# If test-bot cleanup is performed and auto-updates are disabled, this might not already be installed. | ||
unless DevelopmentTools.ca_file_handles_most_https_certificates? | ||
safe_system HOMEBREW_BREW_FILE, "install", "ca-certificates" | ||
end | ||
# If test-bot cleanup is performed and auto-updates are disabled, this might not already be installed. | ||
unless DevelopmentTools.ca_file_handles_most_https_certificates? | ||
safe_system HOMEBREW_BREW_FILE, "install", "ca-certificates" | ||
end | ||
|
||
args.named.each do |name| | ||
name = "portable-#{name}" unless name.start_with? "portable-" | ||
begin | ||
# On Linux, install [email protected] and linux-headers from bottles and don't install their build dependencies. | ||
bottled_dep_allowlist = %w[[email protected] [email protected]] | ||
deps = Dependency.expand(Formula[name], cache_key: "portable-package-#{name}") do |_dependent, dep| | ||
Dependency.prune if dep.test? || dep.optional? | ||
args.named.each do |name| | ||
name = "portable-#{name}" unless name.start_with? "portable-" | ||
begin | ||
# On Linux, install [email protected] and linux-headers from bottles and don't install their build dependencies. | ||
bottled_dep_allowlist = %w[[email protected] [email protected]] | ||
deps = Dependency.expand(Formula[name], cache_key: "portable-package-#{name}") do |_dependent, dep| | ||
Dependency.prune if dep.test? || dep.optional? | ||
|
||
next unless bottled_dep_allowlist.include?(dep.name) | ||
next unless bottled_dep_allowlist.include?(dep.name) | ||
|
||
Dependency.keep_but_prune_recursive_deps | ||
end.map(&:name) | ||
Dependency.keep_but_prune_recursive_deps | ||
end.map(&:name) | ||
|
||
bottled_deps, deps = deps.partition { |dep| bottled_dep_allowlist.include?(dep) } | ||
bottled_deps, deps = deps.partition { |dep| bottled_dep_allowlist.include?(dep) } | ||
|
||
safe_system HOMEBREW_BREW_FILE, "install", *verbose, *bottled_deps if bottled_deps.present? | ||
safe_system HOMEBREW_BREW_FILE, "install", *verbose, *bottled_deps if bottled_deps.present? | ||
|
||
# Build bottles for all other dependencies. | ||
safe_system HOMEBREW_BREW_FILE, "install", "--build-bottle", *verbose, *deps | ||
# Build bottles for all other dependencies. | ||
safe_system HOMEBREW_BREW_FILE, "install", "--build-bottle", *verbose, *deps | ||
|
||
safe_system HOMEBREW_BREW_FILE, "install", "--build-bottle", *verbose, name | ||
unless args.no_uninstall_deps? | ||
safe_system HOMEBREW_BREW_FILE, "uninstall", "--force", "--ignore-dependencies", *verbose, *deps | ||
safe_system HOMEBREW_BREW_FILE, "install", "--build-bottle", *verbose, name | ||
unless args.no_uninstall_deps? | ||
safe_system HOMEBREW_BREW_FILE, "uninstall", "--force", "--ignore-dependencies", *verbose, *deps | ||
end | ||
safe_system HOMEBREW_BREW_FILE, "test", *verbose, name | ||
puts "Linkage information:" | ||
safe_system HOMEBREW_BREW_FILE, "linkage", *verbose, name | ||
bottle_args = %w[ | ||
--skip-relocation | ||
--root-url=https://ghcr.io/v2/homebrew/portable-ruby | ||
--json | ||
--no-rebuild | ||
] | ||
safe_system HOMEBREW_BREW_FILE, "bottle", *verbose, *bottle_args, name | ||
rescue => e | ||
ofail e | ||
end | ||
end | ||
safe_system HOMEBREW_BREW_FILE, "test", *verbose, name | ||
puts "Linkage information:" | ||
safe_system HOMEBREW_BREW_FILE, "linkage", *verbose, name | ||
bottle_args = %w[ | ||
--skip-relocation | ||
--root-url=https://ghcr.io/v2/homebrew/portable-ruby | ||
--json | ||
--no-rebuild | ||
] | ||
safe_system HOMEBREW_BREW_FILE, "bottle", *verbose, *bottle_args, name | ||
rescue => e | ||
ofail e | ||
end | ||
end | ||
end | ||
|