-
Notifications
You must be signed in to change notification settings - Fork 23.4k
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
[pytorch] consolidate android gradle build scripts #39999
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e99b20
[pytorch] consolidate android gradle build scripts
ljk53 514403e
Update on "[pytorch] consolidate android gradle build scripts"
ljk53 6a47b6b
Update on "[pytorch] consolidate android gradle build scripts"
ljk53 4f9b9d1
Update on "[pytorch] consolidate android gradle build scripts"
ljk53 1f597a0
Update on "[pytorch] consolidate android gradle build scripts"
ljk53 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/bash | ||
set -eux | ||
|
||
############################################################################## | ||
# Common util functions for Android build scripts. | ||
############################################################################## | ||
|
||
if [ -z "$PYTORCH_DIR" ]; then | ||
echo "PYTORCH_DIR not set!" | ||
exit 1 | ||
fi | ||
|
||
check_android_sdk() { | ||
if [ -z "$ANDROID_HOME" ]; then | ||
echo "ANDROID_HOME not set; please set it to Android sdk directory" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -d $ANDROID_HOME ]; then | ||
echo "ANDROID_HOME not a directory; did you install it under $ANDROID_HOME?" | ||
exit 1 | ||
fi | ||
echo "ANDROID_HOME:$ANDROID_HOME" | ||
} | ||
|
||
check_gradle() { | ||
GRADLE_PATH=gradle | ||
GRADLE_NOT_FOUND_MSG="Unable to find gradle, please add it to PATH or set GRADLE_HOME" | ||
|
||
if [ ! -x "$(command -v gradle)" ]; then | ||
if [ -z "$GRADLE_HOME" ]; then | ||
echo GRADLE_NOT_FOUND_MSG | ||
exit 1 | ||
fi | ||
GRADLE_PATH=$GRADLE_HOME/bin/gradle | ||
if [ ! -f "$GRADLE_PATH" ]; then | ||
echo GRADLE_NOT_FOUND_MSG | ||
exit 1 | ||
fi | ||
fi | ||
echo "GRADLE_PATH:$GRADLE_PATH" | ||
} | ||
|
||
parse_abis_list() { | ||
ABIS_LIST="armeabi-v7a,arm64-v8a,x86,x86_64" | ||
CUSTOM_ABIS_LIST=false | ||
if [ $# -gt 0 ]; then | ||
ABIS_LIST=$1 | ||
CUSTOM_ABIS_LIST=true | ||
fi | ||
|
||
echo "ABIS_LIST:$ABIS_LIST" | ||
echo "CUSTOM_ABIS_LIST:$CUSTOM_ABIS_LIST" | ||
} | ||
|
||
build_android() { | ||
PYTORCH_ANDROID_DIR=$PYTORCH_DIR/android | ||
BUILD_ROOT=${BUILD_ROOT:-$PYTORCH_DIR} | ||
echo "BUILD_ROOT:$BUILD_ROOT" | ||
|
||
LIB_DIR=$PYTORCH_ANDROID_DIR/pytorch_android/src/main/jniLibs | ||
INCLUDE_DIR=$PYTORCH_ANDROID_DIR/pytorch_android/src/main/cpp/libtorch_include | ||
|
||
# These directories only contain symbolic links. | ||
rm -rf $LIB_DIR && mkdir -p $LIB_DIR | ||
rm -rf $INCLUDE_DIR && mkdir -p $INCLUDE_DIR | ||
|
||
for abi in $(echo $ABIS_LIST | tr ',' '\n') | ||
do | ||
echo "abi:$abi" | ||
ANDROID_BUILD_ROOT=$BUILD_ROOT/build_android_$abi | ||
ANDROID_ABI=$abi BUILD_ROOT=$ANDROID_BUILD_ROOT $PYTORCH_DIR/scripts/build_android.sh -DANDROID_CCACHE=$(which ccache) | ||
|
||
echo "$abi build output lib,include at $ANDROID_BUILD_ROOT/install" | ||
ln -s $ANDROID_BUILD_ROOT/install/lib $LIB_DIR/$abi | ||
ln -s $ANDROID_BUILD_ROOT/install/include $INCLUDE_DIR/$abi | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,42 +4,10 @@ set -eux | |
PYTORCH_DIR="$(cd $(dirname $0)/..; pwd -P)" | ||
PYTORCH_ANDROID_DIR=$PYTORCH_DIR/android | ||
|
||
echo "ANDROID_HOME:$ANDROID_HOME" | ||
if [ ! -z "$ANDROID_HOME" ]; then | ||
echo "ANDROID_HOME not set; please set it to Android sdk directory" | ||
fi | ||
|
||
if [ ! -d $ANDROID_HOME ]; then | ||
echo "ANDROID_HOME not a directory; did you install it under $ANDROID_HOME?" | ||
exit 1 | ||
fi | ||
|
||
echo "ANDROID_NDK:$ANDROID_NDK" | ||
if [ ! -z "$ANDROID_NDK" ]; then | ||
echo "ANDROID_NDK not set; please set it to Android sdk directory" | ||
fi | ||
|
||
if [ ! -d $ANDROID_NDK ]; then | ||
echo "ANDROID_NDK not a directory; did you install it under $ANDROID_NDK?" | ||
exit 1 | ||
fi | ||
|
||
GRADLE_PATH=gradle | ||
GRADLE_NOT_FOUND_MSG="Unable to find gradle, please add it to PATH or set GRADLE_HOME" | ||
|
||
if [ ! -x "$(command -v gradle)" ]; then | ||
if [ -z "$GRADLE_HOME" ]; then | ||
echo GRADLE_NOT_FOUND_MSG | ||
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. We were missing "$" here - fixed in the new revision as well. |
||
exit 1 | ||
fi | ||
GRADLE_PATH=$GRADLE_HOME/bin/gradle | ||
if [ ! -f "$GRADLE_PATH" ]; then | ||
echo GRADLE_NOT_FOUND_MSG | ||
exit 1 | ||
fi | ||
fi | ||
echo "GRADLE_PATH:$GRADLE_PATH" | ||
source $PYTORCH_ANDROID_DIR/common.sh | ||
|
||
check_android_sdk | ||
check_gradle | ||
|
||
# Run android instrumented tests on x86 emulator | ||
|
||
|
@@ -70,7 +38,7 @@ cat <<- EOF | |
$ANDROID_HOME/platform-tools/adb devices | ||
|
||
If everything is ok the output will be: | ||
|
||
List of devices attached | ||
emulator-5554 device | ||
EOF | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be
if [ -z
instead ofif [ ! -z
. It's fixed in the master build script but not here - consolidating these functions can avoid this type of inconsistency.