-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix server build script by using more portable and safer bash and rely on PATH when no ANDROID_HOME #1716
Fix server build script by using more portable and safer bash and rely on PATH when no ANDROID_HOME #1716
Changes from 3 commits
2fb0a87
1cf5918
f50d9dc
3e0dfb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
# | ||
# This script generates the scrcpy binary "manually" (without gradle). | ||
# | ||
|
@@ -9,14 +9,24 @@ | |
# | ||
# BUILD_DIR=my_build_dir ./build_without_gradle.sh | ||
|
||
set -e | ||
set -eo pipefail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it too violent? set -eo pipefail
result=$(echo a | grep b) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends on what behavior you want here. You might want something like this: |
||
|
||
SCRCPY_DEBUG=false | ||
SCRCPY_VERSION_NAME=1.16 | ||
|
||
PLATFORM=${ANDROID_PLATFORM:-29} | ||
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-29.0.2} | ||
|
||
if [ -z ${ANDROID_HOME+x} ]; then | ||
AIDL="$ANDROID_HOME/build-tools/$BUILD_TOOLS/aidl" | ||
DX="$ANDROID_HOME/build-tools/$BUILD_TOOLS/dx" | ||
else | ||
[ -x "$(which dx)" ] && DX="dx" \ | ||
|| (echo "Please provide \$ANDROID_HOME or set \$PATH to include 'dx' executable"; exit 1) | ||
[ -x "$(which aidl)" ] && AIDL="aidl" \ | ||
|| (echo "Please provide \$ANDROID_HOME or set \$PATH to include 'aidl' executable"; exit 1) | ||
fi | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For info, why do you need this? Where do your (That way, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The problem I'm trying to solve here is building Because AOSP source has a huge and monolithic build system and because there's no proper tagging, Arch Linux, to build everything from source, need to do this: https://github.com/archlinux/svntogit-community/blob/packages/android-tools/trunk/generate_build.rb#L3 .
You're right. In fact, I didn't covered this, if you depend on a specific |
||
BUILD_DIR="$(realpath ${BUILD_DIR:-build_manual})" | ||
CLASSES_DIR="$BUILD_DIR/classes" | ||
SERVER_DIR=$(dirname "$0") | ||
|
@@ -40,9 +50,9 @@ EOF | |
|
||
echo "Generating java from aidl..." | ||
cd "$SERVER_DIR/src/main/aidl" | ||
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/aidl" -o"$CLASSES_DIR" \ | ||
"$AIDL" -o"$CLASSES_DIR" \ | ||
android/view/IRotationWatcher.aidl | ||
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/aidl" -o"$CLASSES_DIR" \ | ||
"$AIDL" -o"$CLASSES_DIR" \ | ||
android/content/IOnPrimaryClipChangedListener.aidl | ||
|
||
echo "Compiling java sources..." | ||
|
@@ -54,8 +64,7 @@ javac -bootclasspath "$ANDROID_HOME/platforms/android-$PLATFORM/android.jar" \ | |
|
||
echo "Dexing..." | ||
cd "$CLASSES_DIR" | ||
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/dx" --dex \ | ||
--output "$BUILD_DIR/classes.dex" \ | ||
"$DX" --dex --output "$BUILD_DIR/classes.dex" \ | ||
android/view/*.class \ | ||
android/content/*.class \ | ||
com/genymobile/scrcpy/*.class \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref #426
OK, I don't know which one is good practice (
/bin/bash
seems less risky to me, but why not).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends of the portability you want to have here. I do think it's a good practice for 2 major reasons:
All Linux distributions I'm aware of are compatible with the approach I described in the patch.
Some BSD-based distributions like FreeBSD doesn't support your approach. See here: https://forums.freebsd.org/threads/bash-not-found.31849/ .
The
env
binary simply search for the executable in the provided PATH environment variable, so, here, you rely on it instead of providing the full path.I didn't noticed the previous patch you referred, so if you're good with this, I can rebase and drop it.