From 863b412820d0ccb3d619348a4841f0ef305a23cd Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 8 Jun 2021 00:58:23 +0100 Subject: [PATCH] shims/super/cc: fix `sysroot` flag handling The shim currently does not handle `--sysroot=` and `-isysroot=` flags correctly. For example, the LLVM build passes `--sysroot=.`, and this is incorrectly parsed by the shim. --- Library/Homebrew/shims/super/cc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index a54b2f9009..b1cc61e274 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -212,13 +212,24 @@ class Cmd args << "-Wl,-multiply_defined,suppress" when "-undefineddynamic_lookup" args << "-Wl,-undefined,dynamic_lookup" - when /^-isysroot/, /^--sysroot/ + when /^-isysroot=/, /^--sysroot=/ if mac? - sdk = enum.next + sdk = arg.split("=")[1..-1].join("=") + # We set the sysroot for macOS SDKs + args << arg unless sdk.downcase.include? "osx" + else + args << arg + end + when /^-isysroot(.+)?/, /^--sysroot(.+)?/ + # Support both "-isysrootfoo" and "-isysroot foo" (two arguments) + sdk = chuzzle(Regexp.last_match(1)) + if mac? + sdk ||= enum.next # We set the sysroot for macOS SDKs args << "-isysroot#{sdk}" unless sdk.downcase.include? "osx" else - args << arg << enum.next + args << arg + args << enum.next unless sdk end when "-dylib" args << "-Wl,#{arg}"