-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
enhancement: allow expanding environment variables in patches. #24641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
I checked all our patches with grep and got these results. $ grep -nr '^[+].*@@.*@@' --include="*.patch*"
packages/netcat-openbsd/debian-patches-port-to-linux-with-libbsd.patch:27:+@@ -38,7 +38,8 @@
$ Since we do not have variable named |
This will be useful for |
Filter patch lines and expand environment variables enclosed within `@@` literals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how many specific use cases this might be helpful for right now, but I think it does not break any existing builds, so it should be fine to add this.
It might be helpful to somewhat simplify the build.sh
of vim
in a future version. I force-cross-compiled the perl, ruby and tcl bindings of vim
using a convoluted patch, and this feature might help reduce the length of that code in a future version.
termux-packages/packages/vim/build.sh
Lines 94 to 110 in 3f5084b
# Vim doesn't support cross-compilation for Perl, Ruby and Tcl | |
# out of the box, so we need to patch the configure script to make it work. | |
local perl_version ruby_major_version tcl_major_version | |
perl_version="$(. "$TERMUX_SCRIPTDIR/packages/perl/build.sh"; echo "${TERMUX_PKG_VERSION[0]}")" | |
ruby_major_version="$(. "$TERMUX_SCRIPTDIR/packages/ruby/build.sh"; echo "${TERMUX_PKG_VERSION%\.*}")" | |
tcl_major_version="$(. "$TERMUX_SCRIPTDIR/packages/tcl/build.sh"; echo "${TERMUX_PKG_VERSION%\.*}")" | |
patch="$TERMUX_PKG_BUILDER_DIR/configure-perl-ruby-tcl-cross-compiling.diff" | |
echo "Applying patch: $(basename "$patch")" | |
test -f "$patch" && sed \ | |
-e "s%\@PERL_VERSION\@%${perl_version}%g" \ | |
-e "s%\@RUBY_MAJOR_VERSION\@%${ruby_major_version}%g" \ | |
-e "s%\@TCL_MAJOR_VERSION\@%${tcl_major_version}%g" \ | |
-e "s%\@PERL_PLATFORM\@%${TERMUX_ARCH}-android%g" \ | |
-e "s%\@RUBY_PLATFORM\@%${TERMUX_HOST_PLATFORM}%g" \ | |
-e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \ | |
"$patch" | patch --silent -p1 |
Actually I see 2 ways to improve current PR and make its usage more convenient.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm spread a bit thin right now with PRs and reviews, but how is this different from the existing behavior in termux_step_patch_package
?
termux-packages/scripts/build/termux_step_patch_package.sh
Lines 22 to 34 in 7b2747b
test -f "$patch" && sed \ | |
-e "s%\@TERMUX_APP_PACKAGE\@%${TERMUX_APP_PACKAGE}%g" \ | |
-e "s%\@TERMUX_BASE_DIR\@%${TERMUX_BASE_DIR}%g" \ | |
-e "s%\@TERMUX_CACHE_DIR\@%${TERMUX_CACHE_DIR}%g" \ | |
-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__S_TERMUX_APP\@%${TERMUX_ENV__S_TERMUX_APP}%g" \ | |
-e "s%\@TERMUX_ENV__S_TERMUX_API_APP\@%${TERMUX_ENV__S_TERMUX_API_APP}%g" \ | |
-e "s%\@TERMUX_ENV__S_TERMUX_ROOTFS\@%${TERMUX_ENV__S_TERMUX_ROOTFS}%g" \ | |
-e "s%\@TERMUX_ENV__S_TERMUX_EXEC\@%${TERMUX_ENV__S_TERMUX_EXEC}%g" \ | |
"$patch" | patch --silent -p1 |
One thing I want to make absolutely sure we do not add here is the ability to inject arbitrary environment variable expansion into patches.
That's user controlled input and should not be trusted.
Could you describe an example of what the worst-case scenario for that would be, as you imagine it? |
Filter patch lines and expand environment variables enclosed within
@@
literals.Also scripts are a bit refactored for consistency with other recent changes.
This enhancement allows us write patches with lines like
@@TERMUX_ARCH@@
to be automatically expanded from build-time variables.It should help us avoid writing simple but long heredocs or long regular escaped strings inside buildscripts (like here) or define
*.in
files (like here) for subsequent variable expansion with writing to target directory. Everything can be done in a regular*.patch*
file.Additional variables can be assigned in
termux_step_post_get_source
(if you need additional variables or contextual data).Example (just for reference, not for real use):
And this
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o sl sl.c -lncurses @@TERMUX_ARCH@@
is being expanded to
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o sl sl.c -lncurses aarch64