Skip to content

Commit a282d24

Browse files
hmtheboy154rsuntk
authored andcommitted
kernel: check for remote url instead of .git existence
Current implementation of .git checking have some issues: - If a kernel source being cloned using git-repo tool, especially newer version, it will clone .git in .repo inside of the submodule source. - Newer kernel source changed how $(src) & $(srctree) output. In the case of kernel 6.11 as I tested $(src) show the relative path of the symlink in drivers/ instead of KernelSU main directory. Which makes checking for ../.git existence comletely useless. One idea I would like to propose is to check for the remote URL in $(src). If the remote is correct then we can assume this is KSU repo and then count the version (also unshallow the repo). Here's what I did: - Check if kernel is 6.9+ and then change $(src) accordingly. - Print $(src) remote in verbose and check for the correct URL (both ssh & https). - If correct, check if the repo is shallow by using git rev-parse --is-shallow-repository. Unshallow if it's return true. - Calculate version as usual. The only drawback I can see so far is that forks will have to edit the url in the Makefile, which I don't think it's much of an issue. * Unmerged PR: tiann#2102 Signed-off-by: hmtheboy154 <[email protected]> Signed-off-by: Faris <[email protected]>
1 parent dd8389d commit a282d24

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

kernel/Makefile

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,39 @@ ccflags-y += -I$(objtree)/security/selinux -include $(srctree)/include/uapi/asm-
1717

1818
obj-$(CONFIG_KSU) += kernelsu.o
1919

20-
# .git is a text file while the module is imported by 'git submodule add'.
21-
ifeq ($(shell test -e $(srctree)/$(src)/../.git; echo $$?),0)
22-
$(shell cd $(srctree)/$(src); /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin [ -f ../.git/shallow ] && git fetch --unshallow)
23-
KSU_GIT_VERSION := $(shell cd $(srctree)/$(src); /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git rev-list --count HEAD)
20+
IS_KERNEL_69 := $(strip $(shell \
21+
if [ "$(VERSION)" -ge "6" -a "$(PATCHLEVEL)" -ge "9" ]; then \
22+
echo TRUE; \
23+
else \
24+
echo FALSE; \
25+
fi \
26+
))
27+
28+
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b1992c3772e69a6fd0e3fc81cd4d2820c8b6eca0
29+
ifeq ($(IS_KERNEL_69),TRUE)
30+
SRC_LOCATION := $(src)
31+
else
32+
SRC_LOCATION := $(srctree)/$(src)
33+
endif
34+
35+
GIT_TOOL := /usr/bin/env PATH="$$PATH":/usr/bin:/usr/local/bin git
36+
37+
# Check for both https & ssh remote
38+
REMOTE_CHECK := $(shell cd $(SRC_LOCATION); $(GIT_TOOL) remote -v | grep -E 'github\.com[/:]tiann/KernelSU')
39+
40+
ifneq ($(REMOTE_CHECK),)
41+
ifeq ($(shell cd $(SRC_LOCATION); $(GIT_TOOL) rev-parse --is-shallow-repository),true)
42+
$(shell cd $(SRC_LOCATION); $(GIT_TOOL) fetch --unshallow)
43+
endif
44+
KSU_GIT_VERSION := $(shell cd $(SRC_LOCATION); $(GIT_TOOL) rev-list --count HEAD)
2445
# ksu_version: major * 10000 + git version + 200 for historical reasons
2546
$(eval KSU_VERSION=$(shell expr 10000 + $(KSU_GIT_VERSION) + 200))
2647
$(info -- KernelSU version: $(KSU_VERSION))
2748
ccflags-y += -DKSU_VERSION=$(KSU_VERSION)
28-
else # Allow overriding KernelSU version if its not a submodule
29-
ifneq ($(KSU_EXTERNAL_VERSION),)
30-
$(info -- KernelSU external version: $(KSU_EXTERNAL_VERSION))
31-
ccflags-y += -DKSU_VERSION=$(KSU_EXTERNAL_VERSION)
32-
else # If there is no .git file, the default version will be passed.
49+
else # Pass default version if the defined remote is not found
3350
$(warning "KSU_GIT_VERSION not defined! It is better to make KernelSU a git submodule!")
3451
ccflags-y += -DKSU_VERSION=16
3552
endif
36-
endif
3753

3854
# Checks hooks state
3955
ifeq ($(CONFIG_KSU_MANUAL_HOOK), y)

0 commit comments

Comments
 (0)