82 lines
2.4 KiB
Ruby
82 lines
2.4 KiB
Ruby
class Scrcpy < Formula
|
|
desc "Display and control your Android device"
|
|
homepage "https://github.com/Genymobile/scrcpy"
|
|
url "https://github.com/Genymobile/scrcpy/archive/v1.12.tar.gz"
|
|
sha256 "95aab189448582870d8e7d8a27a2c9b40838bd45ee2737be0f255f7a11647870"
|
|
|
|
bottle do
|
|
sha256 "adb39097a9e57ba3908902f9444763c342f12ea206ea7f459588bb13c7f1c2c2" => :catalina
|
|
sha256 "3c010284acd2f463819c91dc06a87a3e522b60135cdda3cd0ebb2eeb43319403" => :mojave
|
|
sha256 "4f94e31206c84e367a3890026bcc7c02feb0e7a6e081032cfaea7ebc509e514b" => :high_sierra
|
|
end
|
|
|
|
depends_on "meson" => :build
|
|
depends_on "ninja" => :build
|
|
depends_on "pkg-config" => :build
|
|
depends_on "ffmpeg"
|
|
depends_on "sdl2"
|
|
|
|
resource "prebuilt-server" do
|
|
url "https://github.com/Genymobile/scrcpy/releases/download/v1.12/scrcpy-server-v1.12"
|
|
sha256 "b6595262c230e9773fdb817257abcc8c6e6e00f15b1c32b6a850ccfd8176dc10"
|
|
end
|
|
|
|
def install
|
|
r = resource("prebuilt-server")
|
|
r.fetch
|
|
cp r.cached_download, buildpath/"prebuilt-server.jar"
|
|
|
|
mkdir "build" do
|
|
system "meson", "--prefix=#{prefix}",
|
|
"--buildtype=release",
|
|
"-Dprebuilt_server=#{buildpath}/prebuilt-server.jar",
|
|
".."
|
|
|
|
system "ninja", "install"
|
|
end
|
|
end
|
|
|
|
def caveats; <<~EOS
|
|
At runtime, adb must be accessible from your PATH.
|
|
|
|
You can install adb from Homebrew Cask:
|
|
brew cask install android-platform-tools
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
fakeadb = (testpath/"fakeadb.sh")
|
|
|
|
# When running, scrcpy calls adb three times:
|
|
# - adb push ... (to push scrcpy-server.jar)
|
|
# - adb reverse ... tcp:PORT ...
|
|
# - adb shell ...
|
|
# However, exiting on $1 = shell didn't work properly, so instead
|
|
# fakeadb exits on $1 = reverse
|
|
|
|
fakeadb.write <<~EOS
|
|
#!/bin/sh
|
|
echo $@ >> #{testpath/"fakeadb.log"}
|
|
|
|
if [ "$1" = "reverse" ]; then
|
|
exit 42
|
|
fi
|
|
EOS
|
|
|
|
fakeadb.chmod 0755
|
|
ENV["ADB"] = fakeadb
|
|
|
|
# It's expected to fail after adb reverse step because fakeadb exits
|
|
# with code 42
|
|
out = shell_output("#{bin}/scrcpy -p 1337 2>&1", 1)
|
|
assert_match(/ 42/, out)
|
|
|
|
log_content = File.read(testpath/"fakeadb.log")
|
|
|
|
# Check that it used port we've specified
|
|
assert_match(/tcp:1337/, log_content)
|
|
|
|
# Check that it tried to push something from its prefix
|
|
assert_match(/push #{prefix}/, log_content)
|
|
end
|
|
end
|