Merge pull request #10269 from SeekingMeaning/style-cc-shim
shims/super/cc: fix most style errors
This commit is contained in:
commit
c72b375a57
@ -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/]
|
||||
@ -24,25 +25,27 @@ 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
|
||||
|
||||
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 +54,7 @@ class Cmd
|
||||
elsif ["ld", "ld.gold", "gold"].include? @arg0
|
||||
:ld
|
||||
elsif @args.include? "-c"
|
||||
if @arg0 =~ /(?:c|g|clang)\+\+/
|
||||
if CXX_REGEX.match?(@arg0)
|
||||
:cxx
|
||||
else
|
||||
:cc
|
||||
@ -60,12 +63,10 @@ class Cmd
|
||||
:cxx
|
||||
elsif @args.include? "-E"
|
||||
:ccE
|
||||
elsif CXX_REGEX.match?(@arg0)
|
||||
:cxxld
|
||||
else
|
||||
if @arg0 =~ /(?:c|g|clang)\+\+/
|
||||
:cxxld
|
||||
else
|
||||
:ccld
|
||||
end
|
||||
:ccld
|
||||
end
|
||||
end
|
||||
|
||||
@ -75,7 +76,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 +84,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 +105,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 +190,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 +224,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 +267,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 +345,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 +396,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 +439,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 +447,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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user