Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bits_helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ def performPreferCheckWithTempDir(pkg, cmd):
("FULL_BUILD_REQUIRES", " ".join(spec["full_build_requires"])),
("FULL_REQUIRES", " ".join(spec["full_requires"])),
("BITS_PREFER_SYSTEM_KEY", spec.get("key", "")),
("BITS_SCRIPT_DIR", dirname(realpath(__file__))),
]
if "sources" in spec:
for idx, src in enumerate(spec["sources"]):
Expand Down
20 changes: 7 additions & 13 deletions bits_helpers/build_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export PATH=$WORK_DIR/wrapper-scripts:$PATH
# the bits script itself
#
# - ARCHITECTURE
# - BITS_SCRIPT_DIR
# - BUILD_REQUIRES
# - CACHED_TARBALL
# - CAN_DELETE
Expand Down Expand Up @@ -212,27 +213,21 @@ EOF

cd "$WORK_DIR/INSTALLROOT/$PKGHASH/$PKGPATH"
# Find which files need relocation.
{ grep -I -H -l -R "\(INSTALLROOT/$PKGHASH\|[@][@]PKGREVISION[@]$PKGHASH[@][@]\)" . || true; } | sed -e 's|^\./||' > "$INSTALLROOT/.original-unrelocated"
{ grep -I -H -l -R "\($WORK_DIR\|[@][@]PKGREVISION[@]$PKGHASH[@][@]\)" . || true; } | sed -e 's|^\./||' > "$INSTALLROOT/etc/profile.d/.bits-relocate"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why $WORK_DIR and not INSTALLROOT/$PKGHASH?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INSTALLROOT/$PKGHASH is for the package itself but the whole idea of this change was to find all text files which has $WORKDIR (note that this will also match files with INSTALLROOT/$PKGHASH as it is under $WORKDIR directory ... right?) in them. If we search for INSTALLROOT/$PKGHASH then we might miss those text files which have hard coded paths of package dependencies ( e.g. root-config)


# Relocate script for <arch>/<pkgname>/<pkgver> structure
cat > "$INSTALLROOT/relocate-me.sh" <<EoF
#!/bin/bash -e
if [[ "\$WORK_DIR" == '' ]]; then
echo 'Please, define \$WORK_DIR'
exit 1
fi

cat > "$INSTALLROOT/etc/profile.d/.bits-pkginfo" <<EoF
OP=${PKGPATH}
PP=\${PKGPATH:-${PKGPATH}}
PH=${PKGHASH}
PKG_DIR="$WORK_DIR"
EoF

while read -r unrelocated; do
echo "sed -e \"s|/[^ ;:]*INSTALLROOT/\$PH/\$OP|\$WORK_DIR/\$PP|g; s|[@][@]PKGREVISION[@]\$PH[@][@]|$PKGREVISION|g\"" \
"\$PP/$unrelocated.unrelocated > \$PP/$unrelocated"
done < "$INSTALLROOT/.original-unrelocated" >> "$INSTALLROOT/relocate-me.sh"
cp "${BITS_SCRIPT_DIR}/relocate-me.sh" "$INSTALLROOT/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use install, to make sure the copied file has the right mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in #75


# Always relocate the modulefile (if present) so that it works also in devel mode.
if [[ ! -s "$INSTALLROOT/.original-unrelocated" && -f "$INSTALLROOT/etc/modulefiles/$PKGNAME" ]]; then
if [[ ! -s "$INSTALLROOT/etc/profile.d/.bits-relocate" && -f "$INSTALLROOT/etc/modulefiles/$PKGNAME" ]]; then
echo "mv -f \$PP/etc/modulefiles/$PKGNAME \$PP/etc/modulefiles/${PKGNAME}.forced-relocation && sed -e \"s|[@][@]PKGREVISION[@]\$PH[@][@]|$PKGREVISION|g\" \$PP/etc/modulefiles/${PKGNAME}.forced-relocation > \$PP/etc/modulefiles/$PKGNAME" >> "$INSTALLROOT/relocate-me.sh"
fi

Expand Down Expand Up @@ -289,7 +284,6 @@ EOF
fi

cat "$INSTALLROOT/relocate-me.sh"
cat "$INSTALLROOT/.original-unrelocated" | xargs -n1 -I{} cp '{}' '{}'.unrelocated
fi
cd "$WORK_DIR/INSTALLROOT/$PKGHASH"

Expand Down
11 changes: 11 additions & 0 deletions bits_helpers/relocate-me.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -e
THISDIR="$(cd -P "$(dirname "$0")" && pwd)"
source ${THISDIR}/etc/profile.d/.bits-pkginfo
INSTALL_BASE=$(echo $THISDIR | sed "s|/$PP$||")
if [[ -s ${THISDIR}/etc/profile.d/.bits-relocate ]] ; then
for f in $(cat ${THISDIR}/etc/profile.d/.bits-relocate) ; do
sed -i -e "s|${PKG_DIR}/INSTALLROOT/$PH|$INSTALL_BASE|g;s|${PKG_DIR}|$INSTALL_BASE|g" "${THISDIR}/$f"
Copy link
Collaborator

@ktf ktf Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-i should take an argument (the extension of the unmodified file) and the backup file should be deleted afterwards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in #75

done
fi
sed -i -e "s|^PKG_DIR=.*|PKG_DIR="${INSTALL_BASE}"|" $THISDIR/etc/profile.d/.bits-pkginfo