brew icon indicating copy to clipboard operation
brew copied to clipboard

Add shimscript arg to cask DSL

Open FnControlOption opened this issue 1 year ago • 1 comments

  • [ ] Have you followed the guidelines in our Contributing document?
  • [ ] Have you checked to ensure there aren't other open Pull Requests for the same change?
  • [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
  • [ ] Have you written new tests for your changes? Here's an example.
  • [ ] Have you successfully run brew style with your changes locally?
  • [ ] Have you successfully run brew typecheck with your changes locally?
  • [ ] Have you successfully run brew tests with your changes locally?

Sometimes, symlinking doesn't work on a cask binary, so a shim script must be used instead.

shimscript = "#{staged_path}/tiled.wrapper.sh"
binary shimscript, target: "tiled"

preflight do
  File.write shimscript, <<~EOS
    #!/bin/bash
    exec '#{appdir}/Tiled.app/Contents/MacOS/Tiled' "$@"
  EOS
end

can be reduced to

binary "#{appdir}/Tiled.app/Contents/MacOS/Tiled",
       shimscript: "tiled.wrapper.sh",
       target:     "tiled"

Also see: https://github.com/Homebrew/homebrew-cask/issues/18809

FnControlOption avatar Aug 04 '22 17:08 FnControlOption

30 casks use shim scripts, 7 of those are special:

# android-ndk
shimscript = "#{staged_path}/ndk_exec.sh"
preflight do
  build = File.read("#{staged_path}/source.properties").match(/(?<=Pkg.Revision\s=\s\d\d.\d.)\d+/)
  FileUtils.ln_sf("#{staged_path}/AndroidNDK#{build}.app/Contents/NDK", "#{HOMEBREW_PREFIX}/share/android-ndk")

  File.write shimscript, <<~EOS
    #!/bin/bash
    readonly executable="#{staged_path}/AndroidNDK#{build}.app/Contents/NDK/$(basename ${0})"
    test -f "${executable}" && exec "${executable}" "${@}"
  EOS
end

%w[
  ndk-build
  ndk-depends
  ndk-gdb
  ndk-stack
  ndk-which
].each { |link_name| binary shimscript, target: link_name }
# dynamodb-local
preflight do
  File.write shimscript, <<~EOS
    #!/bin/sh
    cd "$(dirname "$(readlink -n "${0}")")" && \
      java -Djava.library.path='./DynamoDBLocal_lib' -jar 'DynamoDBLocal.jar' "$@"
  EOS
end
# gog
preflight do
  File.write shimscript, <<~EOS
    #!/bin/sh
    cd '#{staged_path}/gogs' && ./gogs "$@"
  EOS
end
# minecraft-server
config_dir = HOMEBREW_PREFIX.join("etc", "minecraft-server")

preflight do
  FileUtils.mkdir_p config_dir

  File.write shimscript, <<~EOS
    #!/bin/sh
    cd '#{config_dir}' && \
      exec /usr/bin/java ${@:--Xms1024M -Xmx1024M} -jar '#{staged_path}/server.jar' nogui
  EOS
end
# p4v
p4_wrapper = "#{staged_path}/p4.wrapper.sh"
binary p4_wrapper, target: "p4v"
binary p4_wrapper, target: "p4admin"
binary p4_wrapper, target: "p4merge"

preflight do
  File.write p4_wrapper, <<~EOS
    #!/bin/bash
    set -euo pipefail
    COMMAND=$(basename "$0")
    if [[ "$COMMAND" == "p4merge" ]]; then
      exec "#{appdir}/${COMMAND}.app/Contents/Resources/launch${COMMAND}" "$@" 2> /dev/null
    else
      exec "#{appdir}/${COMMAND}.app/Contents/MacOS/${COMMAND}" "$@" 2> /dev/null
    fi
  EOS
end
# prince
preflight do
  File.write shimscript, <<~EOS
    #!/bin/sh
    exec '#{staged_path}/prince-#{version}-macos/lib/prince/bin/prince' --prefix '#{staged_path}/prince-#{version}-macos/lib/prince' "$@"
  EOS
end
# subsync
preflight do
  File.write shimscript, <<~EOS
    #!/bin/sh
    exec '#{appdir}/subsync.app/Contents/MacOS/subsync' --cli "$@"
  EOS
end

FnControlOption avatar Aug 05 '22 15:08 FnControlOption

Looks fine to me then. @Homebrew/cask?

carlocab avatar Aug 13 '22 06:08 carlocab

Can we also check if the source exists and ensure the target directory does?

SMillerDev avatar Aug 13 '22 18:08 SMillerDev

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Sep 08 '22 00:09 github-actions[bot]