Skip to content

Commit 1b706cc

Browse files
committed
Remove git dependency from Android version code calculation
- Replaces 'git log --oneline | wc -l' with pure qmake logic - Dev builds use fixed version code 1 (not distributed) - Release/alpha/beta/rc builds compute version code from VERSION string - Encoding: major(2) + minor(4) + patch(4) + type(1) + num(1) - Works on all platforms (Windows, macOS, Linux) without git - Works with source tarballs - Fixes issue jamulussoftware#3087
1 parent 6b7a0ad commit 1b706cc

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

Jamulus.pro

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,57 @@ win32 {
249249
} else:android {
250250
ANDROID_ABIS = armeabi-v7a arm64-v8a x86 x86_64
251251
ANDROID_VERSION_NAME = $$VERSION
252-
ANDROID_VERSION_CODE = $$system(git log --oneline | wc -l)
253-
message("Setting ANDROID_VERSION_NAME=$${ANDROID_VERSION_NAME} ANDROID_VERSION_CODE=$${ANDROID_VERSION_CODE}")
252+
253+
contains(VERSION, .*dev.*) {
254+
# Dev builds are never distributed, so version code is irrelevant
255+
# Use a fixed value to indicate "development/local build"
256+
ANDROID_VERSION_CODE = 1
257+
message("Dev build - ANDROID_VERSION_CODE set to 1 (not for distribution)")
258+
} else {
259+
# Release/alpha/beta/rc builds need reproducible version codes
260+
# Strip pre-release suffixes (both dashed and non-dashed formats)
261+
VERSION_CLEAN = $$replace(VERSION, -.*,)
262+
VERSION_CLEAN = $$replace(VERSION_CLEAN, alpha.*,)
263+
VERSION_CLEAN = $$replace(VERSION_CLEAN, beta.*,)
264+
VERSION_CLEAN = $$replace(VERSION_CLEAN, rc.*,)
265+
VERSION_CLEAN = $$replace(VERSION_CLEAN, dev.*,)
266+
267+
VERSION_PARTS = $$split(VERSION_CLEAN, .)
268+
VERSION_MAJOR = $$member(VERSION_PARTS, 0)
269+
VERSION_MINOR = $$member(VERSION_PARTS, 1)
270+
VERSION_PATCH = $$member(VERSION_PARTS, 2)
271+
272+
VERSION_TYPE = 9 # Default to release
273+
VERSION_NUM = 0
274+
275+
contains(VERSION, .*alpha.*) {
276+
VERSION_TYPE = 0
277+
VERSION_NUM = $$replace(VERSION, .*alpha\.?(\d+).*, \1)
278+
!contains(VERSION_NUM, ^[0-9]+$) { VERSION_NUM = 0 }
279+
} else:contains(VERSION, .*beta.*) {
280+
VERSION_TYPE = 5
281+
VERSION_NUM = $$replace(VERSION, .*beta\.?(\d+).*, \1)
282+
!contains(VERSION_NUM, ^[0-9]+$) { VERSION_NUM = 0 }
283+
} else:contains(VERSION, .*rc.*) {
284+
VERSION_TYPE = 8
285+
VERSION_NUM = $$replace(VERSION, .*rc\.?(\d+).*, \1)
286+
!contains(VERSION_NUM, ^[0-9]+$) { VERSION_NUM = 0 }
287+
}
288+
289+
# Ensure numeric values before using format_number
290+
!contains(VERSION_MAJOR, ^[0-9]+$) { VERSION_MAJOR = 0 }
291+
!contains(VERSION_MINOR, ^[0-9]+$) { VERSION_MINOR = 0 }
292+
!contains(VERSION_PATCH, ^[0-9]+$) { VERSION_PATCH = 0 }
293+
294+
# Calculate: major(2) + minor(2) + patch(2) + type(1) + num(1)
295+
# Max value: 99,999,999 (well below Google Play limit of 2,100,000,000)
296+
ANDROID_VERSION_CODE = $$format_number($$VERSION_MAJOR, width=2 zeropad)
297+
ANDROID_VERSION_CODE = $${ANDROID_VERSION_CODE}$$format_number($$VERSION_MINOR, width=2 zeropad)
298+
ANDROID_VERSION_CODE = $${ANDROID_VERSION_CODE}$$format_number($$VERSION_PATCH, width=2 zeropad)
299+
ANDROID_VERSION_CODE = $${ANDROID_VERSION_CODE}$${VERSION_TYPE}$${VERSION_NUM}
300+
301+
message("Release/pre-release build - ANDROID_VERSION_NAME=$${ANDROID_VERSION_NAME} ANDROID_VERSION_CODE=$${ANDROID_VERSION_CODE}")
302+
}
254303

255304
# liboboe requires C++17 for std::timed_mutex
256305
CONFIG += c++17

0 commit comments

Comments
 (0)