Skip to content

Conversation

@dabao1955
Copy link
Contributor

The previous logic for detecting the Git repository in KernelSU's Kbuild assumed two distinct build scenarios—in-tree (as a submodule) and out-of-tree (standalone)—and used hardcoded path checks (e.g., $(srctree)/$(src)/../.git or $(MDIR)/../.git) to differentiate them. This approach is fragile, sensitive to directory layout changes, and fails in more complex repository structures (e.g., subtrees, nested worktrees, or non-standard submodules).

This commit replaces the ad-hoc path inspection with git rev-parse --show-toplevel, which reliably determines the root of the containing Git repository from any subdirectory. This eliminates the need to distinguish between in-tree and out-of-tree builds and unifies the version detection logic into a single, robust code path.

Additionally:

  • Removes the use of realpath, improving compatibility with older or minimal build environments where realpath may be unavailable.
  • Retains shallow-clone handling by unshallowing the repository before counting commits, ensuring accurate version numbers.
  • Adds an informative build message ($(info ...)) to indicate when a Git repository is successfully detected, aiding debuggability.

This change makes Kbuild more portable, maintainable, and resilient across diverse development and integration workflows.

@dabao1955 dabao1955 force-pushed the Kbuild-git branch 2 times, most recently from 44a4d55 to 23ede6c Compare January 1, 2026 04:19
@dabao1955 dabao1955 force-pushed the Kbuild-git branch 2 times, most recently from ff3c78d to 684973d Compare January 8, 2026 04:59
@dabao1955 dabao1955 force-pushed the Kbuild-git branch 3 times, most recently from d90ce42 to c75edf8 Compare January 10, 2026 12:16
@dabao1955 dabao1955 requested a review from 5ec1cff January 10, 2026 12:19
Copy link
Collaborator

@5ec1cff 5ec1cff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensuring that Kernel(KDIR)'s git root directory and MDIR(KernelSU)'s git root directory are different was based on the assumption that KernelSU and the kernel are located in different repositories. Checking this ensures that the commit count obtained comes from the KernelSU repository and not the kernel repository.

@dabao1955 dabao1955 requested a review from 5ec1cff January 12, 2026 16:16
@dabao1955 dabao1955 marked this pull request as draft January 12, 2026 16:19
@dabao1955 dabao1955 marked this pull request as ready for review January 12, 2026 16:30
@5ec1cff
Copy link
Collaborator

5ec1cff commented Jan 13, 2026

Why too slow?

@dabao1955
Copy link
Contributor Author

dabao1955 commented Jan 13, 2026

Why too slow?

For integrating kernelsu without using git submodule, the speed is unacceptable.

@dabao1955
Copy link
Contributor Author

More precisely, since it is built within the tree, not explicitly passing KDIR causes KERNEL_GIT_ROOT to be empty. Changing it to $(srctree) resolves this issue.

@5ec1cff
Copy link
Collaborator

5ec1cff commented Jan 13, 2026

你可以讲讲有什么集成方式,如果你的集成方式完全没有 KernelSU 的原始仓库,那根本不需要数提交来获取版本号

@dabao1955
Copy link
Contributor Author

你可以讲讲有什么集成方式,如果你的集成方式完全没有 KernelSU 的原始仓库,那根本不需要数提交来获取版本号

手动复制和通过 git submodule 两种方式

@5ec1cff
Copy link
Collaborator

5ec1cff commented Jan 13, 2026

如果是要兼容手动复制的方法,改这个的意义是什么?

@dabao1955
Copy link
Contributor Author

#2102 和 pr 的描述我想说的已经很清楚了

The previous logic for detecting the Git repository in KernelSU's Kbuild
assumed two distinct build scenarios—in-tree (as a submodule) and
out-of-tree (standalone)—and used hardcoded path checks (e.g.,
`$(srctree)/$(src)/../.git` or `$(MDIR)/../.git`) to differentiate them.
This approach is fragile, sensitive to directory layout changes, and
fails in more complex repository structures (e.g., subtrees, nested
worktrees, or non-standard submodules).

This commit replaces the ad-hoc path inspection with `git rev-parse
--show-toplevel`, which reliably determines the root of the containing
Git repository from any subdirectory. This eliminates the need to
distinguish between in-tree and out-of-tree builds and unifies the
version detection logic into a single, robust code path.

Additionally:
- Removes the use of `realpath`, improving compatibility with older or
  minimal build environments where `realpath` may be unavailable.
- Retains shallow-clone handling by unshallowing the repository before
  counting commits, ensuring accurate version numbers.
- Adds an informative build message (`$(info ...)`) to indicate when a
  Git repository is successfully detected, aiding debuggability.

This change makes KernelSU's build system more portable, maintainable,
and resilient across diverse development and integration workflows.

Signed-off-by: dabao1955 <[email protected]>
@aviraxp aviraxp merged commit 0fe78fc into tiann:main Jan 14, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants