enhance(scripts,main/android-tools,main/libllvm): replace `TERMUX_ENV__S_TERMUX` in patch files, currently for `$TERMUX_EXEC__PROC_SELF_EXE`

Related pull https://github.com/termux/termux-exec/pull/24
This commit is contained in:
agnostic-apollo 2024-01-04 09:29:21 +05:00
parent f2e19a6b5d
commit 771621452c
No known key found for this signature in database
GPG Key ID: BCCC0287E9DCCAED
3 changed files with 10 additions and 4 deletions

View File

@ -5,7 +5,7 @@
#if defined(__linux__)
std::string path;
- android::base::Readlink("/proc/self/exe", &path);
+ if (const char *tmp = std::getenv("TERMUX_EXEC__PROC_SELF_EXE"))
+ if (const char *tmp = std::getenv("@TERMUX_ENV__S_TERMUX_EXEC@PROC_SELF_EXE"))
+ path.assign(tmp);
+ else
+ android::base::Readlink("/proc/self/exe", &path);
@ -35,7 +35,7 @@
- ssize_t exPathLen = readlink("/proc/self/exe", exPath, sizeof(exPath));
+ ssize_t exPathLen;
+ const char *tmp;
+ if (tmp = getenv("TERMUX_EXEC__PROC_SELF_EXE")) {
+ if (tmp = getenv("@TERMUX_ENV__S_TERMUX_EXEC@PROC_SELF_EXE")) {
+ strncpy(exPath, tmp, sizeof(exPath));
+ exPathLen = strlen(exPath)
+ } else {
@ -51,7 +51,7 @@
bool RunAs::Prepare() {
// run-as can't run /data/local/tmp/simpleperf directly. So copy simpleperf binary if needed.
- if (!android::base::Readlink("/proc/self/exe", &simpleperf_path_)) {
+ if (const char *tmp = std::getenv("TERMUX_EXEC__PROC_SELF_EXE"))
+ if (const char *tmp = std::getenv("@TERMUX_ENV__S_TERMUX_EXEC@PROC_SELF_EXE"))
+ simpleperf_path_.assign(tmp);
+ else if (!android::base::Readlink("/proc/self/exe", &simpleperf_path_)) {
PLOG(ERROR) << "ReadLink failed";

View File

@ -6,7 +6,7 @@ diff -u -r ../orig-src/llvm/lib/Support/Unix/Path.inc ./llvm/lib/Support/Unix/Pa
if (getprogpath(exe_path, argv0) != NULL)
return exe_path;
+#elif defined(__ANDROID__) // termux-exec linker wrapping does not work with /proc/self/exe
+ const char *termux_self_exe = std::getenv("TERMUX_EXEC__PROC_SELF_EXE");
+ const char *termux_self_exe = std::getenv("@TERMUX_ENV__S_TERMUX_EXEC@PROC_SELF_EXE");
+ if (termux_self_exe != NULL) return std::string(termux_self_exe);
+ if (char *real_path = realpath("/proc/self/exe", nullptr)) {
+ std::string ret = std::string(real_path);

View File

@ -26,6 +26,12 @@ termux_step_patch_package() {
-e "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" \
-e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
-e "s%\@TERMUX_PREFIX_CLASSICAL\@%${TERMUX_PREFIX_CLASSICAL}%g" \
-e "s%\@TERMUX_ENV__S_TERMUX\@%${TERMUX_ENV__S_TERMUX}%g" \
-e "s%\@TERMUX_ENV__SE_TERMUX\@%${TERMUX_ENV__SE_TERMUX}%g" \
-e "s%\@TERMUX_ENV__S_TERMUX_APP\@%${TERMUX_ENV__S_TERMUX_APP}%g" \
-e "s%\@TERMUX_ENV__SE_TERMUX_APP\@%${TERMUX_ENV__SE_TERMUX_APP}%g" \
-e "s%\@TERMUX_ENV__S_TERMUX_EXEC\@%${TERMUX_ENV__S_TERMUX_EXEC}%g" \
-e "s%\@TERMUX_ENV__SE_TERMUX_EXEC\@%${TERMUX_ENV__SE_TERMUX_EXEC}%g" \
"$patch" | patch --silent -p1
done
shopt -u nullglob