From eab103d4ed63074afb6707bb14ffbf0964ee514b Mon Sep 17 00:00:00 2001 From: solaiys <63047151+solaiys@users.noreply.github.com> Date: Wed, 22 Oct 2025 19:54:40 +0530 Subject: [PATCH] [RDHC] Update rocm-core package scripts to include rdhc script (#1482) * Add rdhc script in to rocm-core package * Create the rdhc symlink within the package itself. * rdhc tool support is not enabled for windows. * [RDHC] Check if the required pip pkgs are present and warn . rdhc checks the required pip packages are present or not. if not warns the user and exits gracefully. Signed-off-by: Saravanan Solaiyappan --- projects/rocm-core/CMakeLists.txt | 53 ++++++++++++++++++++++++++++++ projects/rocm-core/rdhc/rdhc.py | 54 +++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 3 deletions(-) diff --git a/projects/rocm-core/CMakeLists.txt b/projects/rocm-core/CMakeLists.txt index 0b55cecdc7..bd16a7b36c 100644 --- a/projects/rocm-core/CMakeLists.txt +++ b/projects/rocm-core/CMakeLists.txt @@ -126,6 +126,32 @@ if(BUILD_SHARED_LIBS) DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT CORE_RUNTIME ) + if( NOT WIN32 ) + # rdhc tool is developed and tested for Linux based systems only. + # rdhc tool is not supported on Windows. + # Install rdhc files + install ( FILES + ${CMAKE_CURRENT_SOURCE_DIR}/rdhc/README.md + ${CMAKE_CURRENT_SOURCE_DIR}/rdhc/requirements.txt + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/rdhc + COMPONENT CORE_RUNTIME) + + install ( PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/rdhc/rdhc.py + DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${CORE_TARGET} + COMPONENT CORE_RUNTIME ) + + # Create symlink for rdhc in bin directory + add_custom_target ( rdhc_symlink ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../${CMAKE_INSTALL_LIBEXECDIR}/${CORE_TARGET}/rdhc.py rdhc-link ) + + install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/rdhc-link + DESTINATION ${CMAKE_INSTALL_BINDIR} + RENAME rdhc + COMPONENT CORE_RUNTIME ) + endif() + else() install ( FILES ${BUILD_DIR}/version DESTINATION .info @@ -145,6 +171,33 @@ else() install ( FILES ${BUILD_DIR}/rocmmod DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${STATIC_COMP_TYPE} ) + + if( NOT WIN32 ) + # rdhc tool is developed and tested for Linux based systems only. + # rdhc tool is not supported on Windows. + # Install rdhc files + install ( FILES + ${CMAKE_CURRENT_SOURCE_DIR}/rdhc/README.md + ${CMAKE_CURRENT_SOURCE_DIR}/rdhc/requirements.txt + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/rdhc + COMPONENT ${STATIC_COMP_TYPE}) + + install ( PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/rdhc/rdhc.py + DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${CORE_TARGET} + COMPONENT ${STATIC_COMP_TYPE} ) + + # Create symlink for rdhc in bin directory + add_custom_target ( rdhc_symlink_static ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E create_symlink + ../${CMAKE_INSTALL_LIBEXECDIR}/${CORE_TARGET}/rdhc.py rdhc-link-static ) + + install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/rdhc-link-static + DESTINATION ${CMAKE_INSTALL_BINDIR} + RENAME rdhc + COMPONENT ${STATIC_COMP_TYPE} ) + endif() + endif() ## Cmake module config file configurations diff --git a/projects/rocm-core/rdhc/rdhc.py b/projects/rocm-core/rdhc/rdhc.py index 78eba0e39c..39163e15c3 100755 --- a/projects/rocm-core/rdhc/rdhc.py +++ b/projects/rocm-core/rdhc/rdhc.py @@ -7,10 +7,57 @@ import json import argparse import glob import re -import yaml +import sys import textwrap from enum import Enum -from prettytable import PrettyTable + +# Check for required packages before importing them +def check_required_packages(): + """Check if required Python packages are installed""" + missing_packages = [] + required_packages = { + 'prettytable': 'prettytable', + 'yaml': 'PyYAML' + } + + for import_name, package_name in required_packages.items(): + try: + __import__(import_name) + except ImportError: + missing_packages.append(package_name) + + if missing_packages: + print("\n" + "="*70) + print("WARNING: Missing Required Python Packages") + print("="*70) + print(f"\nThe following packages are required but not installed:") + for pkg in missing_packages: + print(f" - {pkg}") + + print("\nTo install the missing packages, run:") + print(f" pip3 install {' '.join(missing_packages)}") + print("\nOr install all requirements:") + print(" pip3 install -r /share/rdhc/requirements.txt") + print(" Or\n pip3 install -r requirements.txt") + print("\n" + "="*70 + "\n") + + print("Exiting...") + sys.exit(1) + else: + return True + +# Check packages before importing +packages_available = check_required_packages() + +# Now import the packages +try: + from prettytable import PrettyTable + import yaml +except ImportError: + print("WARNING: Unable to import the required Python Packages !!!!") + print("Exiting...") + sys.exit(1) + # Define test status enum class TestStatus(Enum): @@ -1748,7 +1795,8 @@ def main(): parser = argparse.ArgumentParser(description="ROCm Deployment Health Check Tool", formatter_class=argparse.RawDescriptionHelpFormatter, usage="sudo -E ./rdhc.py [options]", - epilog="Usage examples:\n"+ + epilog="Refer the README @/share/rdhc/README.md \n"+ + "Usage examples:\n"+ "# Run quick test (default tests only)\n" + "sudo -E ./rdhc.py\n" + "\n"+