From 3171a644dfa538a1860d93e0c73f311530d0a9de Mon Sep 17 00:00:00 2001 From: Caleb Xu Date: Sun, 12 Jan 2025 01:56:15 -0500 Subject: [PATCH] shims/super/cc: handle double dash in args --- Library/Homebrew/shims/super/cc | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 458a5dc236fa2..38e71bb8e811a 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -40,7 +40,9 @@ class Cmd def initialize(arg0, args) @arg0 = arg0 - @args = args.freeze + provided_args = split_args(args) + @args = provided_args[0].freeze + @positional_args = provided_args[1].freeze @config = ENV.fetch("HOMEBREW_CCCFG", "") @prefix = ENV["HOMEBREW_PREFIX"] @cellar = ENV["HOMEBREW_CELLAR"] @@ -57,6 +59,15 @@ class Cmd @keg_regex = %r{(#{Regexp.escape(opt)}|#{Regexp.escape(cellar)})/([\w+-.@]+)} end + def split_args(args) + double_dash_index = args.find_index("--") + if double_dash_index + [args[0...double_dash_index], args[double_dash_index..-1]] + else + [args, []] + end + end + def mode if @arg0 == "cpp" :cpp @@ -132,19 +143,19 @@ class Cmd case mode when :ccld - cflags + args + cppflags + ldflags + cflags + args + cppflags + ldflags + @positional_args when :cxxld - cxxflags + args + cppflags + ldflags + cxxflags + args + cppflags + ldflags + @positional_args when :cc - cflags + args + cppflags + cflags + args + cppflags + @positional_args when :cxx - cxxflags + args + cppflags + cxxflags + args + cppflags + @positional_args when :ccE - args + cppflags + args + cppflags + @positional_args when :cpp - args + cppflags + args + cppflags + @positional_args when :ld - ldflags + args + ldflags + args + @positional_args end end