Skip to content

Commit

Permalink
Fix upgrade postinst (#1253)
Browse files Browse the repository at this point in the history
* fix upgrade action in the postinst script
* clean up and fix postinst script not creating symlinks in some situations
* [RPM]fix prerm script incorrectly deleting symlinks during an upgrade

Change-Id: I6aee040dc6ac8363d58ccaf35d4a0d81274e5ea3
  • Loading branch information
scchan authored and ssahasra committed Sep 13, 2019
1 parent 2e76487 commit 24e69cd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 45 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@ execute_process(COMMAND ${DEBIAN_EXTRA_SCRIPT_SOURCE_DIR}/process_packaging_scri
${CMAKE_SYSTEM_PROCESSOR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

execute_process(COMMAND ${DEBIAN_EXTRA_SCRIPT_SOURCE_DIR}/process_packaging_script.bsh ${DEBIAN_EXTRA_SCRIPT_SOURCE_DIR}/preinst_rpm.in
${DEBIAN_EXTRA_SCRIPT_DEST_DIR}/preinst_rpm
${CPACK_PACKAGE_NAME}
${HCC_PACKAGE_INSTALL_PREFIX}
${CMAKE_INSTALL_LIBDIR}
${CMAKE_SYSTEM_PROCESSOR}
${HCC_VERSION_MAJOR}
${HCC_VERSION_MINOR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc")
set(CPACK_PACKAGE_VERSION "${HCC_VERSION_MAJOR}.${HCC_VERSION_MINOR}.${HCC_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION_MAJOR ${HCC_VERSION_MAJOR})
Expand Down Expand Up @@ -557,6 +567,7 @@ set(CPACK_DEBIAN_PACKAGE_DEPENDS "${HCC_GENERAL_DEBIAN_DEP} ${HCC_ROCR_DEP} ${HC
# RPM package settings
set(CPACK_RPM_PACKAGE_DESCRIPTION ${PACKAGE_DESCRIPTION})
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${PROJECT_BINARY_DIR}/packaging/debian/postinst")
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${PROJECT_BINARY_DIR}/packaging/debian/preinst_rpm")
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${PROJECT_BINARY_DIR}/packaging/debian/prerm")

# disable automatic shared libraries dependency detection
Expand Down
30 changes: 4 additions & 26 deletions packaging/debian/postinst.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ SOFTLINKS=(

do_softlinks() {

if [ $PACKAGE_NAME == "hcc_hsail" ] && [ -L "$ROCM_PATH/hcc" ] && [ $(readlink -f $ROCM_PATH/hcc) == "$ROCM_PATH/hcc-lc" ] ; then
return
fi

mkdir -p "$ROCM_PATH/lib"
mkdir -p "$ROCM_PATH/lib/cmake"
mkdir -p "$ROCM_PATH/bin"
Expand All @@ -50,28 +46,10 @@ do_softlinks() {
SOURCE_DIR=${SOFTLINKS[i]}
DEST_DIR=${SOFTLINKS[i+1]}
FILE=${SOFTLINKS[i+2]}

if [ -e $ROCM_PATH/hcc/$SOURCE_DIR/$FILE ] ; then
if [ ! -e $ROCM_PATH/$DEST_DIR/$FILE ] ; then
ln -sf $ROCM_PATH/hcc/$SOURCE_DIR/$FILE $ROCM_PATH/$DEST_DIR/$FILE
fi
fi
ln -sf $ROCM_PATH/hcc/$SOURCE_DIR/$FILE $ROCM_PATH/$DEST_DIR/$FILE
done
}

case "$1" in
configure|upgrade|1|2)
do_softlinks
;;

abort-upgrade|abort-remove|abort-deconfigure)
echo "$1"
;;

*)
echo "postinst called with unknown argument: $1" >&2
exit 0
;;

esac

if [ $1 == "configure" ] || [ $1 == "upgrade" ] || [ "$1" -ge "1" ] ; then
do_softlinks
fi
45 changes: 45 additions & 0 deletions packaging/debian/preinst_rpm.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -e

PACKAGE_NAME=@PACKAGE_NAME@
INSTALL_PATH=@INSTALL_PATH@
LIBRARY_DIR=@LIBRARY_DIR@
PROCESSOR=@PROCESSOR@
HCC_VERSION_MAJOR=@HCC_VERSION_MAJOR@
HCC_VERSION_MINOR=@HCC_VERSION_MINOR@

ROCM_PATH="/opt/rocm"

# NOTE: if you modify this table, also update the same table in postinst
SOFTLINKS=(
# <SOURCE DIRECTORY> <DESTINATION DIRECTORY> <FILE>
"bin" "bin" "clamp-config"
"bin" "bin" "extractkernel"
"bin" "bin" "hcc"
"bin" "bin" "hcc-config"
"$LIBRARY_DIR" "lib" "libhc_am.so*"
"$LIBRARY_DIR" "lib" "libmcwamp.so*"
"$LIBRARY_DIR" "lib" "libmcwamp_cpu.so*"
"$LIBRARY_DIR" "lib" "libmcwamp_hsa.so*"
"$LIBRARY_DIR" "lib" "libclang_rt.builtins-${PROCESSOR}.a"
)

remove_all_softlinks_before_upgrade() {

for (( i=0; i<${#SOFTLINKS[@]}; i+=3 ))
do
SOURCE_DIR=${SOFTLINKS[i]}
DEST_DIR=${SOFTLINKS[i+1]}
FILE=${SOFTLINKS[i+2]}

rm -f $ROCM_PATH/$DEST_DIR/$FILE
done
rm -f $ROCM_PATH/include/hcc
rm -f $ROCM_PATH/lib/cmake/hcc
}

if [ "$1" -ge "2" ] ; then
remove_all_softlinks_before_upgrade
fi

23 changes: 4 additions & 19 deletions packaging/debian/prerm.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ SOFTLINKS=(
"$LIBRARY_DIR" "lib" "libclang_rt.builtins-${PROCESSOR}.a"
)

do_softlinks() {
remove_all_softlinks() {

rm -f $INSTALL_PATH/include/hcc

if [ $PACKAGE_NAME == "hcc_hsail" ] && [ -L "$ROCM_PATH/hcc" ] && [ $(readlink -f $ROCM_PATH/hcc) == "$ROCM_PATH/hcc-lc" ] ; then
return
fi

for (( i=0; i<${#SOFTLINKS[@]}; i+=3 ))
do
SOURCE_DIR=${SOFTLINKS[i]}
Expand All @@ -51,17 +47,6 @@ do_softlinks() {
rmdir --ignore-fail-on-non-empty /opt/rocm
}


case "$1" in
remove|purge|upgrade|0|1)
do_softlinks
;;

*)
echo "postrm called with unknown argument: $1" >&2
exit 0
;;

esac


if [ $1 == "remove" ] || [ $1 == "purge" ] || [ $1 == "upgrade" ] || [ "$1" -eq "0" ] ; then
remove_all_softlinks
fi

0 comments on commit 24e69cd

Please sign in to comment.