From c477b9aab3ef9769687dbe82c665cd067e362d6a Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Mon, 21 Nov 2022 22:14:04 -0800 Subject: [PATCH] Cleanup after adding os specific rubocop - Change name of rubocop warning - Disable linting on remaining offending lines - Add todos to move lines with disabled linting checks to extend/os in the future --- Library/.rubocop.yml | 2 +- Library/Homebrew/cask/cmd/install.rb | 3 ++- Library/Homebrew/cmd/update-report.rb | 3 ++- Library/Homebrew/default_prefix.rb | 3 ++- Library/Homebrew/dev-cmd/bottle.rb | 9 +++++++-- Library/Homebrew/dev-cmd/tests.rb | 3 +++ Library/Homebrew/dev-cmd/update-test.rb | 3 ++- Library/Homebrew/formula_cellar_checks.rb | 3 ++- Library/Homebrew/rubocops/platform.rb | 2 +- Library/Homebrew/test/rubocops/platform_spec.rb | 4 ++-- 10 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 3636e41d3b..568235043a 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -57,7 +57,7 @@ FormulaAuditStrict: Homebrew/MoveToExtendOS: Exclude: - - "Homebrew/{extend,test}/**/*" + - "Homebrew/{extend,test,requirements}/**/*" - "Taps/**/*" - "Homebrew/os.rb" diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb index c4a550b5ba..1a3cd870db 100644 --- a/Library/Homebrew/cask/cmd/install.rb +++ b/Library/Homebrew/cask/cmd/install.rb @@ -68,7 +68,8 @@ module Cask zap: nil, dry_run: nil ) - odie "Installing casks is supported only on macOS" unless OS.mac? + # TODO: Refactor and move to extend/os + odie "Installing casks is supported only on macOS" unless OS.mac? # rubocop:disable Homebrew/MoveToExtendOS options = { verbose: verbose, diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index dbc9a7fbfc..71ecb09d92 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -293,7 +293,8 @@ module Homebrew end def migrate_gcc_dependents_if_needed - return if OS.mac? + # TODO: Refactor and move to extend/os + return if OS.mac? # rubocop:disable Homebrew/MoveToExtendOS return if Settings.read("gcc-rpaths.fixed") == "true" Formula.installed.each do |formula| diff --git a/Library/Homebrew/default_prefix.rb b/Library/Homebrew/default_prefix.rb index 70e493c233..de132865d9 100644 --- a/Library/Homebrew/default_prefix.rb +++ b/Library/Homebrew/default_prefix.rb @@ -4,7 +4,8 @@ require "simulate_system" module Homebrew - DEFAULT_PREFIX, DEFAULT_REPOSITORY = if OS.mac? && Hardware::CPU.arm? + # TODO: Refactor and move to extend/os + DEFAULT_PREFIX, DEFAULT_REPOSITORY = if OS.mac? && Hardware::CPU.arm? # rubocop:disable Homebrew/MoveToExtendOS [HOMEBREW_MACOS_ARM_DEFAULT_PREFIX, HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY] elsif Homebrew::SimulateSystem.simulating_or_running_on_linux? [HOMEBREW_LINUX_DEFAULT_PREFIX, HOMEBREW_LINUX_DEFAULT_REPOSITORY] diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 66320adf32..56965db1c1 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -247,7 +247,8 @@ module Homebrew "--pax-option", "globexthdr.name=/GlobalHead.%n,exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime" ].freeze - return ["tar", gnutar_args].freeze if OS.linux? + # TODO: Refactor and move to extend/os + return ["tar", gnutar_args].freeze if OS.linux? # rubocop:disable Homebrew/MoveToExtendOS # Use gnu-tar on macOS as it can be set up for reproducibility better than libarchive. begin @@ -275,6 +276,8 @@ module Homebrew ignores << %r{#{cellar_regex}/#{go_regex}/[\d.]+/libexec} end + # TODO: Refactor and move to extend/os + # rubocop:disable Homebrew/MoveToExtendOS ignores << case f.name # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. @@ -284,6 +287,7 @@ module Homebrew when Version.formula_optionally_versioned_regex(:binutils) %r{#{cellar_regex}/binutils} if OS.linux? end + # rubocop:enable Homebrew/MoveToExtendOS ignores.compact end @@ -409,7 +413,8 @@ module Homebrew # Set the times for reproducible bottles. if file.symlink? # Need to make symlink permissions consistent on macOS and Linux - File.lchmod 0777, file if OS.mac? + # TODO: Refactor and move to extend/os + File.lchmod 0777, file if OS.mac? # rubocop:disable Homebrew/MoveToExtendOS File.lutime(tab.source_modified_time, tab.source_modified_time, file) else file.utime(tab.source_modified_time, tab.source_modified_time) diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 1335d35dcb..2852fdb7d7 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -157,6 +157,8 @@ module Homebrew --require spec_helper ] + # TODO: Refactor and move to extend/os + # rubocop:disable Homebrew/MoveToExtendOS unless OS.mac? bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask" files = files.grep_v(%r{^test/(os/mac|cask)(/.*|_spec\.rb)$}) @@ -166,6 +168,7 @@ module Homebrew bundle_args << "--tag" << "~needs_linux" files = files.grep_v(%r{^test/os/linux(/.*|_spec\.rb)$}) end + # rubocop:enable Homebrew/MoveToExtendOS puts "Randomized with seed #{seed}" diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index 69bfe66f0f..8abffa4869 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -65,7 +65,8 @@ module Homebrew tags = if (HOMEBREW_REPOSITORY/".git/shallow").exist? safe_system "git", "fetch", "--tags", "--depth=1" Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") - elsif OS.linux? + # TODO: Refactor and move to extend/os + elsif OS.linux? # rubocop:disable Homebrew/MoveToExtendOS Utils.popen_read("git tag --list | sort -rV") end end diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 8045e2c968..6f85ab259a 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -319,7 +319,8 @@ module FormulaCellarChecks def check_binary_arches(formula) return unless formula.prefix.directory? # There is no `binary_executable_or_library_files` method for the generic OS - return if !OS.mac? && !OS.linux? + # TODO: Refactor and move to extend/os + return if !OS.mac? && !OS.linux? # rubocop:disable Homebrew/MoveToExtendOS keg = Keg.new(formula.prefix) mismatches = {} diff --git a/Library/Homebrew/rubocops/platform.rb b/Library/Homebrew/rubocops/platform.rb index 0cc65e9344..31706ed63f 100644 --- a/Library/Homebrew/rubocops/platform.rb +++ b/Library/Homebrew/rubocops/platform.rb @@ -8,7 +8,7 @@ module RuboCop # # @api private class MoveToExtendOS < Base - MSG = "Move calls to `OS.linux?` and `OS.mac?` to `extend/os`." + MSG = "Move `OS.linux?` and `OS.mac?` calls to `extend/os`." def_node_matcher :os_check?, <<~PATTERN (send (const nil? :OS) {:mac? | :linux?}) diff --git a/Library/Homebrew/test/rubocops/platform_spec.rb b/Library/Homebrew/test/rubocops/platform_spec.rb index 8a8819d6a3..4e8872c077 100644 --- a/Library/Homebrew/test/rubocops/platform_spec.rb +++ b/Library/Homebrew/test/rubocops/platform_spec.rb @@ -9,14 +9,14 @@ describe RuboCop::Cop::Homebrew::MoveToExtendOS do it "registers an offense when using `OS.linux?`" do expect_offense(<<~RUBY) OS.linux? - ^^^^^^^^^ Move calls to `OS.linux?` and `OS.mac?` to `extend/os`. + ^^^^^^^^^ Move `OS.linux?` and `OS.mac?` calls to `extend/os`. RUBY end it "registers an offense when using `OS.mac?`" do expect_offense(<<~RUBY) OS.mac? - ^^^^^^^ Move calls to `OS.linux?` and `OS.mac?` to `extend/os`. + ^^^^^^^ Move `OS.linux?` and `OS.mac?` calls to `extend/os`. RUBY end end