kernel/Makefile: check kernelsu driver version from online git repo first, if fails then check local .git and if that also fails then use hardcoded fallback

This commit is contained in:
Rifat Azad
2025-06-14 22:28:19 +06:00
committed by ShirkNeko
parent 74ec20745c
commit 00ffa86705
2 changed files with 26 additions and 12 deletions

View File

@@ -19,19 +19,33 @@ obj-$(CONFIG_KSU) += kernelsu.o
obj-$(CONFIG_KPM) += kpm/ obj-$(CONFIG_KPM) += kpm/
# .git is a text file while the module is imported by 'git submodule add'. REPO_OWNER := SukiSU-Ultra
ifeq ($(shell test -e $(srctree)/$(src)/../.git; echo $$?),0) REPO_NAME := SukiSU-Ultra
$(shell cd $(srctree)/$(src); /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin [ -f ../.git/shallow ] && git fetch --unshallow) REPO_BRANCH := main
KSU_GIT_VERSION := $(shell cd $(srctree)/$(src); /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git rev-list --count main)
# ksu_version: major * 10000 + git version + 606 for historical reasons GIT_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git
$(eval KSU_VERSION=$(shell expr 10000 + $(KSU_GIT_VERSION) + 606)) CURL_BIN := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin curl
$(info -- KernelSU version: $(KSU_VERSION))
ccflags-y += -DKSU_VERSION=$(KSU_VERSION) KSU_GITHUB_VERSION := $(shell $(CURL_BIN) -sI "https://api.github.com/repos/$(REPO_OWNER)/$(REPO_NAME)/commits?sha=$(REPO_BRANCH)&per_page=1" | grep -i "link:" | sed -n 's/.*page=\([0-9]*\)>; rel="last".*/\1/p')
else # If there is no .git file, the default version will be passed.
$(warning "KSU_GIT_VERSION not defined! It is better to make KernelSU a git submodule!") ifeq ($(KSU_GITHUB_VERSION),)
ccflags-y += -DKSU_VERSION=16 ifeq ($(shell test -e $(srctree)/$(src)/../.git; echo $$?),0)
$(shell cd $(srctree)/$(src); [ -f ../.git/shallow ] && $(GIT_BIN) fetch --unshallow)
KSU_LOCAL_VERSION := $(shell cd $(srctree)/$(src); $(GIT_BIN) rev-list --count HEAD)
$(eval KSU_VERSION := $(shell expr 10000 + $(KSU_LOCAL_VERSION) + 700))
$(info -- SukiSU-Ultra version (local .git): $(KSU_VERSION))
else
$(eval KSU_VERSION := 13000)
$(warning -- Could not fetch version online or via local .git! Using fallback version: $(KSU_VERSION))
endif
else
$(eval KSU_VERSION := $(shell expr 10000 + $(KSU_GITHUB_VERSION) + 700))
$(info -- SukiSU-Ultra version (GitHub): $(KSU_VERSION))
endif endif
$(info -- SukiSU-Ultra version: $(KSU_VERSION))
ccflags-y += -DKSU_VERSION=$(KSU_VERSION)
ifndef KSU_EXPECTED_SIZE ifndef KSU_EXPECTED_SIZE
KSU_EXPECTED_SIZE := 0x35c KSU_EXPECTED_SIZE := 0x35c
endif endif

View File

@@ -32,7 +32,7 @@ val androidCompileSdkVersion = 36
val androidCompileNdkVersion = "28.0.13004108" val androidCompileNdkVersion = "28.0.13004108"
val androidSourceCompatibility = JavaVersion.VERSION_21 val androidSourceCompatibility = JavaVersion.VERSION_21
val androidTargetCompatibility = JavaVersion.VERSION_21 val androidTargetCompatibility = JavaVersion.VERSION_21
val managerVersionCode by extra(1 * 10000 + getGitCommitCount() + 606) val managerVersionCode by extra(1 * 10000 + getGitCommitCount() + 700)
val managerVersionName by extra(getGitDescribe()) val managerVersionName by extra(getGitDescribe())
fun getGitCommitCount(): Int { fun getGitCommitCount(): Int {