From 771621452c4aa426acb2fb748fdb80bae0309b65 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Thu, 4 Jan 2024 09:29:21 +0500 Subject: [PATCH] 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 --- packages/android-tools/termux-exec.patch | 6 +++--- packages/libllvm/llvm-lib-Support-Unix-Path.inc.patch | 2 +- scripts/build/termux_step_patch_package.sh | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/android-tools/termux-exec.patch b/packages/android-tools/termux-exec.patch index 681df7ae37..d243abef63 100644 --- a/packages/android-tools/termux-exec.patch +++ b/packages/android-tools/termux-exec.patch @@ -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"; diff --git a/packages/libllvm/llvm-lib-Support-Unix-Path.inc.patch b/packages/libllvm/llvm-lib-Support-Unix-Path.inc.patch index 13c804e8db..1fd29922a2 100644 --- a/packages/libllvm/llvm-lib-Support-Unix-Path.inc.patch +++ b/packages/libllvm/llvm-lib-Support-Unix-Path.inc.patch @@ -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); diff --git a/scripts/build/termux_step_patch_package.sh b/scripts/build/termux_step_patch_package.sh index df1082d445..71c11e49b2 100644 --- a/scripts/build/termux_step_patch_package.sh +++ b/scripts/build/termux_step_patch_package.sh @@ -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