From d56193f90cef30a90b18a47acba538dbc0698650 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 22 Jun 2020 21:51:12 +0200 Subject: [PATCH] Makefile,mkversion.sh: set tailscale versions at build time While here, set the gradle versionName from the Makefile as well. Updates tailscale/tailscale#486 Signed-off-by: Elias Naur --- Makefile | 13 ++++-- android/build.gradle | 2 +- mkversion.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100755 mkversion.sh diff --git a/Makefile b/Makefile index 94c9fd4..b807e93 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,29 @@ +# Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + DEBUG_APK=tailscale-debug.apk RELEASE_AAB=tailscale-release.aab APPID=com.tailscale.ipn AAR=android/libs/ipn.aar KEYSTORE=tailscale.jks KEYSTORE_ALIAS=tailscale +GIT_DESCRIBE=$(shell git describe --tags --long) +VERSION_LONG=$(shell ./mkversion.sh long $(GIT_DESCRIBE)) +VERSION_SHORT=$(shell ./mkversion.sh short $(GIT_DESCRIBE)) all: $(APK) aar: mkdir -p android/libs - go run gioui.org/cmd/gogio -buildmode archive -target android -appid $(APPID) -o $(AAR) github.com/tailscale/tailscale-android/cmd/tailscale + go run gioui.org/cmd/gogio -ldflags "-X tailscale.com/version.LONG=$(VERSION_LONG) -X tailscale.com/version.SHORT=$(VERSION_SHORT)" -tags xversion -buildmode archive -target android -appid $(APPID) -o $(AAR) github.com/tailscale/tailscale-android/cmd/tailscale $(DEBUG_APK): aar - (cd android && ./gradlew assembleDebug) + (cd android && VERSION_LONG=$(VERSION_LONG) ./gradlew assembleDebug) mv android/build/outputs/apk/debug/android-debug.apk $@ $(RELEASE_AAB): aar - (cd android && ./gradlew bundleRelease) + (cd android && VERSION_LONG=$(VERSION_LONG) ./gradlew bundleRelease) mv ./android/build/outputs/bundle/release/android-release.aab $@ release: $(RELEASE_AAB) diff --git a/android/build.gradle b/android/build.gradle index b3fbe60..fe51adb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -35,7 +35,7 @@ android { minSdkVersion 23 targetSdkVersion 29 versionCode 8 - versionName getVersionName() + versionName System.getenv("VERSION_LONG") } compileOptions { sourceCompatibility 1.8 diff --git a/mkversion.sh b/mkversion.sh new file mode 100755 index 0000000..0a8685b --- /dev/null +++ b/mkversion.sh @@ -0,0 +1,97 @@ +#!/bin/sh + +# Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +set -eu + +mode=$1 +describe=$2 + +long() { + ver="${describe#v}" + stem="${ver%%-*}" + case "$stem" in + *.*.*) + # Full SemVer, nothing to do. + semver="${stem}" + ;; + *.*) + # Old style major.minor, add a .0 + semver="${stem}.0" + ;; + *) + echo "Unparseable version $stem" >&2 + exit 1 + ;; + esac + suffix="${ver#$stem}" + case "$suffix" in + -*-*) + # Has a change count in addition to the commit hash. + ;; + -*) + # Missing change count, add one. + suffix="-0${suffix}" + ;; + *) + echo "Unexpected version suffix" >&2 + exit 1 + esac + echo "${semver}${suffix}" +} + +short() { + ver="$(long)" + case "$ver" in + *-*-*) + echo "${ver%-*}" + ;; + *-*) + echo "$ver" + ;; + *) + echo "Long version in invalid format" >&2 + exit 1 + ;; + esac +} + +xcode() { + ver=$(short | sed -e 's/-/./') + major=$(echo "$ver" | cut -f1 -d.) + minor=$(echo "$ver" | cut -f2 -d.) + patch=$(echo "$ver" | cut -f3 -d.) + changecount=$(echo "$ver" | cut -f4 -d.) + + # Apple version numbers must be major.minor.patch. We have 4 fields + # because we need major.minor.patch for go module compatibility, and + # changecount for automatic version numbering of unstable builds. To + # resolve this, for Apple builds, we combine changecount into patch: + patch=$((patch*10000 + changecount)) + + # CFBundleShortVersionString: the "short name" used in the App Store. + # eg. 0.92.98 + echo "VERSION_NAME = $major.$minor.$patch" + # CFBundleVersion: the build number. Needs to be 3 numeric sections + # that increment for each release according to SemVer rules. + # + # We start counting at 100 because we submitted using raw build + # numbers before, and Apple doesn't let you start over. + # e.g. 0.98.3-123 -> 100.98.3123 + major=$((major + 100)) + echo "VERSION_ID = $major.$minor.$patch" +} + +case "$mode" in + long) + long + ;; + short) + short + ;; + xcode) + xcode + ;; +esac