1 changed files with 42 additions and 13 deletions
@ -1,45 +1,74 @@
@@ -1,45 +1,74 @@
|
||||
#!/usr/bin/env bash |
||||
|
||||
# git tag is in the form vX.Y.Z for builds from tagged commit |
||||
# git tag is in the form vX.Y.Z-1234-gSHA for builds from non-tagged commit |
||||
|
||||
# Strip the 'v' from the beginning of the tag |
||||
VERSIONNAME=`git describe --always --tags | sed -e 's/^v//'` |
||||
echo "tag $VERSIONNAME" |
||||
|
||||
# Android versionCode from git tag vX.Y.Z-123-gSHA |
||||
# Change all occurences of '-' in tag to '.' and separate into parts |
||||
IFS=. read major minor patch dev sha <<<"${VERSIONNAME//-/.}" |
||||
VERSIONCODE=$(($major*100000)) |
||||
VERSIONCODE=$(($(($minor*10000)) + $VERSIONCODE)) |
||||
echo "major:$major minor:$minor patch:$patch dev:$dev sha:$sha" |
||||
|
||||
# Max Android version code is 2100000000. Version codes must increase with each release and the |
||||
# version codes for multiple apks for the same release must be unique and not collide as well. |
||||
# All of this makes it next to impossible to create a rational system of building a version code |
||||
# from a semantic version without imposing some strict restrictions. |
||||
if [ $major -gt 9 ]; then |
||||
echo "Error: Major version larger than 1 digit: $major" |
||||
exit 1 |
||||
fi |
||||
if [ $minor -gt 9 ]; then |
||||
echo "Error: Minor version larger than 1 digit: $minor" |
||||
exit 1 |
||||
fi |
||||
if [ $patch -gt 99 ]; then |
||||
echo "Error: Patch version larger than 2 digits: $patch" |
||||
exit 1 |
||||
fi |
||||
if [ $dev -gt 999 ]; then |
||||
echo "Error: Dev version larger than 3 digits: $dev" |
||||
exit 1 |
||||
fi |
||||
|
||||
# Version code format: BBMIPPDDD (B=Bitness, I=Minor) |
||||
VERSIONCODE=$(($major*1000000)) |
||||
VERSIONCODE=$(($(($minor*100000)) + $VERSIONCODE)) |
||||
VERSIONCODE=$(($(($patch*1000)) + $VERSIONCODE)) |
||||
VERSIONCODE=$(($(($dev)) + $VERSIONCODE)) |
||||
|
||||
# The 32 bit and 64 bit APKs each need there own version code. |
||||
# The 32 bit and 64 bit APKs each need there own version code unique version code |
||||
if [ "$1" = "32" ]; then |
||||
VERSIONCODE=330$VERSIONCODE |
||||
VERSIONCODE=34$VERSIONCODE |
||||
else |
||||
VERSIONCODE=650$VERSIONCODE |
||||
VERSIONCODE=66$VERSIONCODE |
||||
fi |
||||
|
||||
MANIFEST_FILE=android/AndroidManifest.xml |
||||
|
||||
# manifest package |
||||
if [ "$2" = "master" ]; then |
||||
echo "Adjusting package name for daily build" |
||||
QGC_PKG_NAME="org.mavlink.qgroundcontrolbeta" |
||||
sed -i -e 's/package *= *"[^"]*"/package="'$QGC_PKG_NAME'"/' $MANIFEST_FILE |
||||
echo "Android package name: $QGC_PKG_NAME" |
||||
fi |
||||
|
||||
# android:versionCode |
||||
if [ -n "$VERSIONCODE" ]; then |
||||
echo "Android versionCode: ${VERSIONCODE}" |
||||
sed -i -e "s/android:versionCode=\"[0-9][0-9]*\"/android:versionCode=\"$VERSIONCODE\"/" $MANIFEST_FILE |
||||
echo "Android version: ${VERSIONCODE}" |
||||
else |
||||
echo "Error versionCode empty" |
||||
exit 0 # don't cause the build to fail |
||||
echo "Error: versionCode empty" |
||||
exit 1 |
||||
fi |
||||
|
||||
# android:versionName |
||||
if [ -n "$VERSIONNAME" ]; then |
||||
echo "Android versionName: ${VERSIONNAME}" |
||||
sed -i -e 's/versionName *= *"[^"]*"/versionName="'$VERSIONNAME'"/' $MANIFEST_FILE |
||||
echo "Android name: ${VERSIONNAME}" |
||||
else |
||||
echo "Error versionName empty" |
||||
exit 0 # don't cause the build to fail |
||||
echo "Error: versionName empty" |
||||
exit 1 |
||||
fi |
||||
|
||||
|
Loading…
Reference in new issue