Skip to content

Commit 5bc9fc0

Browse files
committed
Makefile,*: use tailscale.com/cmd/mkversion
We've suffered misalignment in versioning and toolchain usage due to the shell invocations downstream of ./version/tailscale-version.sh, but also the whole version data scheme in the Makefile was quite complicated, and required synchronization in the build.grade. - Makfile no longer needs to be version aware itself. - A Makefile target tailscale.version refreshes a local cached output from tailscale.com/cmd/mkversion which is updated when go.mod / go.sum change. - build.gradle loads tailscale.version to get the version string. - ldflags are produced from tailscale.version via version-ldflags.sh Updates tailscale/tailscale#13850 Signed-off-by: James Tucker <[email protected]>
1 parent 2e9f6b7 commit 5bc9fc0

File tree

7 files changed

+50
-83
lines changed

7 files changed

+50
-83
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ tailscale.jks
3838
libtailscale.aar
3939
libtailscale-sources.jar
4040
.DS_Store
41+
42+
tailscale.version

Makefile

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,7 @@ DEBUG_APK=tailscale-debug.apk
1717
RELEASE_AAB=tailscale-release.aab
1818
RELEASE_TV_AAB=tailscale-tv-release.aab
1919
LIBTAILSCALE=android/libs/libtailscale.aar
20-
TAILSCALE_VERSION=$(shell ./version/tailscale-version.sh 200)
21-
OUR_VERSION=$(shell git describe --dirty --exclude "*" --always --abbrev=200)
22-
TAILSCALE_VERSION_ABBREV=$(shell ./version/tailscale-version.sh 11)
23-
OUR_VERSION_ABBREV=$(shell git describe --exclude "*" --always --abbrev=11)
24-
VERSION_LONG=$(TAILSCALE_VERSION_ABBREV)-g$(OUR_VERSION_ABBREV)
25-
# Extract the long version build.gradle's versionName and strip quotes.
26-
VERSIONNAME=$(patsubst "%",%,$(lastword $(shell grep versionName android/build.gradle)))
27-
# Extract the x.y.z part for the short version.
28-
VERSIONNAME_SHORT=$(shell echo $(VERSIONNAME) | cut -d - -f 1)
29-
TAILSCALE_COMMIT=$(shell echo $(TAILSCALE_VERSION) | cut -d - -f 2 | cut -d t -f 2)
3020
# Extract the version code from build.gradle.
31-
VERSIONCODE=$(lastword $(shell grep versionCode android/build.gradle))
32-
VERSIONCODE_PLUSONE=$(shell expr $(VERSIONCODE) + 1)
33-
VERSION_LDFLAGS=-X tailscale.com/version.longStamp=$(VERSIONNAME) -X tailscale.com/version.shortStamp=$(VERSIONNAME_SHORT) -X tailscale.com/version.gitCommitStamp=$(TAILSCALE_COMMIT) -X tailscale.com/version.extraGitCommitStamp=$(OUR_VERSION)
34-
FULL_LDFLAGS=$(VERSION_LDFLAGS) -w
3521
ifeq ($(shell uname),Linux)
3622
ANDROID_TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip"
3723
ANDROID_TOOLS_SUM="bd1aa17c7ef10066949c88dc6c9c8d536be27f992a1f3b5a584f9bd2ba5646a0 commandlinetools-linux-9477386_latest.zip"
@@ -111,17 +97,17 @@ tailscale-debug: $(DEBUG_APK) ## Build the debug APK
11197

11298
# Builds the release AAB and signs it (phone/tablet/chromeOS variant)
11399
.PHONY: release
114-
release: update-version jarsign-env $(RELEASE_AAB) ## Build the release AAB
100+
release: clean-tailscale.version jarsign-env $(RELEASE_AAB) ## Build the release AAB
115101
@jarsigner -sigalg SHA256withRSA -digestalg SHA-256 -keystore $(JKS_PATH) -storepass $(JKS_PASSWORD) $(RELEASE_AAB) tailscale
116102

117103
# Builds the release AAB and signs it (androidTV variant)
118104
.PHONY: release-tv
119-
release-tv: update-version jarsign-env $(RELEASE_TV_AAB) ## Build the release AAB
105+
release-tv: clean-tailscale.version jarsign-env $(RELEASE_TV_AAB) ## Build the release AAB
120106
@jarsigner -sigalg SHA256withRSA -digestalg SHA-256 -keystore $(JKS_PATH) -storepass $(JKS_PASSWORD) $(RELEASE_TV_AAB) tailscale
121107

122108
# gradle-dependencies groups together the android sources and libtailscale needed to assemble tests/debug/release builds.
123109
.PHONY: gradle-dependencies
124-
gradle-dependencies: $(shell find android -type f -not -path "android/build/*" -not -path '*/.*') $(LIBTAILSCALE)
110+
gradle-dependencies: $(shell find android -type f -not -path "android/build/*" -not -path '*/.*') $(LIBTAILSCALE) tailscale.version
125111

126112
$(DEBUG_APK): gradle-dependencies
127113
(cd android && ./gradlew test assembleDebug)
@@ -141,6 +127,12 @@ tailscale-test.apk: gradle-dependencies
141127
(cd android && ./gradlew assembleApplicationTestAndroidTest)
142128
install -C ./android/build/outputs/apk/androidTest/applicationTest/android-applicationTest-androidTest.apk $@
143129

130+
tailscale.version: go.mod go.sum .git/HEAD
131+
$(shell ./tool/go run tailscale.com/cmd/mkversion > tailscale.version)
132+
133+
version: tailscale.version ## print the current version information
134+
cat tailscale.version
135+
144136
#
145137
# Go Builds:
146138
#
@@ -154,10 +146,10 @@ $(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum
154146
$(GOBIN)/gobind: go.mod go.sum
155147
./tool/go install golang.org/x/mobile/cmd/gobind
156148

157-
$(LIBTAILSCALE): Makefile android/libs $(shell find libtailscale -name *.go) go.mod go.sum $(GOBIN)/gomobile
149+
$(LIBTAILSCALE): Makefile android/libs $(shell find libtailscale -name *.go) go.mod go.sum $(GOBIN)/gomobile tailscale.version
158150
$(GOBIN)/gomobile bind -target android -androidapi 26 \
159151
-tags "$$(./build-tags.sh)" \
160-
-ldflags "$(FULL_LDFLAGS)" \
152+
-ldflags "-w $$(./version-ldflags.sh)" \
161153
-o $@ ./libtailscale
162154

163155
.PHONY: libtailscale
@@ -202,29 +194,25 @@ androidpath:
202194
@echo 'export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH'
203195

204196
.PHONY: tag_release
205-
tag_release: ## Tag the current commit with the current version
206-
git tag -a "$(VERSION_LONG)" -m "OSS and Version updated to ${VERSION_LONG}"
197+
tag_release: tailscale.version ## Tag the current commit with the current version
198+
source tailscale.version && git tag -a "$${VERSION_LONG}" -m "OSS and Version updated to $${VERSION_LONG}"
207199

208200

209201
.PHONY: bumposs ## Bump to the latest oss and update the versions.
210-
bumposs: update-oss update-version
211-
git commit -sm "android: bump OSS" -m "OSS and Version updated to ${VERSION_LONG}" go.toolchain.rev android/build.gradle go.mod go.sum
212-
git tag -a "$(VERSION_LONG)" -m "OSS and Version updated to ${VERSION_LONG}"
202+
bumposs: update-oss tailscale.version
203+
source tailscale.version && git commit -sm "android: bump OSS" -m "OSS and Version updated to $${VERSION_LONG}" go.toolchain.rev android/build.gradle go.mod go.sum
204+
source tailscale.version && git tag -a "$${VERSION_LONG}" -m "OSS and Version updated to $${VERSION_LONG}"
213205

214206
.PHONY: bump_version_code
215207
bump_version_code: ## Bump the version code in build.gradle
216-
sed -i'.bak' 's/versionCode .*/versionCode $(VERSIONCODE_PLUSONE)/' android/build.gradle && rm android/build.gradle.bak
217-
218-
.PHONY: update-version
219-
update-version: ## Update the version in build.gradle
220-
sed -i'.bak' 's/versionName .*/versionName "$(VERSION_LONG)"/' android/build.gradle && rm android/build.gradle.bak
208+
sed -i'.bak' "s/versionCode .*/versionCode $$(expr $$(awk '/versionCode ([0-9]+)/{print $$2}' android/build.gradle) + 1)/" android/build.gradle && rm android/build.gradle.bak
221209

222210
.PHONY: update-oss
223-
update-oss: ## Update the tailscale.com go module and update the version in build.gradle
211+
update-oss: ## Update the tailscale.com go module
224212
GOPROXY=direct ./tool/go get tailscale.com@main
213+
./tool/go mod tidy -compat=1.23
225214
./tool/go run tailscale.com/cmd/printdep --go > go.toolchain.rev.new
226215
mv go.toolchain.rev.new go.toolchain.rev
227-
./tool/go mod tidy -compat=1.23
228216

229217
# Get the commandline tools package, this provides (among other things) the sdkmanager binary.
230218
$(ANDROID_HOME)/cmdline-tools/latest/bin/sdkmanager:
@@ -309,9 +297,12 @@ docker-shell: ## Builds a docker image with the android build env and opens a sh
309297
docker-remove-shell-image: ## Removes all docker shell image
310298
docker rmi --force tailscale-android-shell-amd64
311299

300+
.PHONY: clean-taislcale.version
301+
clean-tailscale.version: ## Remove the tailscale.version file
302+
rm tailscale.version
303+
312304
.PHONY: clean
313-
clean: ## Remove build artifacts. Does not purge docker build envs. Use dockerRemoveEnv for that.
314-
clean: ## Remove build artifacts. Does not purge docker build envs. Use dockerRemoveEnv for that.
305+
clean: clean-tailscale.version ## Remove build artifacts. Does not purge docker build envs. Use dockerRemoveEnv for that.
315306
@echo "Cleaning up old build artifacts"
316307
-rm -rf android/build $(DEBUG_APK) $(RELEASE_AAB) $(RELEASE_TV_AAB) $(LIBTAILSCALE) android/libs *.apk *.aab
317308
@echo "Cleaning cached toolchain"

android/build.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ android {
3838
minSdkVersion 26
3939
targetSdkVersion 34
4040
versionCode 241
41-
versionName "1.77.12-ta8f9c0d6e-g753b8d3fb4b"
41+
versionName getVersionProperty("VERSION_LONG")
4242

4343
// This setting, which defaults to 'true', will cause Tailscale to fall
4444
// back to the Google DNS servers if it cannot determine what the
@@ -181,3 +181,13 @@ def getLocalProperty(key, defaultValue) {
181181
return defaultValue
182182
}
183183
}
184+
185+
186+
def getVersionProperty(key) {
187+
// tailscale.version is created / updated by the makefile, it is in a loosely
188+
// Makfile/envfile format, which is also loosely a properties file format.
189+
// make tailscale.version
190+
def versionProps = new Properties()
191+
versionProps.load(project.file('../tailscale.version').newDataInputStream())
192+
return versionProps.getProperty(key).replaceAll('^\"|\"$', '')
193+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/tailscale/wireguard-go v0.0.0-20240905161824-799c1978fafc
77
golang.org/x/mobile v0.0.0-20240806205939-81131f6468ab
88
inet.af/netaddr v0.0.0-20220617031823-097006376321
9-
tailscale.com v1.75.0-pre.0.20241014151013-a8f9c0d6e40a
9+
tailscale.com v1.75.0-pre.0.20241018175349-bb60da276468
1010
)
1111

1212
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,5 @@ inet.af/netaddr v0.0.0-20220617031823-097006376321 h1:B4dC8ySKTQXasnjDTMsoCMf1sQ
256256
inet.af/netaddr v0.0.0-20220617031823-097006376321/go.mod h1:OIezDfdzOgFhuw4HuWapWq2e9l0H9tK4F1j+ETRtF3k=
257257
software.sslmate.com/src/go-pkcs12 v0.4.0 h1:H2g08FrTvSFKUj+D309j1DPfk5APnIdAQAB8aEykJ5k=
258258
software.sslmate.com/src/go-pkcs12 v0.4.0/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI=
259-
tailscale.com v1.75.0-pre.0.20241014151013-a8f9c0d6e40a h1:nGLKfmPOA8dmMqGUjBDIaUD4RkXo+QpP3TXoAKVwvHU=
260-
tailscale.com v1.75.0-pre.0.20241014151013-a8f9c0d6e40a/go.mod h1:myCwmhYBvMCF/5OgBYuIW42zscuEo30bAml7wABVZLk=
259+
tailscale.com v1.75.0-pre.0.20241018175349-bb60da276468 h1:/gmZCsZi5IDP7TsYBfoLdl2/iomYzXoDcj+16/TuBgA=
260+
tailscale.com v1.75.0-pre.0.20241018175349-bb60da276468/go.mod h1:myCwmhYBvMCF/5OgBYuIW42zscuEo30bAml7wABVZLk=

version-ldflags.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
source tailscale.version || echo >&2 "no tailscale.version file found"
4+
if [[ -z "${VERSION_LONG}" ]]; then
5+
exit 1
6+
fi
7+
echo "-X tailscale.com/version.longStamp=${VERSION_LONG}"
8+
echo "-X tailscale.com/version.shortStamp=${VERSION_SHORT}"
9+
echo "-X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}"
10+
echo "-X tailscale.com/version.extraGitCommitStamp=${VERSION_EXTRA_HASH}"

version/tailscale-version.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)