support: honor DESTDIR in install(CODE) steps - #1238
Open
takano32 wants to merge 1 commit into
Open
Conversation
CMake automatically prepends $ENV{DESTDIR} to the destinations of
install(TARGETS/FILES/DIRECTORY/PROGRAMS) rules, but not to paths
baked into install(CODE) scripts. The support installation steps
passed configure-time absolute paths (derived from
CMAKE_INSTALL_PREFIX) directly, so a staged installation
DESTDIR=/tmp/stage make -C build install
either failed with PermissionError from install-share.py when run as
a regular user, or - worse - executed retdec-yarac from, wrote into,
and REMOVE_RECURSE'd directories under the live installation prefix
when run as root.
Prefix all absolute paths inside the install(CODE) strings with an
install-time-evaluated $ENV{DESTDIR}. When DESTDIR is not set the
variable expands to an empty string, so a plain 'make install' is
unchanged. The install(DIRECTORY ordinals ...) rule needs no change
because CMake already applies DESTDIR to it, and the configure-time
FILE(REMOVE_RECURSE) cache cleanup is left alone because DESTDIR is
unknowable at configure time.
Fixes avast#1177
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014nNMVbAuffaPPQuYdLZgD1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1177.
Problem
CMake automatically prepends
$ENV{DESTDIR}to the destinations ofinstall(TARGETS/FILES/DIRECTORY/PROGRAMS)rules, but not to paths baked intoinstall(CODE)scripts. The support installation steps insupport/CMakeLists.txtpass configure-time absolute paths (derived fromCMAKE_INSTALL_PREFIX) directly, so a staged installationfails with
PermissionError: [Errno 13] Permission denied: '/usr/local/share/retdec'frominstall-share.pywhen run as a regular user (the exact failure in #1177) — or, worse, when run as root it executesretdec-yaracfrom, writes into, andREMOVE_RECURSEs directories under the live installation prefix. This breaks the standard packaging workflow (Debian, RPM, AUR, staged installs in general).Fix
Prefix every absolute path inside the four
install(CODE)strings with an install-time-evaluated\$ENV{DESTDIR}— the same idiom CMake uses in its own generated install rules. Notes:DESTDIRis not set,$ENV{DESTDIR}expands to an empty string, so a plainmake installis byte-for-byte unchanged.retdec-yaracworks because the project sets an$ORIGIN-relative RPATH.install(DIRECTORY ordinals ...)rule is intentionally untouched: CMake already appliesDESTDIRthere, and prefixing it again would double the path (the pitfall that broke the 2019 attempt CMake: unbreak make DESTDIR=/foo install #579 on the pre-rewrite build system).FILE(REMOVE_RECURSE)cache cleanup is left alone becauseDESTDIRis unknowable at configure time.Testing
Ran
DESTDIR=<stage> make -C build installend-to-end as a non-root user:PermissionError+CMake Error at support/cmake_install.cmake),<stage>/usr/local/share/retdec/support/,retdec-yaracwas executed, YARA rules compiled into the stage,version-yarac.txtwritten into the stage,/usr/local.Also verified the generated
support/cmake_install.cmakenow carries$ENV{DESTDIR}on every previously-bare path.🤖 Generated with Claude Code
https://claude.ai/code/session_014nNMVbAuffaPPQuYdLZgD1