diff --git a/Library/Homebrew/cask/artifact.rb b/Library/Homebrew/cask/artifact.rb index eab26b9f4334f3..53e3540fa136ac 100644 --- a/Library/Homebrew/cask/artifact.rb +++ b/Library/Homebrew/cask/artifact.rb @@ -23,6 +23,7 @@ require "cask/artifact/mdimporter" require "cask/artifact/screen_saver" require "cask/artifact/service" +require "cask/artifact/shim_script" require "cask/artifact/stage_only" require "cask/artifact/suite" require "cask/artifact/uninstall" diff --git a/Library/Homebrew/cask/artifact/shim_script.rb b/Library/Homebrew/cask/artifact/shim_script.rb new file mode 100644 index 00000000000000..973e91419adf78 --- /dev/null +++ b/Library/Homebrew/cask/artifact/shim_script.rb @@ -0,0 +1,42 @@ +# typed: true # rubocop:todo Sorbet/StrictSigil +# frozen_string_literal: true + +require "cask/artifact/binary" + +module Cask + module Artifact + # Artifact corresponding to the `shim_script` stanza. + class ShimScript < Binary + DEFAULT_ARGS = ["$@"].freeze + + sig { + params( + cask: Cask, + source: T.any(String, Pathname), + target: T.nilable(T.any(String, Pathname)), + wrapper: T.nilable(String), + args: T.nilable(T::Array[T.any(String, Pathname)]), + shell: String, + ).void + } + def initialize(cask, source, target: nil, wrapper: nil, args: nil, shell: "/bin/bash") + raise CaskInvalidError, "`wrapper` must be a file name not a path" if wrapper&.include?("/") + + @command = cask.staged_path.join(source) + @wrapper = cask.staged_path.join(wrapper || "#{@command.basename}.wrapper.sh") + @args = args || DEFAULT_ARGS + @shell = shell + + super(cask, @wrapper, target: target || @command.basename) + end + + def install_phase(**options) + @wrapper.write <<~EOS + #!#{@shell} + exec "#{@command}" #{@args.map { |arg| "\"#{arg}\"" }.join(" ")} + EOS + super + end + end + end +end diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index 30a5c521cb207a..f2f10311273364 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -147,6 +147,11 @@ def binarydir @binarydir ||= HOMEBREW_PREFIX/"bin" end + sig { returns(Pathname) } + def shim_scriptdir + binarydir + end + sig { returns(Pathname) } def manpagedir @manpagedir ||= HOMEBREW_PREFIX/"share/man" diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index bb5d36cf7ec44c..7b20e50283c74b 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -50,6 +50,7 @@ class DSL Artifact::Mdimporter, Artifact::ScreenSaver, Artifact::Service, + Artifact::ShimScript, Artifact::StageOnly, Artifact::Suite, Artifact::VstPlugin,