shims/super/cc: handle double dash in args

This commit is contained in:
Caleb Xu 2025-01-12 01:56:15 -05:00
parent 2432d01884
commit 1ec8a0488f
No known key found for this signature in database
GPG Key ID: 47E6040D07B8407D

View File

@ -40,7 +40,9 @@ class Cmd
def initialize(arg0, args) def initialize(arg0, args)
@arg0 = arg0 @arg0 = arg0
@args = args.freeze split_args = split_args_at_double_dash(args)
@args = split_args[0].freeze
@positional_args = split_args[1].freeze
@config = ENV.fetch("HOMEBREW_CCCFG", "") @config = ENV.fetch("HOMEBREW_CCCFG", "")
@prefix = ENV["HOMEBREW_PREFIX"] @prefix = ENV["HOMEBREW_PREFIX"]
@cellar = ENV["HOMEBREW_CELLAR"] @cellar = ENV["HOMEBREW_CELLAR"]
@ -57,6 +59,15 @@ class Cmd
@keg_regex = %r{(#{Regexp.escape(opt)}|#{Regexp.escape(cellar)})/([\w+-.@]+)} @keg_regex = %r{(#{Regexp.escape(opt)}|#{Regexp.escape(cellar)})/([\w+-.@]+)}
end end
def split_args_at_double_dash(args)
double_dash_index = args.find_index("--")
if double_dash_index
[args[...double_dash_index], args[double_dash_index..]]
else
[args, []]
end
end
def mode def mode
if @arg0 == "cpp" if @arg0 == "cpp"
:cpp :cpp
@ -130,7 +141,7 @@ class Cmd
end end
end end
case mode optional_args = case mode
when :ccld when :ccld
cflags + args + cppflags + ldflags cflags + args + cppflags + ldflags
when :cxxld when :cxxld
@ -146,6 +157,8 @@ class Cmd
when :ld when :ld
ldflags + args ldflags + args
end end
optional_args + @positional_args
end end
def refurbished_args def refurbished_args