Skip to content

Commit

Permalink
Add install wrapper
Browse files Browse the repository at this point in the history
... to work around Gentoo's wrapper idiosyncrasy.

Signed-off-by: Alexey Neyman <stilor@att.net>
  • Loading branch information
stilor committed Jan 30, 2017
1 parent a08a4c4 commit 7d1b203
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/crosstool-NG.sh.in
Expand Up @@ -116,8 +116,12 @@ cat "${CT_LIB_DIR}/paths.sh" |while read trash line; do
tmpl="${CT_LIB_DIR}/scripts/override/__default"
fi
CT_DoLog DEBUG "Creating script-override for '${tool}' -> '${path}' using '${tmpl}' template"
${sed} -r -e "s#@CONFIG_SHELL@#${CT_CONFIG_SHELL}#g" \
-e "s#@TOOL_PATH@#${path}#g" "${tmpl}" > "${CT_TOOLS_OVERRIDE_DIR}/bin/${tool}"
CT_DoExecLog ALL cp "${tmpl}" "${CT_TOOLS_OVERRIDE_DIR}/bin/${tool}"
CT_DoExecLog ALL ${sed} -i -r \
-e "s#@CONFIG_SHELL@#${CT_CONFIG_SHELL}#g" \
-e "s#@TOOL_PATH@#${path}#g" \
-e "s#@TOOLS_OVERRIDE_DIR@#${CT_TOOLS_OVERRIDE_DIR}#g" \
"${CT_TOOLS_OVERRIDE_DIR}/bin/${tool}"
CT_DoExecLog ALL chmod 700 "${CT_TOOLS_OVERRIDE_DIR}/bin/${tool}"
done
export PATH="${CT_TOOLS_OVERRIDE_DIR}/bin:${PATH}"
Expand Down
35 changes: 35 additions & 0 deletions scripts/override/install
@@ -0,0 +1,35 @@
#!@CONFIG_SHELL@

# Do the most common case first
if [ -z "${__PORTAGE_HELPER_PATH}" ]; then
exec @TOOL_PATH@ "$@"
fi

# Not so simple case: Gentoo uses *two* wrappers around install script
# to deal with extended attributes:
# - /usr/lib/portage/python*/ebuild-helpers/xattr/install
# This sets __PORTAGE_HELPER_PATH (see the check above) and
# invokes either C- or Python-based wrapper (they do the same
# thing anyway). E.g., let it be /usr/bin/install-xattrs...
# - /usr/bin/install-xattrs
# This now analyzes $PATH and invokes 'install' in the first directory
# in $PATH where it is found, but not the __PORTAGE_HELPER_PATH
# This scheme breaks if we interject another install wrapper, resulting
# in a fork bomb. Hence, if we detected a loop, we need to remove our
# own directory from $PATH and try again. Ironically, the very code below
# based on that portage helper.
IFS=:
set -f
path=
for x in ${PATH}; do
case "${x}" in
@TOOLS_OVERRIDE_DIR@/bin) continue;;
esac
if test -n "${path}"; then
path="${path}:${x}"
else
path="${x}"
fi
done
PATH="${path}"
exec @TOOL_PATH@ "$@"

0 comments on commit 7d1b203

Please sign in to comment.