Skip to content

Commit

Permalink
cask/artifact/shim_script: add DSL to create shim scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cho-m committed Oct 4, 2024
1 parent 3994768 commit 08ec471
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/cask/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 42 additions & 0 deletions Library/Homebrew/cask/artifact/shim_script.rb
Original file line number Diff line number Diff line change
@@ -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(

Check warning on line 13 in Library/Homebrew/cask/artifact/shim_script.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/shim_script.rb#L13

Added line #L13 was not covered by tests
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

Check warning on line 28 in Library/Homebrew/cask/artifact/shim_script.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/shim_script.rb#L25-L28

Added lines #L25 - L28 were not covered by tests

super(cask, @wrapper, target: target || @command.basename)

Check warning on line 30 in Library/Homebrew/cask/artifact/shim_script.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/shim_script.rb#L30

Added line #L30 was not covered by tests
end

def install_phase(**options)
@wrapper.write <<~EOS

Check warning on line 34 in Library/Homebrew/cask/artifact/shim_script.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/shim_script.rb#L34

Added line #L34 was not covered by tests
#!#{@shell}
exec "#{@command}" #{@args.map { |arg| "\"#{arg}\"" }.join(" ")}

Check warning on line 36 in Library/Homebrew/cask/artifact/shim_script.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/shim_script.rb#L36

Added line #L36 was not covered by tests
EOS
super

Check warning on line 38 in Library/Homebrew/cask/artifact/shim_script.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/shim_script.rb#L38

Added line #L38 was not covered by tests
end
end
end
end
5 changes: 5 additions & 0 deletions Library/Homebrew/cask/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def binarydir
@binarydir ||= HOMEBREW_PREFIX/"bin"
end

sig { returns(Pathname) }
def shim_scriptdir
binarydir

Check warning on line 152 in Library/Homebrew/cask/config.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/config.rb#L152

Added line #L152 was not covered by tests
end

sig { returns(Pathname) }
def manpagedir
@manpagedir ||= HOMEBREW_PREFIX/"share/man"
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class DSL
Artifact::Mdimporter,
Artifact::ScreenSaver,
Artifact::Service,
Artifact::ShimScript,
Artifact::StageOnly,
Artifact::Suite,
Artifact::VstPlugin,
Expand Down

0 comments on commit 08ec471

Please sign in to comment.