diff --git a/build_tools/packaging/linux/package.json b/build_tools/packaging/linux/package.json index cecb5069ae..2ed9ecff9f 100644 --- a/build_tools/packaging/linux/package.json +++ b/build_tools/packaging/linux/package.json @@ -2487,6 +2487,7 @@ "Vendor": "Advanced Micro Devices, Inc", "Homepage": "https://github.com/ROCm/rocm-libraries", "Metapackage": "True", + "Postinstall": "True", "Gfxarch": "True" }, { diff --git a/build_tools/packaging/linux/template/scripts/amdrocm-core-devel-postinst.j2 b/build_tools/packaging/linux/template/scripts/amdrocm-core-devel-postinst.j2 new file mode 100644 index 0000000000..170362f17f --- /dev/null +++ b/build_tools/packaging/linux/template/scripts/amdrocm-core-devel-postinst.j2 @@ -0,0 +1,85 @@ +#!/bin/bash + +is_debian_like() { + local id_like="$1" + case " $id_like " in + (*" debian "*|*" ubuntu "*) + return 0 + ;; + (*) + return 1 + ;; + esac +} + +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + local binaries altscore now + now=$(date -u +%s) # Number of seconds since 1 Jan 1970 + + + # The reason for this approach rather than using the build number + # is to allow for jobs from different builds. In one build job the + # job number might be at 1200, whilst in a release job the number + # may be only 1. This approach assums that if you install a build + # with a different semantic version then the highest is the + # desired one, but if you install two with the same semver then + # the newest is the desired version. + + # Build up a score. It needs to fit in 32 bits + altscore=$(({{ version_major }} - 3)) + altscore=$((altscore * 14 + {{ version_minor }})) # Allow up to 14 minor + altscore=$((altscore * 14 + {{ version_patch }})) # Allow up to 14 patch + + # So far if the version is less than 9 we have a number (altscore) + # that is less than 1175. 2**31/1175 is about 1.8 million. So + # multiply altscore by 1,000,000 and add in a factor of how many + # minutes have passed from an arbitary point in time (1,600,000,000 + # seconds after 1 Jan 1970 or Sep 13 12:26:40 2020) on the + # basis that no one is going to be installing a new version more + # often than every minute. This does get things wrong if a million + # minutes pass and you are downgrading, but the chances of someone + # waiting almost 2 years between installing a version and the + # previous patch level is small. + altscore=$((altscore*1000000+(now-1600000000)/60)) + + binaries=( amdclang amdclang++ amdclang-cl amdclang-cpp amdflang amdlld ) + + {% if target == "deb" %} + PKG_INSTALL_PREFIX={{ install_prefix }} + {% else %} + PKG_INSTALL_PREFIX="$RPM_INSTALL_PREFIX0" + {% endif %} + + for i in "${binaries[@]}" + do + # No obvious recover strategy if things fail + # No manual or other slave pages to install + if [ -e $PKG_INSTALL_PREFIX/bin/"$i" ] + then + update-alternatives --install /usr/bin/"$i" "$i" \ + $PKG_INSTALL_PREFIX/bin/"$i" "$altscore" + else + echo "$PKG_INSTALL_PREFIX/bin/$i not found, but that is OK" >&2 + fi + done + true +} + +if [ -e /etc/os-release ] && source /etc/os-release && is_debian_like "${ID_LIKE:-$ID}" +then + case "$1" in + (configure) + do_update_alternatives + ;; + (abort-upgrade|abort-remove|abort-deconfigure) + echo "$1" + ;; + (*) + exit 0 + ;; + esac +else + do_update_alternatives +fi diff --git a/build_tools/packaging/linux/template/scripts/amdrocm-core-devel-prerm.j2 b/build_tools/packaging/linux/template/scripts/amdrocm-core-devel-prerm.j2 new file mode 100644 index 0000000000..61d388447c --- /dev/null +++ b/build_tools/packaging/linux/template/scripts/amdrocm-core-devel-prerm.j2 @@ -0,0 +1,49 @@ +#!/bin/bash + +binaries=( amdclang amdclang++ amdclang-cl amdclang-cpp amdflang amdlld ) + +is_debian_like() { + local id_like="$1" + case " $id_like " in + (*" debian "*|*" ubuntu "*) + return 0 + ;; + (*) + return 1 + ;; + esac +} + +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + + {% if target == "deb" %} + PKG_INSTALL_PREFIX={{ install_prefix }} + {% else %} + PKG_INSTALL_PREFIX="$RPM_INSTALL_PREFIX0" + {% endif %} + + for i in "${binaries[@]}" + do + update-alternatives --remove "$i" \ + "$PKG_INSTALL_PREFIX/bin/$i" + done +} + +if [ -e /etc/os-release ] && source /etc/os-release && is_debian_like "${ID_LIKE:-$ID}" +then + case "$1" in + (remove|upgrade) + do_update_alternatives + ;; + (purge) + # nothing to do + ;; + (*) + exit 0 + ;; + esac +else + do_update_alternatives +fi diff --git a/build_tools/packaging/linux/template/scripts/amdrocm-core-postinst.j2 b/build_tools/packaging/linux/template/scripts/amdrocm-core-postinst.j2 index f3cdda45cf..e3f29f83ca 100644 --- a/build_tools/packaging/linux/template/scripts/amdrocm-core-postinst.j2 +++ b/build_tools/packaging/linux/template/scripts/amdrocm-core-postinst.j2 @@ -44,7 +44,7 @@ do_update_alternatives(){ # previous patch level is small. altscore=$((altscore*1000000+(now-1600000000)/60)) - binaries=( hipcc rocminfo amd-smi rocm_agent_enumerator rocm-smi rocprofv3 ) + binaries=( hipcc hipcc_cmake_linker_helper hipconfig hipdemangleatp hipify-clang roc-obj roc-obj-extract roc-obj-ls rocminfo amd-smi rocm_agent_enumerator rocm-smi rocprofv3 rocprofv3-avail rocgdb ) {% if target == "deb" %} PKG_INSTALL_PREFIX={{ install_prefix }} @@ -61,10 +61,11 @@ do_update_alternatives(){ update-alternatives --install "/opt/rocm/lib" "rocm-lib" "$PKG_INSTALL_PREFIX/lib" "$altscore" update-alternatives --install "/opt/rocm/include" "rocm-include" "$PKG_INSTALL_PREFIX/include" "$altscore" - # Install /opt/rocm/llvm, /opt/rocm/amdgcn, and /opt/rocm/libexec soft links + # Install /opt/rocm/llvm, /opt/rocm/amdgcn, /opt/rocm/libexec, and /opt/rocm/share soft links update-alternatives --install "/opt/rocm/llvm" "rocm-llvm" "$PKG_INSTALL_PREFIX/llvm" "$altscore" update-alternatives --install "/opt/rocm/amdgcn" "rocm-amdgcn" "$PKG_INSTALL_PREFIX/amdgcn" "$altscore" update-alternatives --install "/opt/rocm/libexec" "rocm-libexec" "$PKG_INSTALL_PREFIX/libexec" "$altscore" + update-alternatives --install "/opt/rocm/share" "rocm-share" "$PKG_INSTALL_PREFIX/share" "$altscore" for i in "${binaries[@]}" do diff --git a/build_tools/packaging/linux/template/scripts/amdrocm-core-prerm.j2 b/build_tools/packaging/linux/template/scripts/amdrocm-core-prerm.j2 index 9dd7e2e780..9430751264 100644 --- a/build_tools/packaging/linux/template/scripts/amdrocm-core-prerm.j2 +++ b/build_tools/packaging/linux/template/scripts/amdrocm-core-prerm.j2 @@ -1,6 +1,6 @@ #!/bin/bash -binaries=( hipcc rocminfo amd-smi rocm_agent_enumerator rocm-smi rocprofv3 ) +binaries=( hipcc hipcc_cmake_linker_helper hipconfig hipdemangleatp hipify-clang roc-obj roc-obj-extract roc-obj-ls rocminfo amd-smi rocm_agent_enumerator rocm-smi rocprofv3 rocprofv3-avail rocgdb ) is_debian_like() { local id_like="$1" @@ -39,10 +39,11 @@ do_update_alternatives(){ update-alternatives --remove "rocm-lib" "$PKG_INSTALL_PREFIX/lib" update-alternatives --remove "rocm-include" "$PKG_INSTALL_PREFIX/include" - # Remove /opt/rocm/llvm, /opt/rocm/amdgcn, and /opt/rocm/libexec soft links + # Remove /opt/rocm/llvm, /opt/rocm/amdgcn, /opt/rocm/libexec, and /opt/rocm/share soft links update-alternatives --remove "rocm-llvm" "$PKG_INSTALL_PREFIX/llvm" update-alternatives --remove "rocm-amdgcn" "$PKG_INSTALL_PREFIX/amdgcn" update-alternatives --remove "rocm-libexec" "$PKG_INSTALL_PREFIX/libexec" + update-alternatives --remove "rocm-share" "$PKG_INSTALL_PREFIX/share" } if [ -e /etc/os-release ] && source /etc/os-release && is_debian_like "${ID_LIKE:-$ID}"