From 8c5e6e10a7d0d7c8fb398d97cede9b47fd3c9e0e Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 24 Jan 2023 13:26:47 +0800 Subject: [PATCH 1/2] rubocops/lines: update hard-coded compiler check 1. `llvm-g{cc,++}` has been gone for a long time. We don't need to check for this anymore. 2. Also check for calling the compiler as `cc`, `c89`, `c99`, or `c++`. --- Library/Homebrew/rubocops/lines.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index d17ed977e3..05336f7f93 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -618,18 +618,18 @@ module RuboCop # Avoid hard-coding compilers find_every_method_call_by_name(body_node, :system).each do |method| param = parameters(method).first - if (match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)(\s|$)})) + if (match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|clang|cc|c[89]9)(\s|$)})) problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\"" - elsif (match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)(\s|$)})) + elsif (match = regex_match_group(param, %r{^(/usr/bin/)?((g|clang|c)\+\+)(\s|$)})) problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\"" end end find_instance_method_call(body_node, "ENV", :[]=) do |method| param = parameters(method)[1] - if (match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)(\s|$)})) + if (match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|clang|cc|c[89]9)(\s|$)})) problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\"" - elsif (match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)(\s|$)})) + elsif (match = regex_match_group(param, %r{^(/usr/bin/)?((g|clang|c)\+\+)(\s|$)})) problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\"" end end From 86161e8c3240b9e7689abad4ed538c46476e9cdb Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 24 Jan 2023 14:04:36 +0800 Subject: [PATCH 2/2] Fix test failures --- Library/Homebrew/rubocops/lines.rb | 4 ++++ Library/Homebrew/test/rubocops/text/miscellaneous_spec.rb | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index 05336f7f93..cb02f75e5d 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -617,6 +617,8 @@ module RuboCop # Avoid hard-coding compilers find_every_method_call_by_name(body_node, :system).each do |method| + next if @formula_name == "bazel" # TODO: Remove shim bypass in bazel. + param = parameters(method).first if (match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|clang|cc|c[89]9)(\s|$)})) problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\"" @@ -626,6 +628,8 @@ module RuboCop end find_instance_method_call(body_node, "ENV", :[]=) do |method| + next if @formula_name == "bazel" # TODO: Remove shim bypass in bazel. + param = parameters(method)[1] if (match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|clang|cc|c[89]9)(\s|$)})) problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\"" diff --git a/Library/Homebrew/test/rubocops/text/miscellaneous_spec.rb b/Library/Homebrew/test/rubocops/text/miscellaneous_spec.rb index 0c7d7ee41e..cb3781bd45 100644 --- a/Library/Homebrew/test/rubocops/text/miscellaneous_spec.rb +++ b/Library/Homebrew/test/rubocops/text/miscellaneous_spec.rb @@ -255,14 +255,14 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do RUBY end - it "reports an offense when a hard-coded `llvm-g++` is set as COMPILER_PATH" do + it "reports an offense when a hard-coded `c++` is set as COMPILER_PATH" do expect_offense(<<~'RUBY') class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install - ENV["COMPILER_PATH"] = "/usr/bin/llvm-g++" - ^^^^^^^^^^^^^^^^^^^ Use "#{ENV.cxx}" instead of hard-coding "llvm-g++" + ENV["COMPILER_PATH"] = "/usr/bin/c++" + ^^^^^^^^^^^^^^ Use "#{ENV.cxx}" instead of hard-coding "c++" end end RUBY