Skip to content

Commit e7325f7

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 c7b1362 commit e7325f7

File tree

5 files changed

+45
-80
lines changed

5 files changed

+45
-80
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: 22 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: 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: 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,13 @@ 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 $(wildcard .git/HEAD)
131+
$(shell ./tool/go run tailscale.com/cmd/mkversion > tailscale.version)
132+
133+
.PHONY: version
134+
version: tailscale.version ## print the current version information
135+
cat tailscale.version
136+
144137
#
145138
# Go Builds:
146139
#
@@ -154,10 +147,10 @@ $(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum
154147
$(GOBIN)/gobind: go.mod go.sum
155148
./tool/go install golang.org/x/mobile/cmd/gobind
156149

157-
$(LIBTAILSCALE): Makefile android/libs $(shell find libtailscale -name *.go) go.mod go.sum $(GOBIN)/gomobile
150+
$(LIBTAILSCALE): Makefile android/libs $(shell find libtailscale -name *.go) go.mod go.sum $(GOBIN)/gomobile tailscale.version
158151
$(GOBIN)/gomobile bind -target android -androidapi 26 \
159152
-tags "$$(./build-tags.sh)" \
160-
-ldflags "$(FULL_LDFLAGS)" \
153+
-ldflags "-w $$(./version-ldflags.sh)" \
161154
-o $@ ./libtailscale
162155

163156
.PHONY: libtailscale
@@ -202,29 +195,25 @@ androidpath:
202195
@echo 'export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH'
203196

204197
.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}"
198+
tag_release: tailscale.version ## Tag the current commit with the current version
199+
source tailscale.version && git tag -a "$${VERSION_LONG}" -m "OSS and Version updated to $${VERSION_LONG}"
207200

208201

209202
.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}"
203+
bumposs: update-oss tailscale.version
204+
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
205+
source tailscale.version && git tag -a "$${VERSION_LONG}" -m "OSS and Version updated to $${VERSION_LONG}"
213206

214207
.PHONY: bump_version_code
215208
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
209+
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
221210

222211
.PHONY: update-oss
223-
update-oss: ## Update the tailscale.com go module and update the version in build.gradle
212+
update-oss: ## Update the tailscale.com go module
224213
GOPROXY=direct ./tool/go get tailscale.com@main
214+
./tool/go mod tidy -compat=1.23
225215
./tool/go run tailscale.com/cmd/printdep --go > go.toolchain.rev.new
226216
mv go.toolchain.rev.new go.toolchain.rev
227-
./tool/go mod tidy -compat=1.23
228217

229218
# Get the commandline tools package, this provides (among other things) the sdkmanager binary.
230219
$(ANDROID_HOME)/cmdline-tools/latest/bin/sdkmanager:
@@ -310,13 +299,13 @@ docker-remove-shell-image: ## Removes all docker shell image
310299
docker rmi --force tailscale-android-shell-amd64
311300

312301
.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.
302+
clean: clean-tailscale.version ## Remove build artifacts. Does not purge docker build envs. Use dockerRemoveEnv for that.
315303
@echo "Cleaning up old build artifacts"
316304
-rm -rf android/build $(DEBUG_APK) $(RELEASE_AAB) $(RELEASE_TV_AAB) $(LIBTAILSCALE) android/libs *.apk *.aab
317305
@echo "Cleaning cached toolchain"
318306
-rm -rf $(HOME)/.cache/tailscale-go{,.extracted}
319307
-pkill -f gradle
308+
-rm tailscale.version
320309

321310
.PHONY: help
322311
help: ## Show this help

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.44-tc0a1ed86c-gcafb114ae0a"
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
@@ -182,3 +182,13 @@ def getLocalProperty(key, defaultValue) {
182182
return defaultValue
183183
}
184184
}
185+
186+
187+
def getVersionProperty(key) {
188+
// tailscale.version is created / updated by the makefile, it is in a loosely
189+
// Makfile/envfile format, which is also loosely a properties file format.
190+
// make tailscale.version
191+
def versionProps = new Properties()
192+
versionProps.load(project.file('../tailscale.version').newDataInputStream())
193+
return versionProps.getProperty(key).replaceAll('^\"|\"$', '')
194+
}

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)