Homebrew / homebrew-core

🍻 Default formulae for the missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
13.58k stars 12.33k forks source link

Hardware::CPU.arch used as string gives an error #142308

Closed fxcoudert closed 12 months ago

fxcoudert commented 1 year ago

There are type errors with Hardware::CPU.arch which tends to be used as a string in formulas:

a/alerter.rb:    xcodebuild "-arch", Hardware::CPU.arch,
b/blis.rb:      Hardware::CPU.arch
b/blueutil.rb:    xcodebuild "-arch", Hardware::CPU.arch, "SDKROOT=", "SYMROOT=build"
c/choose-gui.rb:    xcodebuild "-arch", Hardware::CPU.arch, "SDKROOT=", "SYMROOT=build", "-configuration", "Release", "build"
c/configen.rb:    xcodebuild "-arch", Hardware::CPU.arch, "SYMROOT=build"
c/cpufetch.rb:    arch = (OS.mac? && Hardware::CPU.arm?) ? "ARM" : Hardware::CPU.arch
d/dark-mode.rb:      xcodebuild "-arch", Hardware::CPU.arch,
i/imagesnap.rb:    xcodebuild "-arch", Hardware::CPU.arch, "-project", "ImageSnap.xcodeproj", "SYMROOT=build"
i/ios-deploy.rb:               "-arch", Hardware::CPU.arch
i/ios-deploy.rb:               "-arch", Hardware::CPU.arch
l/launch.rb:    xcodebuild "-arch", Hardware::CPU.arch, "-configuration", "Deployment", "SYMROOT=build"
lib/libetpan.rb:    xcodebuild "-arch", Hardware::CPU.arch,
lib/libetpan.rb:    xcodebuild "-arch", Hardware::CPU.arch,
m/macosvpn.rb:    xcodebuild "-arch", Hardware::CPU.arch, "SYMROOT=build"
m/mogenerator.rb:    xcodebuild "-arch", Hardware::CPU.arch,
m/mplayershell.rb:    xcodebuild "-arch", Hardware::CPU.arch,
o/objc-codegenutils.rb:    xcodebuild "-arch", Hardware::CPU.arch, "-project", "codegenutils.xcodeproj", "-target", "assetgen",
o/objc-codegenutils.rb:    xcodebuild "-arch", Hardware::CPU.arch, "-target", "colordump", "-configuration", "Release", "SYMROOT=build",
o/objc-codegenutils.rb:    xcodebuild "-arch", Hardware::CPU.arch, "-target", "identifierconstants", "-configuration", "Release",
o/ocmtoc.rb:    xcodebuild "-arch", Hardware::CPU.arch,
r/rem.rb:    xcodebuild "-arch", Hardware::CPU.arch, "SYMROOT=build"
r/rpcgen.rb:    xcodebuild "-arch", Hardware::CPU.arch,
s/sbjson.rb:               "-arch", Hardware::CPU.arch,
s/sevenzip.rb:      mac_suffix = Hardware::CPU.intel? ? "x64" : Hardware::CPU.arch
s/stella.rb:        xcodebuild "-arch", Hardware::CPU.arch, "SYMROOT=build"
s/swimat.rb:    xcodebuild "-arch", Hardware::CPU.arch,
s/switchaudio-osx.rb:               "-arch", Hardware::CPU.arch,
t/telnet.rb:                 "-arch", Hardware::CPU.arch
t/telnet.rb:               "-arch", Hardware::CPU.arch,
t/telnetd.rb:                 "-arch", Hardware::CPU.arch
t/telnetd.rb:               "-arch", Hardware::CPU.arch,
t/terminal-notifier.rb:    xcodebuild "-arch", Hardware::CPU.arch,
w/webarchiver.rb:    xcodebuild "SYMROOT=build", "-arch", Hardware::CPU.arch
x/xcproj.rb:    xcodebuild "-arch", Hardware::CPU.arch,

Now this gives errors like this:

  Error: An exception occurred within a child process:
    TypeError: Parameter 'args': Expected type T.any(Pathname, String), got type Symbol with value :arm64
  Caller: /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/t/telnet.rb:32
  Definition: /opt/homebrew/Library/Homebrew/formula.rb:2798
fxcoudert commented 1 year ago

lua has an error for ENV.cflags, which seems to be shared with other formulas:

c/cabocha.rb:      s.change_make_var! "CFLAGS", ENV.cflags
c/cabocha.rb:      s.change_make_var! "CXXFLAGS", ENV.cflags
c/calc.rb:    ENV["EXTRA_CFLAGS"] = ENV.cflags
d/dnsmasq.rb:      s.change_make_var! "CFLAGS", ENV.cflags
g/glade.rb:    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
g/gmime.rb:    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
g/gnome-autoar.rb:    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
j/jsonrpc-glib.rb:    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
l/llvm.rb:      cflags = ENV.cflags&.split || []
l/lua.rb:      s.change_make_var! "MYCFLAGS", ENV.cflags
lib/libdazzle.rb:    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
lib/libgedit-amtk.rb:    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
o/openssl@1.1.rb:      args += (ENV.cflags || "").split
o/openssl@3.0.rb:      args += (ENV.cflags || "").split
o/openssl@3.rb:      args += (ENV.cflags || "").split
q/quictls.rb:      args += (ENV.cflags || "").split
t/template-glib.rb:    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
t/tepl.rb:    flags = (ENV.cflags || "").split + (ENV.cppflags || "").split + (ENV.ldflags || "").split
samford commented 1 year ago

If we decide that updating the related type signatures to allow for more types that can be cast to a String is fine, https://github.com/Homebrew/brew/pull/16002 will address the xcodebuild/Hardware::CPU.arch type errors without requiring changes to formulae. If we instead decide that it's preferable to maintain the existing type signatures and manually cast the values as strings (e.g., using #to_s), then I can help with updating related formulae.


Past that, I've addressed usage of ENV.cflags/ENV.ldflags in formulae where a nil value wasn't handled, so those shouldn't produce type errors now. Most of the instances above already use || "" to fall back to an empty string, so they were fine. [Some others use a combination of #to_s and #split when an array is expected.]

The one exception above is calc but it follows a slightly different pattern and built fine for me on Sonoma (ARM64) without adding || "".

Bo98 commented 12 months ago

I think this is fixed now