From 1d576d2754999c6ca0b14ee096eeecc99374d8c8 Mon Sep 17 00:00:00 2001 From: Seeker Date: Fri, 8 Jan 2021 12:15:55 -0800 Subject: [PATCH 1/3] shims/super/cc: fix most style errors --- Library/Homebrew/shims/super/cc | 53 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 517c628a5d..03fc509d59 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -30,19 +30,19 @@ class Cmd def initialize(arg0, args) @arg0 = arg0 @args = args.freeze - @config = ENV.fetch("HOMEBREW_CCCFG") { "" } + @config = ENV.fetch("HOMEBREW_CCCFG", "") @prefix = ENV["HOMEBREW_PREFIX"] @cellar = ENV["HOMEBREW_CELLAR"] @cachedir = ENV["HOMEBREW_CACHE"] @opt = ENV["HOMEBREW_OPT"] @tmpdir = ENV["HOMEBREW_TEMP"] @sysroot = ENV["HOMEBREW_SDKROOT"] - @archflags = ENV.fetch("HOMEBREW_ARCHFLAGS") { "" }.split(" ") - @optflags = ENV.fetch("HOMEBREW_OPTFLAGS") { "" }.split(" ") - @deps = Set.new(ENV.fetch("HOMEBREW_DEPENDENCIES") { "" }.split(",")) + @archflags = ENV.fetch("HOMEBREW_ARCHFLAGS", "").split + @optflags = ENV.fetch("HOMEBREW_OPTFLAGS", "").split + @deps = Set.new(ENV.fetch("HOMEBREW_DEPENDENCIES", "").split(",")) @formula_prefix = ENV["HOMEBREW_FORMULA_PREFIX"] # matches opt or cellar prefix and formula name - @keg_regex = %r[(#{Regexp.escape(opt)}|#{Regexp.escape(cellar)})/([\w+-.@]+)] + @keg_regex = %r{(#{Regexp.escape(opt)}|#{Regexp.escape(cellar)})/([\w+-.@]+)} end def mode @@ -51,7 +51,7 @@ class Cmd elsif ["ld", "ld.gold", "gold"].include? @arg0 :ld elsif @args.include? "-c" - if @arg0 =~ /(?:c|g|clang)\+\+/ + if /(?:c|g|clang)\+\+/.match?(@arg0) :cxx else :cc @@ -60,12 +60,10 @@ class Cmd :cxx elsif @args.include? "-E" :ccE + elsif /(?:c|g|clang)\+\+/.match?(@arg0) + :cxxld else - if @arg0 =~ /(?:c|g|clang)\+\+/ - :cxxld - else - :ccld - end + :ccld end end @@ -75,7 +73,7 @@ class Cmd when "gold", "ld.gold" then "ld.gold" when "cpp" then "cpp" when /llvm_(clang(\+\+)?)/ - "#{ENV["HOMEBREW_PREFIX"]}/opt/llvm/bin/#{$1}" + "#{ENV["HOMEBREW_PREFIX"]}/opt/llvm/bin/#{Regexp.last_match(1)}" when /\w\+\+(-\d+(\.\d)?)?$/ case ENV["HOMEBREW_CC"] when /clang/ @@ -83,7 +81,7 @@ class Cmd when /llvm-gcc/ "llvm-g++-4.2" when /(g)?cc(-\d+(\.\d)?)?$/ - "g++" + $2.to_s + "g++#{Regexp.last_match(2)}" end else # Note that this is a universal fallback, so that we'll always invoke @@ -104,10 +102,10 @@ class Cmd return @args.dup end - if !refurbish_args? || tool == "ld" || configure? - args = @args.dup + args = if !refurbish_args? || tool == "ld" || configure? + @args.dup else - args = refurbished_args + refurbished_args end if sysroot @@ -189,10 +187,12 @@ class Cmd # used for -Xpreprocessor -fopenmp args << arg << enum.next when /-mmacosx-version-min=(\d+)\.(\d+)/ - arg = "-mmacosx-version-min=10.9" if high_sierra_or_later? && $1 == "10" && $2.to_i < 9 + if high_sierra_or_later? && Regexp.last_match(1) == "10" && Regexp.last_match(2).to_i < 9 + arg = "-mmacosx-version-min=10.9" + end args << arg when "--fast-math" - arg = "-ffast-math" if tool =~ /^clang/ + arg = "-ffast-math" if /^clang/.match?(tool) args << arg when "-Wno-deprecated-register" # older gccs don't support these flags @@ -221,11 +221,11 @@ class Cmd args << "-Wl,#{arg}" when /^-I(.+)?/ # Support both "-Ifoo" (one argument) and "-I foo" (two arguments) - val = chuzzle($1) || enum.next + val = chuzzle(Regexp.last_match(1)) || enum.next path = canonical_path(val) args << "-I#{val}" if keep?(path) && @iset.add?(path) when /^-L(.+)?/ - val = chuzzle($1) || enum.next + val = chuzzle(Regexp.last_match(1)) || enum.next path = canonical_path(val) args << "-L#{val}" if keep?(path) && @lset.add?(path) else @@ -264,14 +264,14 @@ class Cmd def cflags args = [] - return args unless refurbish_args? || configure? + return args if !refurbish_args? && !configure? args << "-pipe" args << "-w" unless configure? args << "-#{ENV["HOMEBREW_OPTIMIZATION_LEVEL"]}" args.concat(optflags) args.concat(archflags) - args << "-std=#{@arg0}" if @arg0 =~ /c[89]9/ + args << "-std=#{@arg0}" if /c[89]9/.match?(@arg0) args end @@ -342,7 +342,7 @@ class Cmd def system_library_paths paths = ["#{sysroot}/usr/lib"] - paths << "/usr/local/lib" unless sysroot || ENV["SDKROOT"] + paths << "/usr/local/lib" if !sysroot && !ENV["SDKROOT"] paths end @@ -393,11 +393,12 @@ class Cmd end def path_split(key) - ENV.fetch(key) { "" }.split(File::PATH_SEPARATOR) + ENV.fetch(key, "").split(File::PATH_SEPARATOR) end def chuzzle(val) return val if val.nil? + val = val.chomp return val unless val.empty? end @@ -435,7 +436,7 @@ if __FILE__ == $PROGRAM_NAME ####################################################################### main - dirname, basename = File.split($0) + dirname, basename = File.split($PROGRAM_NAME) cmd = Cmd.new(basename, ARGV) tool = cmd.tool @@ -443,7 +444,7 @@ if __FILE__ == $PROGRAM_NAME log(basename, ARGV, tool, args) - args << { :close_others => false } + args << { close_others: false } if mac? exec "#{dirname}/xcrun", tool, *args else From 0f2ed88f9f10b8cf9c783b07745a388df771d004 Mon Sep 17 00:00:00 2001 From: Seeker Date: Tue, 12 Jan 2021 13:44:57 -0800 Subject: [PATCH 2/3] shims/super/cc: require `English` --- Library/Homebrew/shims/super/cc | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 03fc509d59..dc64c59657 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -10,6 +10,7 @@ exec "$HOMEBREW_RUBY_PATH" --enable-frozen-string-literal --disable=gems,did_you require "pathname" require "set" +require "English" def mac? RUBY_PLATFORM[/darwin/] From b58571a90b71f0edfaaeb9bd21bba0fe89126b36 Mon Sep 17 00:00:00 2001 From: Seeker Date: Tue, 12 Jan 2021 13:49:14 -0800 Subject: [PATCH 3/3] shims/super/cc: add `CXX_REGEX` constant --- Library/Homebrew/shims/super/cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index dc64c59657..3ee05771f7 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -25,6 +25,8 @@ def linux? end class Cmd + CXX_REGEX = /(?:c|g|clang)\+\+/.freeze + attr_reader :config, :prefix, :cellar, :opt, :cachedir, :tmpdir, :sysroot, :deps attr_reader :archflags, :optflags, :keg_regex, :formula_prefix @@ -52,7 +54,7 @@ class Cmd elsif ["ld", "ld.gold", "gold"].include? @arg0 :ld elsif @args.include? "-c" - if /(?:c|g|clang)\+\+/.match?(@arg0) + if CXX_REGEX.match?(@arg0) :cxx else :cc @@ -61,7 +63,7 @@ class Cmd :cxx elsif @args.include? "-E" :ccE - elsif /(?:c|g|clang)\+\+/.match?(@arg0) + elsif CXX_REGEX.match?(@arg0) :cxxld else :ccld