Skip to content
Snippets Groups Projects
Unverified Commit eed1444d authored by Mike McQuaid's avatar Mike McQuaid
Browse files

Update deprecations and cleanup

- Move `odeprecated` to `odisabled`
- Remove `odisabled`
- Enable automatic cleanup on install/reinstall/upgrade.
parent 193af144
No related branches found
No related tags found
No related merge requests found
Showing
with 11 additions and 502 deletions
......@@ -64,10 +64,10 @@ Metrics/LineLength:
IgnoredPatterns: ['#: ']
# we won't change backward compatible predicate names
# TODO: deprecate whitelisted names and move to compat
Naming/PredicateName:
Exclude:
- 'compat/**/*'
# can't rename these
NameWhitelist: is_32_bit?, is_64_bit?
# whitelist those that are standard
......
......@@ -95,7 +95,7 @@ begin
end
if ENV["HOMEBREW_BUILD_FROM_SOURCE"]
odeprecated("HOMEBREW_BUILD_FROM_SOURCE", "--build-from-source")
odisabled("HOMEBREW_BUILD_FROM_SOURCE", "--build-from-source")
end
if internal_cmd
......
......@@ -41,7 +41,7 @@ module Homebrew
MACOSX_DEPLOYMENT_TARGET PKG_CONFIG_PATH PKG_CONFIG_LIBDIR
HOMEBREW_DEBUG HOMEBREW_MAKE_JOBS HOMEBREW_VERBOSE
HOMEBREW_SVN HOMEBREW_GIT
HOMEBREW_SDKROOT HOMEBREW_BUILD_FROM_SOURCE
HOMEBREW_SDKROOT
MAKE GIT CPP
ACLOCAL_PATH PATH CPATH
LD_LIBRARY_PATH LD_RUN_PATH LD_PRELOAD LIBRARY_PATH
......
......@@ -158,7 +158,6 @@ module Homebrew
def self.install_formula_clean!(f)
return if ENV["HOMEBREW_NO_INSTALL_CLEANUP"]
return unless ENV["HOMEBREW_INSTALL_CLEANUP"]
cleanup = Cleanup.new
if cleanup.periodic_clean_due?
......@@ -170,7 +169,6 @@ module Homebrew
def periodic_clean_due?
return false if ENV["HOMEBREW_NO_INSTALL_CLEANUP"]
return unless ENV["HOMEBREW_INSTALL_CLEANUP"]
return true unless PERIODIC_CLEAN_FILE.exist?
PERIODIC_CLEAN_FILE.mtime < CLEANUP_DEFAULT_DAYS.days.ago
......
......@@ -31,10 +31,6 @@
#: source even if a bottle is provided. Dependencies will still be installed
#: from bottles if they are available.
#:
#: If `HOMEBREW_BUILD_FROM_SOURCE` is set, regardless of whether `--build-from-source` was
#: passed, then both <formula> and the dependencies installed as part of this process
#: are built from source even if bottles are available.
#:
#: If `--force-bottle` is passed, install from a bottle if it exists for the
#: current or newest version of macOS, even if it would not normally be used
#: for installation.
......
......@@ -25,7 +25,6 @@ module Homebrew
def prune
prune_args.parse
odeprecated("'brew prune'", "'brew cleanup'")
Cleanup.new(dry_run: args.dry_run?).prune_prefix_symlinks_and_directories
odisabled("'brew prune'", "'brew cleanup'")
end
end
......@@ -3,9 +3,6 @@
#:
#: If `--display-times` is passed, install times for each formula are printed
#: at the end of the run.
#:
#: If `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed versions
#: of upgraded <formulae> as well as the HOMEBREW_CACHE for that formula.
require "formula_installer"
require "development_tools"
......@@ -23,9 +20,6 @@ module Homebrew
`reinstall` [<option(s)>] <formula>:
Uninstall and then install <formula> (with existing install options).
If `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed versions
of upgraded <formulae> as well as the HOMEBREW_CACHE for that formula.
EOS
switch "-s", "--build-from-source",
description: "Compile the formula> from source even if a bottle is available."
......
......@@ -28,13 +28,10 @@ module Homebrew
module_function
def upgrade
# TODO: deprecate for next minor release.
if ARGV.include?("--cleanup")
ENV["HOMEBREW_INSTALL_CLEANUP"] = "1"
odeprecated("'brew upgrade --cleanup'", "'HOMEBREW_INSTALL_CLEANUP'")
odisabled("'brew upgrade --cleanup'")
elsif ENV["HOMEBREW_UPGRADE_CLEANUP"]
ENV["HOMEBREW_INSTALL_CLEANUP"] = "1"
odeprecated("'HOMEBREW_UPGRADE_CLEANUP'", "'HOMEBREW_INSTALL_CLEANUP'")
odisabled("'HOMEBREW_UPGRADE_CLEANUP'")
end
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
......
require "compat/extend/os/mac/utils/bottles"
require "compat/os/mac"
require "compat/requirements/x11_requirement"
require "compat/requirements/xcode_requirement"
require "compat/cask"
require "compat/download_strategy"
require "compat/formula"
require "compat/tap"
require "compat/cask/cache"
require "compat/cask/cask_loader"
require "compat/cask/caskroom"
require "compat/cask/dsl"
module Cask
class << self
module Compat
def init
Cache.delete_legacy_cache
Caskroom.migrate_caskroom_from_repo_to_prefix
Caskroom.migrate_legacy_caskroom
super
end
end
prepend Compat
end
end
module Cask
module Cache
class << self
module Compat
def delete_legacy_cache
legacy_cache = HOMEBREW_CACHE.join("Casks")
return unless legacy_cache.exist?
ohai "Deleting legacy cache at #{legacy_cache}"
FileUtils.remove_entry_secure(legacy_cache)
end
end
prepend Compat
end
end
end
module Cask
module CaskLoader
class FromContentLoader; end
class FromPathLoader < FromContentLoader
module Compat
private
# TODO: can't delete this code until the merge of
# https://github.com/Homebrew/brew/pull/4730 or an equivalent.
def cask(header_token, **options, &block)
if header_token.is_a?(Hash) && header_token.key?(:v1)
odisabled %q("cask :v1 => 'token'"), %q("cask 'token'")
header_token = header_token[:v1]
end
super(header_token, **options, &block)
end
end
prepend Compat
end
end
end
module Cask
module Caskroom
class << self
module Compat
def migrate_legacy_caskroom
return if path.exist?
legacy_caskroom_path = Pathname.new("/opt/homebrew-cask/Caskroom")
return if path == legacy_caskroom_path
return unless legacy_caskroom_path.exist?
return if legacy_caskroom_path.symlink?
ohai "Migrating Caskroom from #{legacy_caskroom_path} to #{path}."
if path.parent.writable?
FileUtils.mv legacy_caskroom_path, path
else
opoo "#{path.parent} is not writable, sudo is needed to move the Caskroom."
SystemCommand.run("/bin/mv", args: [legacy_caskroom_path, path.parent], sudo: true)
end
ohai "Creating symlink from #{path} to #{legacy_caskroom_path}."
if legacy_caskroom_path.parent.writable?
FileUtils.ln_s path, legacy_caskroom_path
else
opoo "#{legacy_caskroom_path.parent} is not writable, sudo is needed to link the Caskroom."
SystemCommand.run("/bin/ln", args: ["-s", path, legacy_caskroom_path], sudo: true)
end
end
def migrate_caskroom_from_repo_to_prefix
repo_caskroom_path = HOMEBREW_REPOSITORY.join("Caskroom")
return if path.exist?
return unless repo_caskroom_path.directory?
ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX"
if path.parent.writable?
FileUtils.mv repo_caskroom_path, path
else
opoo "#{path.parent} is not writable, sudo is needed to move the Caskroom."
SystemCommand.run("/bin/mv", args: [repo_caskroom_path, path.parent], sudo: true)
end
end
end
prepend Compat
end
end
end
module Cask
class DSL
module Compat
# TODO: can't delete this code until the merge of
# https://github.com/Homebrew/brew/pull/4730 or an equivalent.
def gpg(*)
odisabled "the `gpg` stanza"
end
def license(*)
odisabled "the `license` stanza"
end
def accessibility_access(*)
odisabled "the `accessibility_access` stanza"
end
end
prepend Compat
end
end
require "download_strategy"
# S3DownloadStrategy downloads tarballs from AWS S3.
# To use it, add `:using => :s3` to the URL section of your
# formula. This download strategy uses AWS access tokens (in the
# environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`)
# to sign the request. This strategy is good in a corporate setting,
# because it lets you use a private S3 bucket as a repo for internal
# distribution. (It will work for public buckets as well.)
class S3DownloadStrategy < CurlDownloadStrategy
def initialize(url, name, version, **meta)
odisabled("S3DownloadStrategy",
"a vendored S3DownloadStrategy in your own formula or tap (using require_relative)")
super
end
def _fetch(url:, resolved_url:)
if url !~ %r{^https?://([^.].*)\.s3\.amazonaws\.com/(.+)$} &&
url !~ %r{^s3://([^.].*?)/(.+)$}
raise "Bad S3 URL: " + url
end
bucket = Regexp.last_match(1)
key = Regexp.last_match(2)
ENV["AWS_ACCESS_KEY_ID"] = ENV["HOMEBREW_AWS_ACCESS_KEY_ID"]
ENV["AWS_SECRET_ACCESS_KEY"] = ENV["HOMEBREW_AWS_SECRET_ACCESS_KEY"]
begin
require "aws-sdk-s3"
rescue LoadError
Homebrew.install_gem! "aws-sdk-s3", "~> 1.8"
require "aws-sdk-s3"
end
begin
signer = Aws::S3::Presigner.new
s3url = signer.presigned_url :get_object, bucket: bucket, key: key
rescue Aws::Sigv4::Errors::MissingCredentialsError
ohai "AWS credentials missing, trying public URL instead."
s3url = url
end
curl_download s3url, to: temporary_path
end
end
# GitHubPrivateRepositoryDownloadStrategy downloads contents from GitHub
# Private Repository. To use it, add
# `:using => :github_private_repo` to the URL section of
# your formula. This download strategy uses GitHub access tokens (in the
# environment variables `HOMEBREW_GITHUB_API_TOKEN`) to sign the request. This
# strategy is suitable for corporate use just like S3DownloadStrategy, because
# it lets you use a private GitHub repository for internal distribution. It
# works with public one, but in that case simply use CurlDownloadStrategy.
class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy
require "utils/formatter"
require "utils/github"
def initialize(url, name, version, **meta)
odisabled("GitHubPrivateRepositoryDownloadStrategy",
"a vendored GitHubPrivateRepositoryDownloadStrategy in your own formula or tap (using require_relative)")
super
parse_url_pattern
set_github_token
end
def parse_url_pattern
unless match = url.match(%r{https://github.com/([^/]+)/([^/]+)/(\S+)})
raise CurlDownloadStrategyError, "Invalid url pattern for GitHub Repository."
end
_, @owner, @repo, @filepath = *match
end
def download_url
"https://#{@github_token}@github.com/#{@owner}/#{@repo}/#{@filepath}"
end
private
def _fetch(url:, resolved_url:)
curl_download download_url, to: temporary_path
end
def set_github_token
@github_token = ENV["HOMEBREW_GITHUB_API_TOKEN"]
unless @github_token
raise CurlDownloadStrategyError, "Environmental variable HOMEBREW_GITHUB_API_TOKEN is required."
end
validate_github_repository_access!
end
def validate_github_repository_access!
# Test access to the repository
GitHub.repository(@owner, @repo)
rescue GitHub::HTTPNotFoundError
# We only handle HTTPNotFoundError here,
# becase AuthenticationFailedError is handled within util/github.
message = <<~EOS
HOMEBREW_GITHUB_API_TOKEN can not access the repository: #{@owner}/#{@repo}
This token may not have permission to access the repository or the url of formula may be incorrect.
EOS
raise CurlDownloadStrategyError, message
end
end
# GitHubPrivateRepositoryReleaseDownloadStrategy downloads tarballs from GitHub
# Release assets. To use it, add `:using => :github_private_release` to the URL section
# of your formula. This download strategy uses GitHub access tokens (in the
# environment variables HOMEBREW_GITHUB_API_TOKEN) to sign the request.
class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDownloadStrategy
def initialize(url, name, version, **meta)
odisabled("GitHubPrivateRepositoryReleaseDownloadStrategy",
"a vendored GitHubPrivateRepositoryReleaseDownloadStrategy in your own formula or tap (using require_relative)")
super
end
def parse_url_pattern
url_pattern = %r{https://github.com/([^/]+)/([^/]+)/releases/download/([^/]+)/(\S+)}
unless @url =~ url_pattern
raise CurlDownloadStrategyError, "Invalid url pattern for GitHub Release."
end
_, @owner, @repo, @tag, @filename = *@url.match(url_pattern)
end
def download_url
"https://#{@github_token}@api.github.com/repos/#{@owner}/#{@repo}/releases/assets/#{asset_id}"
end
private
def _fetch(url:, resolved_url:)
# HTTP request header `Accept: application/octet-stream` is required.
# Without this, the GitHub API will respond with metadata, not binary.
curl_download download_url, "--header", "Accept: application/octet-stream", to: temporary_path
end
def asset_id
@asset_id ||= resolve_asset_id
end
def resolve_asset_id
release_metadata = fetch_release_metadata
assets = release_metadata["assets"].select { |a| a["name"] == @filename }
raise CurlDownloadStrategyError, "Asset file not found." if assets.empty?
assets.first["id"]
end
def fetch_release_metadata
release_url = "https://api.github.com/repos/#{@owner}/#{@repo}/releases/tags/#{@tag}"
GitHub.open_api(release_url)
end
end
# ScpDownloadStrategy downloads files using ssh via scp. To use it, add
# `:using => :scp` to the URL section of your formula or
# provide a URL starting with scp://. This strategy uses ssh credentials for
# authentication. If a public/private keypair is configured, it will not
# prompt for a password.
#
# @example
# class Abc < Formula
# url "scp://example.com/src/abc.1.0.tar.gz"
# ...
class ScpDownloadStrategy < AbstractFileDownloadStrategy
def initialize(url, name, version, **meta)
odisabled("ScpDownloadStrategy",
"a vendored ScpDownloadStrategy in your own formula or tap (using require_relative)")
super
parse_url_pattern
end
def parse_url_pattern
url_pattern = %r{scp://([^@]+@)?([^@:/]+)(:\d+)?/(\S+)}
if @url !~ url_pattern
raise ScpDownloadStrategyError, "Invalid URL for scp: #{@url}"
end
_, @user, @host, @port, @path = *@url.match(url_pattern)
end
def fetch
ohai "Downloading #{@url}"
if cached_location.exist?
puts "Already downloaded: #{cached_location}"
else
system_command! "scp", args: [scp_source, temporary_path.to_s]
ignore_interrupts { temporary_path.rename(cached_location) }
end
end
def clear_cache
super
rm_rf(temporary_path)
end
private
def scp_source
path_prefix = "/" unless @path.start_with?("~")
port_arg = "-P #{@port[1..-1]} " if @port
"#{port_arg}#{@user}#{@host}:#{path_prefix}#{@path}"
end
end
class DownloadStrategyDetector
class << self
module Compat
def detect_from_url(url)
case url
when %r{^s3://}
odisabled("s3://",
"a vendored S3DownloadStrategy in your own formula or tap (using require_relative)")
S3DownloadStrategy
when %r{^scp://}
odisabled("scp://",
"a vendored ScpDownloadStrategy in your own formula or tap (using require_relative)")
ScpDownloadStrategy
else
super(url)
end
end
def detect_from_symbol(symbol)
case symbol
when :github_private_repo
odisabled(":github_private_repo",
"a vendored GitHubPrivateRepositoryDownloadStrategy in your own formula or tap (using require_relative)")
GitHubPrivateRepositoryDownloadStrategy
when :github_private_release
odisabled(":github_private_repo",
"a vendored GitHubPrivateRepositoryReleaseDownloadStrategy in your own formula or tap "\
"(using require_relative)")
GitHubPrivateRepositoryReleaseDownloadStrategy
when :s3
odisabled(":s3",
"a vendored S3DownloadStrategy in your own formula or tap (using require_relative)")
S3DownloadStrategy
when :scp
odisabled(":scp",
"a vendored ScpDownloadStrategy in your own formula or tap (using require_relative)")
ScpDownloadStrategy
else
super(symbol)
end
end
end
prepend Compat
end
end
module Utils
class Bottles
class Collector
module Compat
private
def tag_without_or_later(tag)
return super unless tag.to_s.end_with?("_or_later")
odisabled "`or_later` bottles",
"bottles without `or_later` (or_later is implied now)"
tag.to_s[/(\w+)_or_later$/, 1].to_sym
end
end
prepend Compat
end
end
end
......@@ -2,40 +2,15 @@ class Formula
module Compat
# Run `scons` using a Homebrew-installed version rather than whatever is
# in the `PATH`.
# TODO: deprecate
def scons(*args)
odeprecated("scons", 'system "scons"')
system Formulary.factory("scons").opt_bin/"scons", *args
def scons(*)
odisabled("scons", 'system "scons"')
end
# Run `make` 3.81 or newer.
# Uses the system make on Leopard and newer, and the
# path to the actually-installed make on Tiger or older.
# TODO: deprecate
def make(*args)
odeprecated("make", 'system "make"')
if Utils.popen_read("/usr/bin/make", "--version")
.match(/Make (\d\.\d+)/)[1] > "3.80"
make_path = "/usr/bin/make"
else
make = Formula["make"].opt_bin/"make"
make_path = if make.exist?
make.to_s
else
(Formula["make"].opt_bin/"gmake").to_s
end
end
if superenv?
make_name = File.basename(make_path)
with_env(HOMEBREW_MAKE: make_name) do
system "make", *args
end
else
system make_path, *args
end
def make(*)
odisabled("make", 'system "make"')
end
end
......
......@@ -3,7 +3,7 @@ module OS
class << self
module Compat
def prefer_64_bit?
odeprecated("MacOS.prefer_64_bit?")
odisabled("MacOS.prefer_64_bit?")
Hardware::CPU.is_64_bit?
end
end
......
require "requirement"
class X11Requirement < Requirement
module Compat
def initialize(tags = [])
if tags.first.to_s.match?(/(\d\.)+\d/)
odisabled('depends_on :x11 => "X.Y.Z"')
end
super(tags)
end
end
prepend Compat
end
require "requirement"
class XcodeRequirement < Requirement
module Compat
def initialize(tags = [])
@version = if tags.first.to_s.match?(/(\d\.)+\d/)
tags.shift
else
tags.find do |tag|
next unless tag.to_s.match?(/(\d\.)+\d/)
odisabled('depends_on :xcode => [..., "X.Y.Z"]')
tags.delete(tag)
end
end
super(tags)
end
end
prepend Compat
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment