From 94416e82f0e59cea55153005db93335ffeb744f9 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 24 Sep 2024 10:15:34 +0100 Subject: [PATCH] Add new odeprecated, odisabled, remove disabled code. Prepare the usual deprecation cycle for Homebrew 4.4.0. --- Library/Homebrew/cask/artifact/moved.rb | 6 +- Library/Homebrew/cask/dsl.rb | 2 +- Library/Homebrew/cask/dsl/caveats.rb | 2 +- Library/Homebrew/cask/installer.rb | 6 +- Library/Homebrew/cask/utils.rb | 2 +- Library/Homebrew/cleanup.rb | 6 +- Library/Homebrew/cli/parser.rb | 10 +- Library/Homebrew/cmd/update-report.rb | 4 +- Library/Homebrew/cmd/update.sh | 20 ++-- Library/Homebrew/cmd/upgrade.rb | 7 -- Library/Homebrew/dev-cmd/bump-cask-pr.rb | 4 - Library/Homebrew/dev-cmd/bump-formula-pr.rb | 4 - Library/Homebrew/dev-cmd/prof.rb | 1 - Library/Homebrew/dev-cmd/tap-new.rb | 8 +- Library/Homebrew/diagnostic.rb | 2 +- Library/Homebrew/download_strategy.rb | 7 -- Library/Homebrew/exceptions.rb | 4 +- Library/Homebrew/extend/kernel.rb | 2 +- Library/Homebrew/extend/pathname.rb | 2 +- Library/Homebrew/formula.rb | 12 +-- Library/Homebrew/formula_auditor.rb | 2 +- Library/Homebrew/formula_installer.rb | 6 +- Library/Homebrew/git_repository.rb | 13 ++- Library/Homebrew/github_packages.rb | 8 +- Library/Homebrew/keg.rb | 2 +- Library/Homebrew/language/go.rb | 2 +- Library/Homebrew/os/linux.rb | 74 ++------------- Library/Homebrew/os/mac.rb | 19 ++-- Library/Homebrew/os/mac/xcode.rb | 4 - Library/Homebrew/reinstall.rb | 4 +- Library/Homebrew/software_spec.rb | 2 +- Library/Homebrew/tap.rb | 92 +++++++++++-------- Library/Homebrew/tap_constants.rb | 6 +- .../Homebrew/test/cask/artifact/app_spec.rb | 2 +- Library/Homebrew/test/cask/installer_spec.rb | 2 +- Library/Homebrew/test/cask/uninstall_spec.rb | 2 +- Library/Homebrew/test/cmd/reinstall_spec.rb | 2 +- .../Homebrew/test/cmd/update-report_spec.rb | 6 +- .../Homebrew/test/diagnostic_checks_spec.rb | 4 +- Library/Homebrew/test/exceptions_spec.rb | 4 +- .../Homebrew/test/formula_installer_spec.rb | 10 +- Library/Homebrew/test/formula_spec.rb | 12 +-- Library/Homebrew/test/keg_spec.rb | 2 +- Library/Homebrew/test/migrator_spec.rb | 2 +- Library/Homebrew/test/tap_spec.rb | 44 ++++----- Library/Homebrew/unpack_strategy/bazaar.rb | 2 +- Library/Homebrew/utils/inreplace.rb | 2 +- .../utils/string_inreplace_extension.rb | 16 ++-- 48 files changed, 199 insertions(+), 258 deletions(-) diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index 7a98a9161b272..b8be1ecd6907a 100644 --- a/Library/Homebrew/cask/artifact/moved.rb +++ b/Library/Homebrew/cask/artifact/moved.rb @@ -86,7 +86,7 @@ def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall end # Remove the source as we don't need to move it to the target location - source.rmtree + FileUtils.rm_r(source) return post_move(command) end @@ -112,14 +112,14 @@ def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall sudo: true) end Quarantine.copy_xattrs(source, target, command:) - source.rmtree + FileUtils.rm_r(source) elsif target.dirname.writable? FileUtils.move(source, target) else # default sudo user isn't necessarily able to write to Homebrew's locations # e.g. with runas_default set in the sudoers (5) file. command.run!("/bin/cp", args: ["-pR", source, target], sudo: true) - source.rmtree + FileUtils.rm_r(source) end post_move(command) diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index 32021a702c1b7..bb5d36cf7ec44 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -411,7 +411,7 @@ def caveats(*strings, &block) end def discontinued? - odeprecated "`discontinued?`", "`deprecated?` or `disabled?`" + odisabled "`discontinued?`", "`deprecated?` or `disabled?`" @caveats&.discontinued? == true end diff --git a/Library/Homebrew/cask/dsl/caveats.rb b/Library/Homebrew/cask/dsl/caveats.rb index 5872cb79108eb..cd27bf0776038 100644 --- a/Library/Homebrew/cask/dsl/caveats.rb +++ b/Library/Homebrew/cask/dsl/caveats.rb @@ -164,7 +164,7 @@ def eval_caveats(&block) end caveat :discontinued do - odeprecated "`caveats :discontinued`", "`deprecate!`" + odisabled "`caveats :discontinued`", "`deprecate!`" @discontinued = true <<~EOS #{@cask} has been officially discontinued upstream. diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 1b5433dae1dc3..6877f13ee651c 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -399,7 +399,7 @@ def save_caskfile extension = @cask.loaded_from_api? ? "json" : "rb" (metadata_subdir/"#{@cask.token}.#{extension}").write @cask.source - old_savedir&.rmtree + FileUtils.rm_r(old_savedir) if old_savedir end def save_config_file @@ -454,8 +454,8 @@ def backup def restore_backup return if !backup_path.directory? || !backup_metadata_path.directory? - @cask.staged_path.rmtree if @cask.staged_path.exist? - @cask.metadata_versioned_path.rmtree if @cask.metadata_versioned_path.exist? + FileUtils.rm_r(@cask.staged_path) if @cask.staged_path.exist? + FileUtils.rm_r(@cask.metadata_versioned_path) if @cask.metadata_versioned_path.exist? backup_path.rename @cask.staged_path backup_metadata_path.rename @cask.metadata_versioned_path diff --git a/Library/Homebrew/cask/utils.rb b/Library/Homebrew/cask/utils.rb index f401e4a5e3be8..dff67823d8286 100644 --- a/Library/Homebrew/cask/utils.rb +++ b/Library/Homebrew/cask/utils.rb @@ -47,7 +47,7 @@ def self.gain_permissions_remove(path, command: SystemCommand) gain_permissions(path, permission_flags, command) do |p| if p.parent.writable? if directory - p.rmtree + FileUtils.rm_r p else FileUtils.rm_f p end diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 6122abaf45d14..0cda61fb8bb4d 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -372,7 +372,7 @@ def cleanup_logs logs_days = [days, CLEANUP_DEFAULT_DAYS].min HOMEBREW_LOGS.subdirs.each do |dir| - cleanup_path(dir) { dir.rmtree } if self.class.prune?(dir, logs_days) + cleanup_path(dir) { FileUtils.rm_r(dir) } if self.class.prune?(dir, logs_days) end end @@ -518,7 +518,7 @@ def cleanup_portable_ruby end portable_rubies_to_remove.each do |portable_ruby| - cleanup_path(portable_ruby) { portable_ruby.rmtree } + cleanup_path(portable_ruby) { FileUtils.rm_r(portable_ruby) } end end @@ -531,7 +531,7 @@ def cleanup_bootsnap return unless bootsnap.directory? bootsnap.each_child do |subdir| - cleanup_path(subdir) { subdir.rmtree } if subdir.basename.to_s != Homebrew.bootsnap_key + cleanup_path(subdir) { FileUtils.rm_r(subdir) } if subdir.basename.to_s != Homebrew.bootsnap_key end end diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 13bc524901ea3..3d9e6553e1ff6 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -166,11 +166,11 @@ def initialize(cmd = nil, &block) @command_name = T.let(T.must(cmd_location.label).chomp("_args").tr("_", "-"), String) @is_dev_cmd = T.let(T.must(cmd_location.absolute_path).start_with?(Commands::HOMEBREW_DEV_CMD_PATH), T::Boolean) - # odeprecated( - # "`brew #{@command_name}'. This command needs to be refactored, as it is written in a style that", - # "inheritance from `Homebrew::AbstractCommand' ( see https://docs.brew.sh/External-Commands )", - # disable_for_developers: false, - # ) + odeprecated( + "`brew #{@command_name}'. This command needs to be refactored, as it is written in a style that", + "inherits from `Homebrew::AbstractCommand' ( see https://docs.brew.sh/External-Commands )", + disable_for_developers: false, + ) end @constraints = T.let([], T::Array[[String, String]]) diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 46891ec815f57..dd22f475f6ab6 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -432,11 +432,11 @@ def initialize(tap, api_names_txt: nil, api_names_before_txt: nil, api_dir_prefi @api_names_before_txt = api_names_before_txt @api_dir_prefix = api_dir_prefix else - initial_revision_var = "HOMEBREW_UPDATE_BEFORE#{tap.repo_var_suffix}" + initial_revision_var = "HOMEBREW_UPDATE_BEFORE#{tap.repository_var_suffix}" @initial_revision = ENV[initial_revision_var].to_s raise ReporterRevisionUnsetError, initial_revision_var if @initial_revision.empty? - current_revision_var = "HOMEBREW_UPDATE_AFTER#{tap.repo_var_suffix}" + current_revision_var = "HOMEBREW_UPDATE_AFTER#{tap.repository_var_suffix}" @current_revision = ENV[current_revision_var].to_s raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty? end diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index fe3b64b6cbad9..2bf3bb32722a2 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -82,18 +82,18 @@ git_init_if_necessary() { fi } -repo_var_suffix() { - local repo_dir="${1}" - local repo_var_suffix +repository_var_suffix() { + local repository_directory="${1}" + local repository_var_suffix - if [[ "${repo_dir}" == "${HOMEBREW_REPOSITORY}" ]] + if [[ "${repository_directory}" == "${HOMEBREW_REPOSITORY}" ]] then - repo_var_suffix="" + repository_var_suffix="" else - repo_var_suffix="${repo_dir#"${HOMEBREW_LIBRARY}/Taps"}" - repo_var_suffix="$(echo -n "${repo_var_suffix}" | tr -C "A-Za-z0-9" "_" | tr "[:lower:]" "[:upper:]")" + repository_var_suffix="${repository_directory#"${HOMEBREW_LIBRARY}/Taps"}" + repository_var_suffix="$(echo -n "${repository_var_suffix}" | tr -C "A-Za-z0-9" "_" | tr "[:lower:]" "[:upper:]")" fi - echo "${repo_var_suffix}" + echo "${repository_var_suffix}" } upstream_branch() { @@ -592,7 +592,7 @@ EOS echo "Checking if we need to fetch ${DIR}..." fi - TAP_VAR="$(repo_var_suffix "${DIR}")" + TAP_VAR="$(repository_var_suffix "${DIR}")" UPSTREAM_BRANCH_DIR="$(upstream_branch)" declare UPSTREAM_BRANCH"${TAP_VAR}"="${UPSTREAM_BRANCH_DIR}" declare PREFETCH_REVISION"${TAP_VAR}"="$(git rev-parse -q --verify refs/remotes/origin/"${UPSTREAM_BRANCH_DIR}")" @@ -778,7 +778,7 @@ EOS continue fi - TAP_VAR="$(repo_var_suffix "${DIR}")" + TAP_VAR="$(repository_var_suffix "${DIR}")" UPSTREAM_BRANCH_VAR="UPSTREAM_BRANCH${TAP_VAR}" UPSTREAM_BRANCH="${!UPSTREAM_BRANCH_VAR}" CURRENT_REVISION="$(read_current_revision)" diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 54da623d0feb5..c2dfb656f9bb9 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -61,10 +61,6 @@ class UpgradeCmd < AbstractCommand "formula is outdated. Otherwise, the repository's HEAD will only be checked for " \ "updates when a new stable or development version has been released.", }], - [:switch, "--ignore-pinned", { - description: "Set a successful exit status even if pinned formulae are not upgraded.", - hidden: true, - }], [:switch, "--keep-tmp", { description: "Retain the temporary files created during installation.", }], @@ -124,9 +120,6 @@ class UpgradeCmd < AbstractCommand sig { override.void } def run - # Disabled since this is now the default behavior. - odisabled "`brew upgrade --ignore-pinned`" if args.ignore_pinned? - formulae, casks = args.named.to_resolved_formulae_to_casks # If one or more formulae are specified, but no casks were # specified, we want to make note of that so we don't diff --git a/Library/Homebrew/dev-cmd/bump-cask-pr.rb b/Library/Homebrew/dev-cmd/bump-cask-pr.rb index 1f42fda187c9d..52cd7b1ddb576 100644 --- a/Library/Homebrew/dev-cmd/bump-cask-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-cask-pr.rb @@ -27,8 +27,6 @@ class BumpCaskPr < AbstractCommand "to the cask file." switch "--no-audit", description: "Don't run `brew audit` before opening the PR." - switch "--online", - hidden: true switch "--no-style", description: "Don't run `brew style --fix` before opening the PR." switch "--no-browse", @@ -60,8 +58,6 @@ class BumpCaskPr < AbstractCommand sig { override.void } def run - odisabled "brew bump-cask-pr --online" if args.online? - # This will be run by `brew audit` or `brew style` later so run it first to # not start spamming during normal output. gem_groups = [] diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 12a4a636adf23..5f93b441a367f 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -507,10 +507,6 @@ def check_throttle(formula, new_version) return if tap.nil? throttled_rate = formula.livecheck.throttle - throttled_rate ||= if (rate = tap.audit_exceptions.dig(:throttled_formulae, formula.name)) - odisabled "throttled_formulae.json", "Livecheck#throttle" - rate - end return if throttled_rate.blank? formula_suffix = Version.new(new_version).patch.to_i diff --git a/Library/Homebrew/dev-cmd/prof.rb b/Library/Homebrew/dev-cmd/prof.rb index 4965b8d6220ec..f2ec8555b5c38 100644 --- a/Library/Homebrew/dev-cmd/prof.rb +++ b/Library/Homebrew/dev-cmd/prof.rb @@ -41,7 +41,6 @@ def run Homebrew.setup_gem_environment! if args.stackprof? - # odeprecated. vernier is better in every way with_env HOMEBREW_STACKPROF: "1" do system(*HOMEBREW_RUBY_EXEC_ARGS, brew_rb, *args.named) end diff --git a/Library/Homebrew/dev-cmd/tap-new.rb b/Library/Homebrew/dev-cmd/tap-new.rb index aeda5d721cd31..b8356898f10de 100644 --- a/Library/Homebrew/dev-cmd/tap-new.rb +++ b/Library/Homebrew/dev-cmd/tap-new.rb @@ -39,17 +39,17 @@ def run odie "Tap is already installed!" if tap.installed? titleized_user = tap.user.dup - titleized_repo = tap.repo.dup + titleized_repository = tap.repository.dup titleized_user[0] = titleized_user[0].upcase - titleized_repo[0] = titleized_repo[0].upcase - root_url = GitHubPackages.root_url(tap.user, "homebrew-#{tap.repo}") if args.github_packages? + titleized_repository[0] = titleized_repository[0].upcase + root_url = GitHubPackages.root_url(tap.user, "homebrew-#{tap.repository}") if args.github_packages? (tap.path/"Formula").mkpath # FIXME: https://github.com/errata-ai/vale/issues/818 # readme = <<~MARKDOWN - # #{titleized_user} #{titleized_repo} + # #{titleized_user} #{titleized_repository} ## How do I install these formulae? diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index a2507d200a5ee..6b63ac93aee05 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -560,7 +560,7 @@ def check_tap_git_branch def check_deprecated_official_taps tapped_deprecated_taps = - Tap.select(&:official?).map(&:repo) & DEPRECATED_OFFICIAL_TAPS + Tap.select(&:official?).map(&:repository) & DEPRECATED_OFFICIAL_TAPS return if tapped_deprecated_taps.empty? <<~EOS diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 9a895611b8d3c..9f9bb1135f5bf 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -76,13 +76,6 @@ def quiet! @quiet = true end - # Disable any output during downloading. - sig { void } - def shutup! - odisabled "`AbstractDownloadStrategy#shutup!`", "`AbstractDownloadStrategy#quiet!`" - quiet! - end - def quiet? Context.current.quiet? || @quiet end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 7b3158f347e57..baede0cbc3f48 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -218,12 +218,12 @@ def initialize(name, error) # Raised when a formula in a specific tap is unavailable. class TapFormulaUnavailableError < FormulaUnavailableError - attr_reader :tap, :user, :repo + attr_reader :tap, :user, :repository def initialize(tap, name) @tap = tap @user = tap.user - @repo = tap.repo + @repository = tap.repository super "#{tap}/#{name}" end diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index 90481e28bc324..e248325ac0b1c 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -156,7 +156,7 @@ def odeprecated(method, replacement = nil, require "tap" - tap = Tap.fetch(match[:user], match[:repo]) + tap = Tap.fetch(match[:user], match[:repository]) tap_message = +"\nPlease report this issue to the #{tap.full_name} tap" tap_message += " (not Homebrew/brew or Homebrew/homebrew-core)" unless tap.official? tap_message += ", or even better, submit a PR to fix it" if replacement diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 1f8cd606dd87c..0df8d17dd43e1 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -509,7 +509,7 @@ def rmtree(noop: nil, verbose: nil, secure: nil) # create a RuboCop autocorrect instead soon. # This is why monkeypatching is non-ideal (but right solution to get # Ruby 3.3 over the line). - # odeprecated "rmtree", "FileUtils#rm_r" + odeprecated "rmtree", "FileUtils#rm_r" FileUtils.rm_r(@path, noop:, verbose:, secure:) nil end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 48749f0ac3186..74ab4a987bdb0 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1234,7 +1234,7 @@ def with_logging(log_type) # # @see https://www.unix.com/man-page/all/5/plist/ plist(5) man page def plist - odeprecated "`Formula#plist`", "`Homebrew::Service`" + odisabled "`Formula#plist`", "`Homebrew::Service`" nil end @@ -2777,12 +2777,12 @@ def on_system_blocks_exist? ).returns(Pathname) } def fetch(verify_download_integrity: true, timeout: nil, quiet: false) - # odeprecated "Formula#fetch", "Resource#fetch on Formula#resource" + odeprecated "Formula#fetch", "Resource#fetch on Formula#resource" active_spec.fetch(verify_download_integrity:, timeout:, quiet:) end def verify_download_integrity(filename) - # odeprecated "Formula#verify_download_integrity", "Resource#verify_download_integrity on Formula#resource" + odeprecated "Formula#verify_download_integrity", "Resource#verify_download_integrity on Formula#resource" active_spec.verify_download_integrity(filename) end @@ -2887,8 +2887,8 @@ def install; end def inreplace(paths, before = nil, after = nil, old_audit_result = nil, audit_result: true, &block) # NOTE: must check for `#nil?` and not `#blank?`, or else `old_audit_result = false` will not call `odeprecated`. unless old_audit_result.nil? - # odeprecated "inreplace(paths, before, after, #{old_audit_result})", - # "inreplace(paths, before, after, audit_result: #{old_audit_result})" + odeprecated "inreplace(paths, before, after, #{old_audit_result})", + "inreplace(paths, before, after, audit_result: #{old_audit_result})" audit_result = old_audit_result end Utils::Inreplace.inreplace(paths, before, after, audit_result:, &block) @@ -3749,7 +3749,7 @@ def resource(name, klass = Resource, &block) # # @api public def go_resource(name, &block) - odeprecated "`Formula.go_resource`", "Go modules" + odisabled "`Formula.go_resource`", "Go modules" specs.each { |spec| spec.go_resource(name, &block) } end diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index c19909e2f9199..db48a0ec3ebf4 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -948,7 +948,7 @@ def audit_reverse_migration problem <<~EOS #{formula.name} seems to be listed in tap_migrations.json! Please remove #{formula.name} from present tap & tap_migrations.json - before submitting it to Homebrew/homebrew-#{formula.tap.repo}. + before submitting it to Homebrew/homebrew-#{formula.tap.repository}. EOS end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 587e3b70cf571..e09a55a8694a9 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -483,7 +483,7 @@ def install # any exceptions must leave us with nothing installed ignore_interrupts do begin - formula.prefix.rmtree if formula.prefix.directory? + FileUtils.rm_r(formula.prefix) if formula.prefix.directory? rescue Errno::EACCES, Errno::ENOTEMPTY odie <<~EOS Could not remove #{formula.prefix.basename} keg! Do so manually: @@ -825,7 +825,7 @@ def install_dependency(dep, inherited_options) # dependency tree. In that case, don't generate an error, just move on. nil else - ignore_interrupts { tmp_keg.rmtree if tmp_keg&.directory? } + ignore_interrupts { FileUtils.rm_r(tmp_keg) if tmp_keg&.directory? } end sig { void } @@ -1020,7 +1020,7 @@ def build ignore_interrupts do # any exceptions must leave us with nothing installed formula.update_head_version - formula.prefix.rmtree if formula.prefix.directory? + FileUtils.rm_r(formula.prefix) if formula.prefix.directory? formula.rack.rmdir_if_possible end raise e diff --git a/Library/Homebrew/git_repository.rb b/Library/Homebrew/git_repository.rb index c8c36e36c2ac8..f8d1dfc79d440 100644 --- a/Library/Homebrew/git_repository.rb +++ b/Library/Homebrew/git_repository.rb @@ -19,8 +19,13 @@ def initialize(pathname) def git_repository? pathname.join(".git").exist? end - # odeprecated: use git_repository? instead - alias git_repo? git_repository? + + sig { returns(T::Boolean) } + def git_repo? + # delete this whole function when removing odisabled + odeprecated "GitRepository#git_repo?", "GitRepository#git_repository?" + git_repository? + end # Gets the URL of the Git origin remote. sig { returns(T.nilable(String)) } @@ -31,7 +36,7 @@ def origin_url # Sets the URL of the Git origin remote. sig { params(origin: String).returns(T.nilable(T::Boolean)) } def origin_url=(origin) - return if !git_repo? || !Utils::Git.available? + return if !git_repository? || !Utils::Git.available? safe_system Utils::Git.git, "remote", "set-url", "origin", origin, chdir: pathname end @@ -115,7 +120,7 @@ def to_s = pathname.to_s sig { params(args: T.untyped, safe: T::Boolean, err: T.nilable(Symbol)).returns(T.nilable(String)) } def popen_git(*args, safe: false, err: nil) - unless git_repo? + unless git_repository? return unless safe raise "Not a Git repository: #{pathname}" diff --git a/Library/Homebrew/github_packages.rb b/Library/Homebrew/github_packages.rb index 3af412251552c..a3cde6b1ec6db 100644 --- a/Library/Homebrew/github_packages.rb +++ b/Library/Homebrew/github_packages.rb @@ -123,11 +123,11 @@ def self.image_formula_name(formula_name) end def self.image_version_rebuild(version_rebuild) - return version_rebuild if version_rebuild.match?(VALID_OCI_TAG_REGEX) + unless version_rebuild.match?(VALID_OCI_TAG_REGEX) + raise ArgumentError, "GitHub Packages versions must match #{VALID_OCI_TAG_REGEX.source}!" + end - odisabled "GitHub Packages versions that do not match #{VALID_OCI_TAG_REGEX.source}", - "declaring a new `version` without these characters" - version_rebuild.gsub(INVALID_OCI_TAG_CHARS_REGEX, ".") + version_rebuild end private diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index d327846e13fd7..8cbe45ec603ce 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -268,7 +268,7 @@ def uninstall(raise_failures: false) LinkageCacheStore.new(path, db).delete! end - path.rmtree + FileUtils.rm_r(path) path.parent.rmdir_if_possible remove_opt_record if optlinked? remove_linked_keg_record if linked? diff --git a/Library/Homebrew/language/go.rb b/Library/Homebrew/language/go.rb index 6118ffc5bb312..2dc65920e5de4 100644 --- a/Library/Homebrew/language/go.rb +++ b/Library/Homebrew/language/go.rb @@ -14,7 +14,7 @@ module Go # e.g. `resource "github.com/foo/bar"`. sig { params(resources: T::Array[Resource], target: T.any(String, Pathname)).void } def self.stage_deps(resources, target) - odeprecated "`Language::Go.stage_deps`", "Go modules" + odisabled "`Language::Go.stage_deps`", "Go modules" if resources.empty? if Homebrew::EnvConfig.developer? odie "Tried to stage empty Language::Go resources array" diff --git a/Library/Homebrew/os/linux.rb b/Library/Homebrew/os/linux.rb index 7f5c32d85a15d..a70e9e70460a6 100644 --- a/Library/Homebrew/os/linux.rb +++ b/Library/Homebrew/os/linux.rb @@ -6,6 +6,13 @@ module OS # Helper module for querying system information on Linux. module Linux + raise "Loaded OS::Linux on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"] + + # This check is the only acceptable or necessary one in this file. + # rubocop:disable Homebrew/MoveToExtendOS + raise "Loaded OS::Linux on macOS!" if OS.mac? + # rubocop:enable Homebrew/MoveToExtendOS + # Get the OS version. # # @api internal @@ -50,71 +57,4 @@ def self.wsl_version end end end - - # rubocop:disable Style/Documentation - module Mac - ::MacOS = OS::Mac - - raise "Loaded OS::Linux on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"] - - def self.version - odisabled "`MacOS.version` on Linux" - MacOSVersion::NULL - end - - def self.full_version - odisabled "`MacOS.full_version` on Linux" - MacOSVersion::NULL - end - - def self.languages - odisabled "`MacOS.languages` on Linux" - @languages ||= Array(ENV["LANG"]&.slice(/[a-z]+/)).uniq - end - - def self.language - odisabled "`MacOS.language` on Linux" - languages.first - end - - def self.sdk_root_needed? - odisabled "`MacOS.sdk_root_needed?` on Linux" - false - end - - def self.sdk_path_if_needed(_version = nil) - odisabled "`MacOS.sdk_path_if_needed` on Linux" - nil - end - - def self.sdk_path(_version = nil) - odisabled "`MacOS.sdk_path` on Linux" - nil - end - - module Xcode - def self.version - odisabled "`MacOS::Xcode.version` on Linux" - ::Version::NULL - end - - def self.installed? - odisabled "`MacOS::Xcode.installed?` on Linux" - false - end - end - - module CLT - def self.version - odisabled "`MacOS::CLT.version` on Linux" - ::Version::NULL - end - - def self.installed? - odisabled "`MacOS::CLT.installed?` on Linux" - false - end - end - end - # rubocop:enable Style/Documentation end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 3a65aeab2f744..c017622bc82b3 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -7,16 +7,19 @@ require "os/mac/sdk" require "os/mac/keg" -# TODO: remove this once the `MacOS` module is undefined on Linux -require "simulate_system" - module OS # Helper module for querying system information on macOS. module Mac - ::MacOS = OS::Mac - raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"] + # This check is the only acceptable or necessary one in this file. + # rubocop:disable Homebrew/MoveToExtendOS + raise "Loaded OS::Mac on Linux!" if OS.linux? + # rubocop:enable Homebrew/MoveToExtendOS + + # Provide MacOS alias for backwards compatibility and nicer APIs. + ::MacOS = OS::Mac + VERSION = ENV.fetch("HOMEBREW_MACOS_VERSION").chomp.freeze private_constant :VERSION @@ -35,7 +38,6 @@ def self.version # @api internal sig { returns(MacOSVersion) } def self.full_version - odisabled "`MacOS.full_version` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? @full_version ||= if (fake_macos = ENV.fetch("HOMEBREW_FAKE_MACOS", nil)) # for Portable Ruby building MacOSVersion.new(fake_macos) else @@ -68,7 +70,6 @@ def self.preferred_perl_version end def self.languages - odisabled "`MacOS.languages` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? return @languages if @languages os_langs = Utils.popen_read("defaults", "read", "-g", "AppleLanguages") @@ -82,7 +83,6 @@ def self.languages end def self.language - odisabled "`MacOS.language` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? languages.first end @@ -93,7 +93,6 @@ def self.active_developer_dir sig { returns(T::Boolean) } def self.sdk_root_needed? - odisabled "`MacOS.sdk_root_needed?` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? if MacOS::CLT.installed? # If there's no CLT SDK, return false return false unless MacOS::CLT.provides_sdk? @@ -142,13 +141,11 @@ def self.sdk_for_formula(formula, version = nil, check_only_runtime_requirements # Returns the path to an SDK or nil, following the rules set by {sdk}. def self.sdk_path(version = nil) - odisabled "`MacOS.sdk_path` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? s = sdk(version) s&.path end def self.sdk_path_if_needed(version = nil) - odisabled "`MacOS.sdk_path_if_needed` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? # Prefer CLT SDK when both Xcode and the CLT are installed. # Expected results: # 1. On Xcode-only systems, return the Xcode SDK. diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 1372a03ec6099..40e6c870be877 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -126,7 +126,6 @@ def self.bundle_path sig { returns(T::Boolean) } def self.installed? - odisabled "`MacOS::Xcode.installed?` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? !prefix.nil? end @@ -178,7 +177,6 @@ def self.update_instructions # @api internal sig { returns(::Version) } def self.version - odisabled "`MacOS::Xcode.version` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? # may return a version string # that is guessed based on the compiler, so do not # use it in order to check if Xcode is installed. @@ -278,7 +276,6 @@ module CLT # Returns true even if outdated tools are installed. sig { returns(T::Boolean) } def self.installed? - odisabled "`MacOS::CLT.installed?` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? !version.null? end @@ -423,7 +420,6 @@ def self.detect_version_from_clang_version # @api internal sig { returns(::Version) } def self.version - odisabled "`MacOS::CLT.version` on Linux" if Homebrew::SimulateSystem.simulating_or_running_on_linux? if @version ||= detect_version ::Version.new @version else diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index 3c21f7b2998f4..6e5ba2613144e 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -69,7 +69,7 @@ def self.reinstall_formula( raise else begin - backup_path(keg).rmtree if backup_path(keg).exist? + FileUtils.rm_r(backup_path(keg)) if backup_path(keg).exist? rescue Errno::EACCES, Errno::ENOTEMPTY odie <<~EOS Could not remove #{backup_path(keg).parent.basename} backup keg! Do so manually: @@ -96,7 +96,7 @@ def self.restore_backup(keg, keg_was_linked, verbose:) return unless path.directory? - Pathname.new(keg).rmtree if keg.exist? + FileUtils.rm_r(Pathname.new(keg)) if keg.exist? path.rename keg keg.link(verbose:) if keg_was_linked diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 5c4bd6f911c49..45106519bf474 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -154,7 +154,7 @@ def resource(name = T.unsafe(nil), klass = Resource, &block) end def go_resource(name, &block) - odeprecated "`SoftwareSpec#go_resource`", "Go modules" + odisabled "`SoftwareSpec#go_resource`", "Go modules" resource name, Resource::Go, &block end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index dd78d0a97c3a5..88c3e18552c22 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -49,26 +49,26 @@ class InvalidNameError < ArgumentError; end # Fetch a {Tap} by name. # # @api public - sig { params(user: String, repo: String).returns(Tap) } - def self.fetch(user, repo = T.unsafe(nil)) - user, repo = user.split("/", 2) if repo.nil? + sig { params(user: String, repository: String).returns(Tap) } + def self.fetch(user, repository = T.unsafe(nil)) + user, repository = user.split("/", 2) if repository.nil? - if [user, repo].any? { |part| part.nil? || part.include?("/") } - raise InvalidNameError, "Invalid tap name: '#{[*user, *repo].join("/")}'" + if [user, repository].any? { |part| part.nil? || part.include?("/") } + raise InvalidNameError, "Invalid tap name: '#{[*user, *repository].join("/")}'" end user = T.must(user) - repo = T.must(repo) + repository = T.must(repository) # We special case homebrew and linuxbrew so that users don't have to shift in a terminal. user = user.capitalize if ["homebrew", "linuxbrew"].include?(user) - repo = repo.sub(HOMEBREW_OFFICIAL_REPO_PREFIXES_REGEX, "") + repository = repository.sub(HOMEBREW_OFFICIAL_REPO_PREFIXES_REGEX, "") - return CoreTap.instance if ["Homebrew", "Linuxbrew"].include?(user) && ["core", "homebrew"].include?(repo) - return CoreCaskTap.instance if user == "Homebrew" && repo == "cask" + return CoreTap.instance if ["Homebrew", "Linuxbrew"].include?(user) && ["core", "homebrew"].include?(repository) + return CoreCaskTap.instance if user == "Homebrew" && repository == "cask" - cache_key = "#{user}/#{repo}".downcase - cache.fetch(cache_key) { |key| cache[key] = new(user, repo) } + cache_key = "#{user}/#{repository}".downcase + cache.fetch(cache_key) { |key| cache[key] = new(user, repository) } end # Get a {Tap} from its path or a path inside of it. @@ -79,9 +79,9 @@ def self.from_path(path) return unless match return unless (user = match[:user]) - return unless (repo = match[:repo]) + return unless (repository = match[:repository]) - fetch(user, repo) + fetch(user, repository) end sig { params(name: String).returns(T.nilable([Tap, String])) } @@ -89,13 +89,13 @@ def self.with_formula_name(name) return unless (match = name.match(HOMEBREW_TAP_FORMULA_REGEX)) user = T.must(match[:user]) - repo = T.must(match[:repo]) + repository = T.must(match[:repository]) name = T.must(match[:name]) # Relative paths are not taps. - return if [user, repo].intersect?([".", ".."]) + return if [user, repository].intersect?([".", ".."]) - tap = fetch(user, repo) + tap = fetch(user, repository) [tap, name.downcase] end @@ -104,13 +104,13 @@ def self.with_cask_token(token) return unless (match = token.match(HOMEBREW_TAP_CASK_REGEX)) user = T.must(match[:user]) - repo = T.must(match[:repo]) + repository = T.must(match[:repository]) token = T.must(match[:token]) # Relative paths are not taps. - return if [user, repo].intersect?([".", ".."]) + return if [user, repository].intersect?([".", ".."]) - tap = fetch(user, repo) + tap = fetch(user, repository) [tap, token.downcase] end @@ -157,8 +157,14 @@ def self.forbidden_taps # # @api public attr_reader :repository - # odeprecated: use repository instead. - alias repo repository + + # @deprecated + sig { returns(T::Boolean) } + def repo + # delete this whole function when removing odisabled + odeprecated "Tap#repo", "Tap#repository" + repository + end # The name of this {Tap}. It combines {#user} and {#repository} with a slash. # {#name} is always in lowercase. @@ -267,12 +273,20 @@ def remote # # @api public sig { returns(T.nilable(String)) } - def remote_repo + def remote_repository return unless (remote = self.remote) - @remote_repo ||= remote.delete_prefix("https://github.com/") - .delete_prefix("git@github.com:") - .delete_suffix(".git") + @remote_repository ||= remote.delete_prefix("https://github.com/") + .delete_prefix("git@github.com:") + .delete_suffix(".git") + end + + # @deprecated + sig { returns(T.nilable(String)) } + def remote_repo + # delete this whole function when removing odisabled + odeprecated "Tap#remote_repo", "Tap#remote_repository" + remote_repository end # The default remote path to this {Tap}. @@ -288,8 +302,14 @@ def repository_var_suffix .tr("^A-Za-z0-9", "_") .upcase end - # odeprecated: use repository_var_suffix instead. - alias repo_var_suffix repository_var_suffix + + # @deprecated + sig { returns(String) } + def repo_var_suffix + # delete this whole function when removing odisabled + odeprecated "Tap#repo_var_suffix", "Tap#repository_var_suffix" + repository_var_suffix + end # Check whether this {Tap} is a Git repository. # @@ -326,7 +346,7 @@ def git_last_commit end # The issues URL of this {Tap}. - # e.g. `https://github.com/user/homebrew-repo/issues` + # e.g. `https://github.com/user/homebrew-repository/issues` # # @api public sig { returns(T.nilable(String)) } @@ -417,11 +437,11 @@ def install(quiet: false, clone_target: nil, require "descriptions" require "readall" - if official? && DEPRECATED_OFFICIAL_TAPS.include?(repo) + if official? && DEPRECATED_OFFICIAL_TAPS.include?(repository) odie "#{name} was deprecated. This tap is now empty and all its contents were either deleted or migrated." elsif user == "caskroom" || name == "phinze/cask" - new_repo = (repo == "cask") ? "cask" : "cask-#{repo}" - odie "#{name} was moved. Tap homebrew/#{new_repo} instead." + new_repository = (repository == "cask") ? "cask" : "cask-#{repository}" + odie "#{name} was moved. Tap homebrew/#{new_repository} instead." end raise TapNoCustomRemoteError, name if custom_remote && clone_target.nil? @@ -618,7 +638,7 @@ def uninstall(manual: false) require "utils/link" Utils::Link.unlink_manpages(path) Utils::Link.unlink_completions(path) - path.rmtree + FileUtils.rm_r(path) path.parent.rmdir_if_possible $stderr.puts "Untapped#{formatted_contents} (#{abv})." @@ -866,7 +886,7 @@ def to_hash hash = { "name" => name, "user" => user, - "repo" => repo, + "repository" => repository, "path" => path.to_s, "installed" => installed?, "official" => official?, @@ -1059,7 +1079,7 @@ def self.each(&block) # An array of all installed {Tap} names. sig { returns(T::Array[String]) } def self.names - odeprecated "`#{self}.names`" + odisabled "`#{self}.names`" map(&:name).sort end @@ -1165,7 +1185,7 @@ def ensure_installed! sig { void } def self.ensure_installed! - odeprecated "`#{self}.ensure_installed!`", "`#{self}.instance.ensure_installed!`" + odisabled "`#{self}.ensure_installed!`", "`#{self}.instance.ensure_installed!`" instance.ensure_installed! end @@ -1234,7 +1254,7 @@ def core_tap? sig { returns(T::Boolean) } def linuxbrew_core? - remote_repo.to_s.end_with?("/linuxbrew-core") || remote_repo == "Linuxbrew/homebrew-core" + remote_repository.to_s.end_with?("/linuxbrew-core") || remote_repository == "Linuxbrew/homebrew-core" end sig { returns(Pathname) } diff --git a/Library/Homebrew/tap_constants.rb b/Library/Homebrew/tap_constants.rb index f8a9d7f6dd8f4..fe2d73e7ef998 100644 --- a/Library/Homebrew/tap_constants.rb +++ b/Library/Homebrew/tap_constants.rb @@ -5,7 +5,7 @@ HOMEBREW_TAP_FORMULA_NAME_REGEX = T.let(/(?[\w+\-.@]+)/, Regexp) # Match taps' formulae, e.g. `someuser/sometap/someformula`. HOMEBREW_TAP_FORMULA_REGEX = T.let( - %r{\A(?[^/]+)/(?[^/]+)/#{HOMEBREW_TAP_FORMULA_NAME_REGEX.source}\Z}, + %r{\A(?[^/]+)/(?[^/]+)/#{HOMEBREW_TAP_FORMULA_NAME_REGEX.source}\Z}, Regexp, ) # Match default formula taps' formulae, e.g. `homebrew/core/someformula` or `someformula`. @@ -18,7 +18,7 @@ HOMEBREW_TAP_CASK_TOKEN_REGEX = T.let(/(?[\w+\-.@]+)/, Regexp) # Match taps' casks, e.g. `someuser/sometap/somecask`. HOMEBREW_TAP_CASK_REGEX = T.let( - %r{\A(?[^/]+)/(?[^/]+)/#{HOMEBREW_TAP_CASK_TOKEN_REGEX.source}\Z}, + %r{\A(?[^/]+)/(?[^/]+)/#{HOMEBREW_TAP_CASK_TOKEN_REGEX.source}\Z}, Regexp, ) # Match default cask taps' casks, e.g. `homebrew/cask/somecask` or `somecask`. @@ -29,7 +29,7 @@ # Match taps' directory paths, e.g. `HOMEBREW_LIBRARY/Taps/someuser/sometap`. HOMEBREW_TAP_DIR_REGEX = T.let( - %r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/(?[^/]+)/(?[^/]+)}, + %r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/(?[^/]+)/(?[^/]+)}, Regexp, ) # Match taps' formula paths, e.g. `HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula`. diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index 95cc8d9a8b446..72f644cd45be1 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -239,7 +239,7 @@ end it "gives a warning if the source doesn't exist" do - source_path.rmtree + FileUtils.rm_r(source_path) message = "It seems the App source '#{source_path}' is not there." diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index b81cdd2f8757b..2f407fc79a616 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -386,7 +386,7 @@ class #{Formulary.class_s(dep_name)} < Formula described_class.new(cask).forbidden_tap_check end.to raise_error(Cask::CaskCannotBeInstalledError, /from the #{dep_tap} tap but/) ensure - dep_path.parent.parent.rmtree + FileUtils.rm_r(dep_path.parent.parent) end end diff --git a/Library/Homebrew/test/cask/uninstall_spec.rb b/Library/Homebrew/test/cask/uninstall_spec.rb index 6fdf8b589871c..0bf718e1f2025 100644 --- a/Library/Homebrew/test/cask/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/uninstall_spec.rb @@ -60,7 +60,7 @@ expect(cask).to be_installed - cask.config.appdir.join("MyFancyApp.app").rmtree + FileUtils.rm_r(cask.config.appdir.join("MyFancyApp.app")) expect { described_class.uninstall_casks(cask) } .to raise_error(Cask::CaskError, /uninstall script .* does not exist/) diff --git a/Library/Homebrew/test/cmd/reinstall_spec.rb b/Library/Homebrew/test/cmd/reinstall_spec.rb index 2657b8eb62188..fd5690de263fa 100644 --- a/Library/Homebrew/test/cmd/reinstall_spec.rb +++ b/Library/Homebrew/test/cmd/reinstall_spec.rb @@ -11,7 +11,7 @@ install_test_formula "testball" foo_dir = HOMEBREW_CELLAR/"testball/0.1/bin" expect(foo_dir).to exist - foo_dir.rmtree + FileUtils.rm_r(foo_dir) expect { brew "reinstall", "testball" } .to output(/Reinstalling testball/).to_stdout diff --git a/Library/Homebrew/test/cmd/update-report_spec.rb b/Library/Homebrew/test/cmd/update-report_spec.rb index bb7844084d17c..7f36c0d0e5b6f 100644 --- a/Library/Homebrew/test/cmd/update-report_spec.rb +++ b/Library/Homebrew/test/cmd/update-report_spec.rb @@ -15,8 +15,8 @@ def initialize(tap) @tap = tap - ENV["HOMEBREW_UPDATE_BEFORE#{tap.repo_var_suffix}"] = "12345678" - ENV["HOMEBREW_UPDATE_AFTER#{tap.repo_var_suffix}"] = "abcdef00" + ENV["HOMEBREW_UPDATE_BEFORE#{tap.repository_var_suffix}"] = "12345678" + ENV["HOMEBREW_UPDATE_AFTER#{tap.repository_var_suffix}"] = "abcdef00" super end @@ -94,7 +94,7 @@ def perform_update(fixture_name = "") end after do - tap.path.parent.rmtree + FileUtils.rm_r(tap.path.parent) end specify "with restructured Tap" do diff --git a/Library/Homebrew/test/diagnostic_checks_spec.rb b/Library/Homebrew/test/diagnostic_checks_spec.rb index f5fc3b0dc71e0..3e1d9c05639b3 100644 --- a/Library/Homebrew/test/diagnostic_checks_spec.rb +++ b/Library/Homebrew/test/diagnostic_checks_spec.rb @@ -71,11 +71,11 @@ expect(checks.check_user_path_3) .to match("Homebrew's \"sbin\" was not found in your PATH") ensure - sbin.rmtree + FileUtils.rm_rf(sbin) end specify "#check_for_symlinked_cellar" do - HOMEBREW_CELLAR.rmtree + FileUtils.rm_r(HOMEBREW_CELLAR) mktmpdir do |path| FileUtils.ln_s path, HOMEBREW_CELLAR diff --git a/Library/Homebrew/test/exceptions_spec.rb b/Library/Homebrew/test/exceptions_spec.rb index 1ad4c18ab5cac..27d03c3239035 100644 --- a/Library/Homebrew/test/exceptions_spec.rb +++ b/Library/Homebrew/test/exceptions_spec.rb @@ -46,7 +46,7 @@ describe TapFormulaOrCaskUnavailableError do subject(:error) { described_class.new(tap, "foo") } - let(:tap) { instance_double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) } + let(:tap) { instance_double(Tap, user: "u", repository: "r", to_s: "u/r", installed?: false) } it(:to_s) { expect(error.to_s).to match(%r{Please tap it and then try again: brew tap u/r}) } end @@ -88,7 +88,7 @@ describe TapFormulaUnavailableError do subject(:error) { described_class.new(tap, "foo") } - let(:tap) { instance_double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) } + let(:tap) { instance_double(Tap, user: "u", repository: "r", to_s: "u/r", installed?: false) } it(:to_s) { expect(error.to_s).to match(%r{Please tap it and then try again: brew tap u/r}) } end diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index d4b6284b3d1b7..d0b079efcfa9b 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -39,7 +39,7 @@ def temporary_install(formula, **options) keg.uninstall formula.clear_cache # there will be log files when sandbox is enable. - formula.logs.rmtree if formula.logs.directory? + FileUtils.rm_r(formula.logs) if formula.logs.directory? end expect(keg).not_to exist @@ -288,7 +288,7 @@ class #{Formulary.class_s(f_name)} < Formula fi.forbidden_tap_check end.to raise_error(CannotInstallFormulaError, /has the tap #{f_tap}/) ensure - f_path.parent.parent.rmtree + FileUtils.rm_r(f_path.parent.parent) end it "raises on not allowed third-party tap on formula" do @@ -311,7 +311,7 @@ class #{Formulary.class_s(f_name)} < Formula fi.forbidden_tap_check end.to raise_error(CannotInstallFormulaError, /has the tap #{f_tap}/) ensure - f_path.parent.parent.parent.rmtree + FileUtils.rm_r(f_path.parent.parent.parent) end it "does not raise on allowed tap on formula" do @@ -332,7 +332,7 @@ class #{Formulary.class_s(f_name)} < Formula expect { fi.forbidden_tap_check }.not_to raise_error ensure - f_path.parent.parent.parent.rmtree + FileUtils.rm_r(f_path.parent.parent.parent) end it "raises on forbidden tap on dependency" do @@ -366,7 +366,7 @@ class #{Formulary.class_s(f_name)} < Formula fi.forbidden_tap_check end.to raise_error(CannotInstallFormulaError, /from the #{dep_tap} tap but/) ensure - dep_path.parent.parent.rmtree + FileUtils.rm_r(dep_path.parent.parent) end end diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index bb1b9fd5c8e6d..7346b11226d40 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -63,8 +63,8 @@ context "when in a Tap" do let(:tap) { Tap.fetch("foo", "bar") } let(:path) { (tap.path/"Formula/#{name}.rb") } - let(:full_name) { "#{tap.user}/#{tap.repo}/#{name}" } - let(:full_alias_name) { "#{tap.user}/#{tap.repo}/#{alias_name}" } + let(:full_name) { "#{tap.user}/#{tap.repository}/#{name}" } + let(:full_alias_name) { "#{tap.user}/#{tap.repository}/#{alias_name}" } specify "formula instantiation" do expect(f.name).to eq(name) @@ -228,7 +228,7 @@ alias_name = "bar" alias_path = tap.alias_dir/alias_name - full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}" + full_alias_name = "#{tap.user}/#{tap.repository}/#{alias_name}" tap.alias_dir.mkpath FileUtils.ln_sf f.path, alias_path @@ -1545,7 +1545,7 @@ def setup_tab_for_prefix(prefix, options = {}) described_class.clear_cache expect(f.outdated_kegs(fetch_head: true)).not_to be_empty - head_prefix_a.rmtree + FileUtils.rm_r(head_prefix_a) described_class.clear_cache expect(f.outdated_kegs(fetch_head: true)).not_to be_empty @@ -1553,7 +1553,7 @@ def setup_tab_for_prefix(prefix, options = {}) described_class.clear_cache expect(f.outdated_kegs(fetch_head: true)).to be_empty ensure - testball_repo.rmtree if testball_repo.exist? + FileUtils.rm_r(testball_repo) if testball_repo.exist? end end @@ -1632,7 +1632,7 @@ def setup_tab_for_prefix(prefix, options = {}) expect(f.outdated_kegs).not_to be_empty described_class.clear_cache - head_prefix.rmtree + FileUtils.rm_r(head_prefix) setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 2 }) expect(f.outdated_kegs).to be_empty diff --git a/Library/Homebrew/test/keg_spec.rb b/Library/Homebrew/test/keg_spec.rb index d7f6d804b66f7..ffac76b7f0961 100644 --- a/Library/Homebrew/test/keg_spec.rb +++ b/Library/Homebrew/test/keg_spec.rb @@ -47,7 +47,7 @@ def setup_test_keg(name, version) expect(keg).to be_a_directory expect(keg).not_to be_an_empty_installation - (keg/"bin").rmtree + FileUtils.rm_r(keg/"bin") expect(keg).to be_an_empty_installation (keg/"bin").mkpath diff --git a/Library/Homebrew/test/migrator_spec.rb b/Library/Homebrew/test/migrator_spec.rb index 8a1608f88d596..e84ca5fe7c4a7 100644 --- a/Library/Homebrew/test/migrator_spec.rb +++ b/Library/Homebrew/test/migrator_spec.rb @@ -87,7 +87,7 @@ end specify "#backup_oldname_cellar" do - old_keg_record.parent.rmtree + FileUtils.rm_r(old_keg_record.parent) (new_keg_record/"bin").mkpath migrator.backup_oldname_cellar diff --git a/Library/Homebrew/test/tap_spec.rb b/Library/Homebrew/test/tap_spec.rb index a455b15cd74de..9c969e44b7be3 100644 --- a/Library/Homebrew/test/tap_spec.rb +++ b/Library/Homebrew/test/tap_spec.rb @@ -163,7 +163,7 @@ def setup_completion(link:) specify "attributes" do expect(homebrew_foo_tap.user).to eq("Homebrew") - expect(homebrew_foo_tap.repo).to eq("foo") + expect(homebrew_foo_tap.repository).to eq("foo") expect(homebrew_foo_tap.name).to eq("homebrew/foo") expect(homebrew_foo_tap.path).to eq(path) expect(homebrew_foo_tap).to be_installed @@ -186,7 +186,7 @@ def setup_completion(link:) (HOMEBREW_TAP_DIRECTORY/"someone/homebrew-no-git").mkpath expect(described_class.fetch("someone", "no-git").issues_url).to be_nil ensure - path.parent.rmtree + FileUtils.rm_rf(path.parent) end specify "files" do @@ -238,7 +238,7 @@ def setup_completion(link:) it "returns the remote https repository" do setup_git_repo - expect(homebrew_foo_tap.remote_repo).to eq("Homebrew/homebrew-foo") + expect(homebrew_foo_tap.remote_repository).to eq("Homebrew/homebrew-foo") services_tap = described_class.fetch("Homebrew", "services") services_tap.path.mkpath @@ -246,13 +246,13 @@ def setup_completion(link:) system "git", "init" system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-bar" end - expect(services_tap.remote_repo).to eq("Homebrew/homebrew-bar") + expect(services_tap.remote_repository).to eq("Homebrew/homebrew-bar") end it "returns the remote ssh repository" do setup_git_repo - expect(homebrew_foo_tap.remote_repo).to eq("Homebrew/homebrew-foo") + expect(homebrew_foo_tap.remote_repository).to eq("Homebrew/homebrew-foo") services_tap = described_class.fetch("Homebrew", "services") services_tap.path.mkpath @@ -260,17 +260,17 @@ def setup_completion(link:) system "git", "init" system "git", "remote", "add", "origin", "git@github.com:Homebrew/homebrew-bar" end - expect(services_tap.remote_repo).to eq("Homebrew/homebrew-bar") + expect(services_tap.remote_repository).to eq("Homebrew/homebrew-bar") end it "returns nil if the Tap is not a Git repository" do - expect(homebrew_foo_tap.remote_repo).to be_nil + expect(homebrew_foo_tap.remote_repository).to be_nil end it "returns nil if Git is not available" do setup_git_repo allow(Utils::Git).to receive(:available?).and_return(false) - expect(homebrew_foo_tap.remote_repo).to be_nil + expect(homebrew_foo_tap.remote_repository).to be_nil end end @@ -412,8 +412,8 @@ def setup_completion(link:) expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").not_to exist expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").not_to exist ensure - (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist? - (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? + FileUtils.rm_r(HOMEBREW_PREFIX/"etc") if (HOMEBREW_PREFIX/"etc").exist? + FileUtils.rm_r(HOMEBREW_PREFIX/"share") if (HOMEBREW_PREFIX/"share").exist? end specify "#link_completions_and_manpages when completions are enabled for non-official tap" do @@ -433,8 +433,8 @@ def setup_completion(link:) expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file tap.uninstall ensure - (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist? - (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? + FileUtils.rm_r(HOMEBREW_PREFIX/"etc") if (HOMEBREW_PREFIX/"etc").exist? + FileUtils.rm_r(HOMEBREW_PREFIX/"share") if (HOMEBREW_PREFIX/"share").exist? end specify "#link_completions_and_manpages when completions are disabled for non-official tap" do @@ -451,8 +451,8 @@ def setup_completion(link:) expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").not_to be_a_file tap.uninstall ensure - (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist? - (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? + FileUtils.rm_r(HOMEBREW_PREFIX/"etc") if (HOMEBREW_PREFIX/"etc").exist? + FileUtils.rm_r(HOMEBREW_PREFIX/"share") if (HOMEBREW_PREFIX/"share").exist? end specify "#link_completions_and_manpages when completions are enabled for official tap" do @@ -472,8 +472,8 @@ def setup_completion(link:) expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file tap.uninstall ensure - (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist? - (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? + FileUtils.rm_r(HOMEBREW_PREFIX/"etc") if (HOMEBREW_PREFIX/"etc").exist? + FileUtils.rm_r(HOMEBREW_PREFIX/"share") if (HOMEBREW_PREFIX/"share").exist? end specify "#config" do @@ -736,7 +736,7 @@ def setup_completion(link:) specify "attributes" do expect(core_tap.user).to eq("Homebrew") - expect(core_tap.repo).to eq("core") + expect(core_tap.repository).to eq("core") expect(core_tap.name).to eq("homebrew/core") expect(core_tap.command_files).to eq([]) expect(core_tap).to be_installed @@ -790,14 +790,16 @@ class Foo < Formula end end - describe "#repo_var_suffix" do + describe "#repository_var_suffix" do it "converts the repo directory to an environment variable suffix" do - expect(CoreTap.instance.repo_var_suffix).to eq "_HOMEBREW_HOMEBREW_CORE" + expect(CoreTap.instance.repository_var_suffix).to eq "_HOMEBREW_HOMEBREW_CORE" end it "converts non-alphanumeric characters to underscores" do - expect(described_class.fetch("my", "tap-with-dashes").repo_var_suffix).to eq "_MY_HOMEBREW_TAP_WITH_DASHES" - expect(described_class.fetch("my", "tap-with-@-symbol").repo_var_suffix).to eq "_MY_HOMEBREW_TAP_WITH___SYMBOL" + expect(described_class.fetch("my", + "tap-with-dashes").repository_var_suffix).to eq "_MY_HOMEBREW_TAP_WITH_DASHES" + expect(described_class.fetch("my", + "tap-with-@-symbol").repository_var_suffix).to eq "_MY_HOMEBREW_TAP_WITH___SYMBOL" end end diff --git a/Library/Homebrew/unpack_strategy/bazaar.rb b/Library/Homebrew/unpack_strategy/bazaar.rb index 770cca92aad86..c237507ad93ce 100644 --- a/Library/Homebrew/unpack_strategy/bazaar.rb +++ b/Library/Homebrew/unpack_strategy/bazaar.rb @@ -18,7 +18,7 @@ def extract_to_dir(unpack_dir, basename:, verbose:) super # The export command doesn't work on checkouts (see https://bugs.launchpad.net/bzr/+bug/897511). - (unpack_dir/".bzr").rmtree + FileUtils.rm_r(unpack_dir/".bzr") end end end diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 24beae198bbff..a7e3e9bddf6ff 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -68,7 +68,7 @@ def self.inreplace(paths, before = nil, after = nil, audit_result: true, &block) yield s else - s.gsub!(T.must(before), T.must(after), audit_result) + s.gsub!(T.must(before), T.must(after), audit_result:) end errors[path] = s.errors unless s.errors.empty? diff --git a/Library/Homebrew/utils/string_inreplace_extension.rb b/Library/Homebrew/utils/string_inreplace_extension.rb index e1a1cc625ed35..bca6fa1936786 100644 --- a/Library/Homebrew/utils/string_inreplace_extension.rb +++ b/Library/Homebrew/utils/string_inreplace_extension.rb @@ -39,8 +39,8 @@ def sub!(before, after) def gsub!(before, after, old_audit_result = nil, audit_result: true) # NOTE: must check for `#nil?` and not `#blank?`, or else `old_audit_result = false` will not call `odeprecated`. unless old_audit_result.nil? - # odeprecated "gsub!(before, after, #{old_audit_result})", - # "gsub!(before, after, audit_result: #{old_audit_result})" + odeprecated "gsub!(before, after, #{old_audit_result})", + "gsub!(before, after, audit_result: #{old_audit_result})" audit_result = old_audit_result end before = before.to_s if before.is_a?(Pathname) @@ -55,7 +55,9 @@ def gsub!(before, after, old_audit_result = nil, audit_result: true) # @api public sig { params(flag: String, new_value: T.any(String, Pathname)).void } def change_make_var!(flag, new_value) - return if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=[ \t]*((?:.*\\\n)*.*)$/, "#{flag}=#{new_value}", false) + return if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=[ \t]*((?:.*\\\n)*.*)$/, + "#{flag}=#{new_value}", + audit_result: false) errors << "expected to change #{flag.inspect} to #{new_value.inspect}" end @@ -67,9 +69,11 @@ def change_make_var!(flag, new_value) def remove_make_var!(flags) Array(flags).each do |flag| # Also remove trailing \n, if present. - unless gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=(?:.*\\\n)*.*$\n?/, "", false) - errors << "expected to remove #{flag.inspect}" - end + next if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=(?:.*\\\n)*.*$\n?/, + "", + audit_result: false) + + errors << "expected to remove #{flag.inspect}" end end