From 534ed9eb6b879eab6422fd5a230cd61444a6267b Mon Sep 17 00:00:00 2001 From: Mustafa Abdulrahman Date: Wed, 4 Sep 2024 12:25:13 -0400 Subject: [PATCH 1/2] Add PACKGEN to build_ackages.sh and add better parameter parsing --- Scripts/Packaging/build_packages.sh | 120 ++++++++++++++++++++++++---- 1 file changed, 103 insertions(+), 17 deletions(-) diff --git a/Scripts/Packaging/build_packages.sh b/Scripts/Packaging/build_packages.sh index 09e2faee..9419ac37 100755 --- a/Scripts/Packaging/build_packages.sh +++ b/Scripts/Packaging/build_packages.sh @@ -23,19 +23,101 @@ set -e +# Default values GIT_TOP_LEVEL=$(git rev-parse --show-toplevel) +ROCM_EXAMPLES_ROOT="$GIT_TOP_LEVEL" +PACKAGE_NAME="ROCm-SDK-Examples" +PACKAGE_VERSION="6.2.0" +PACKAGE_INSTALL_PREFIX="/opt/rocm/examples" +TEST_PACKAGE_INSTALL_PREFIX="/opt/rocm/examples-test" +BUILD_DIR="$ROCM_EXAMPLES_ROOT/build" +DEB_DIR="$BUILD_DIR/deb" +RPM_DIR="$BUILD_DIR/rpm" +DEB_PACKAGE_RELEASE="local.9999" +RPM_PACKAGE_RELEASE="local.9999" +CPACKGEN="" -# Inputs and Defaults -ROCM_EXAMPLES_ROOT="${1:-$GIT_TOP_LEVEL}" -PACKAGE_NAME="${2:-ROCm-SDK-Examples}" -PACKAGE_VERSION="${3:-6.2.0}" -PACKAGE_INSTALL_PREFIX="${4:-/opt/rocm/examples}" -TEST_PACKAGE_INSTALL_PREFIX="${5:-/opt/rocm/examples-test}" -BUILD_DIR="${6:-$ROCM_EXAMPLES_ROOT/build}" -DEB_DIR="${7:-$BUILD_DIR/deb}" -RPM_DIR="${8:-$BUILD_DIR/rpm}" -DEB_PACKAGE_RELEASE="${9:-local.9999}" -RPM_PACKAGE_RELEASE="${10:-local.9999}" +PACKAGE_CONTACT="ROCm Developer Support " +PACKAGE_DESCRIPTION_SUMMARY="A collection of examples for the ROCm software stack" +PACKAGE_HOMEPAGE_URL="https://github.com/ROCm/ROCm-examples" + +# Getopt argument parsing +VALID_ARGS=$(getopt -o hcr --long help,clean,release,root:,pkgname:,version:,install-prefix:,test-install-prefix:,build-dir:,deb-dir:,rpm-dir:,deb-release:,rpm-release:,cpackgen: -- "$@") +if [[ $? -ne 0 ]]; then + echo "Invalid arguments" + exit 1 +fi + +eval set -- "$VALID_ARGS" + +while [ : ]; do + case "$1" in + -h | --help) + echo "Usage: build_rocm_examples.sh [options]" + echo "Options:" + echo " --root Set the root of the ROCm examples" + echo " --pkgname Set the package name" + echo " --version Set the package version" + echo " --install-prefix Set the package install prefix" + echo " --test-install-prefix Set the test package install prefix" + echo " --build-dir Set the build directory" + echo " --deb-dir Set the DEB directory" + echo " --rpm-dir Set the RPM directory" + echo " --deb-release Set the DEB package release" + echo " --rpm-release Set the RPM package release" + echo " --cpackgen Specify the CPack tool" + exit 0 + ;; + --root) + ROCM_EXAMPLES_ROOT="$2" + shift 2 + ;; + --pkgname) + PACKAGE_NAME="$2" + shift 2 + ;; + --version) + PACKAGE_VERSION="$2" + shift 2 + ;; + --install-prefix) + PACKAGE_INSTALL_PREFIX="$2" + shift 2 + ;; + --test-install-prefix) + TEST_PACKAGE_INSTALL_PREFIX="$2" + shift 2 + ;; + --build-dir) + BUILD_DIR="$2" + shift 2 + ;; + --deb-dir) + DEB_DIR="$2" + shift 2 + ;; + --rpm-dir) + RPM_DIR="$2" + shift 2 + ;; + --deb-release) + DEB_PACKAGE_RELEASE="$2" + shift 2 + ;; + --rpm-release) + RPM_PACKAGE_RELEASE="$2" + shift 2 + ;; + --cpackgen) + CPACKGEN="$2" + shift 2 + ;; + --) + shift + break + ;; + esac +done STAGING_DIR="$BUILD_DIR/$PACKAGE_NAME-$PACKAGE_VERSION" TEST_STAGING_DIR="$BUILD_DIR/${PACKAGE_NAME}-test-$PACKAGE_VERSION" @@ -70,6 +152,7 @@ print_input_variables() { echo "RPM_DIR=$RPM_DIR" echo "DEB_PACKAGE_RELEASE=$DEB_PACKAGE_RELEASE" echo "RPM_PACKAGE_RELEASE=$RPM_PACKAGE_RELEASE" + echo "CPACKGEN=$CPACKGEN" echo "************************************" } @@ -321,12 +404,15 @@ copy_sources # Copy CTest files to the test staging directory copy_test_files -# Create DEB and RPM packages -create_deb_package -create_rpm_package +# Conditionally create DEB and RPM packages based on CPACKGEN +if [ -z "$CPACKGEN" ] || [ "$CPACKGEN" == "DEB" ]; then + create_deb_package + create_deb_test_package +fi -# Create DEB and RPM test packages -create_deb_test_package -create_rpm_test_package +if [ -z "$CPACKGEN" ] || [ "$CPACKGEN" == "RPM" ]; then + create_rpm_package + create_rpm_test_package +fi popd || exit From 816026ad4183790976c83f79d53dada2abac25cd Mon Sep 17 00:00:00 2001 From: Mustafa Abdulrahman Date: Thu, 5 Sep 2024 09:55:07 -0400 Subject: [PATCH 2/2] address PR review --- Scripts/Packaging/build_packages.sh | 70 ++++++++++++++--------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/Scripts/Packaging/build_packages.sh b/Scripts/Packaging/build_packages.sh index 9419ac37..c3273806 100755 --- a/Scripts/Packaging/build_packages.sh +++ b/Scripts/Packaging/build_packages.sh @@ -25,24 +25,24 @@ set -e # Default values GIT_TOP_LEVEL=$(git rev-parse --show-toplevel) -ROCM_EXAMPLES_ROOT="$GIT_TOP_LEVEL" PACKAGE_NAME="ROCm-SDK-Examples" PACKAGE_VERSION="6.2.0" +DEB_PACKAGE_RELEASE="local.9999" +RPM_PACKAGE_RELEASE="local.9999" PACKAGE_INSTALL_PREFIX="/opt/rocm/examples" TEST_PACKAGE_INSTALL_PREFIX="/opt/rocm/examples-test" -BUILD_DIR="$ROCM_EXAMPLES_ROOT/build" +SRC_DIR="$GIT_TOP_LEVEL" +BUILD_DIR="$SRC_DIR/build" DEB_DIR="$BUILD_DIR/deb" RPM_DIR="$BUILD_DIR/rpm" -DEB_PACKAGE_RELEASE="local.9999" -RPM_PACKAGE_RELEASE="local.9999" -CPACKGEN="" +PACKGEN="" # Default is both DEB and RPM PACKAGE_CONTACT="ROCm Developer Support " PACKAGE_DESCRIPTION_SUMMARY="A collection of examples for the ROCm software stack" PACKAGE_HOMEPAGE_URL="https://github.com/ROCm/ROCm-examples" # Getopt argument parsing -VALID_ARGS=$(getopt -o hcr --long help,clean,release,root:,pkgname:,version:,install-prefix:,test-install-prefix:,build-dir:,deb-dir:,rpm-dir:,deb-release:,rpm-release:,cpackgen: -- "$@") +VALID_ARGS=$(getopt -o h --long help,pkgname:,version:,deb-release:,rpm-release:,install-prefix:,test-install-prefix:,src-dir:,build-dir:,deb-dir:,rpm-dir:,packgen: -- "$@") if [[ $? -ne 0 ]]; then echo "Invalid arguments" exit 1 @@ -53,25 +53,21 @@ eval set -- "$VALID_ARGS" while [ : ]; do case "$1" in -h | --help) - echo "Usage: build_rocm_examples.sh [options]" + echo "Usage: build_packages.sh [options]" echo "Options:" - echo " --root Set the root of the ROCm examples" echo " --pkgname Set the package name" echo " --version Set the package version" + echo " --deb-release Set the DEB package release info (used to generate filename)" + echo " --rpm-release Set the RPM package release info (used to generate filename)" echo " --install-prefix Set the package install prefix" echo " --test-install-prefix Set the test package install prefix" + echo " --src-dir Set the source directory" echo " --build-dir Set the build directory" echo " --deb-dir Set the DEB directory" echo " --rpm-dir Set the RPM directory" - echo " --deb-release Set the DEB package release" - echo " --rpm-release Set the RPM package release" - echo " --cpackgen Specify the CPack tool" + echo " --packgen Specify the package format. Options 'DEB' or 'RPM'. Default: '', which generates both." exit 0 ;; - --root) - ROCM_EXAMPLES_ROOT="$2" - shift 2 - ;; --pkgname) PACKAGE_NAME="$2" shift 2 @@ -80,6 +76,14 @@ while [ : ]; do PACKAGE_VERSION="$2" shift 2 ;; + --deb-release) + DEB_PACKAGE_RELEASE="$2" + shift 2 + ;; + --rpm-release) + RPM_PACKAGE_RELEASE="$2" + shift 2 + ;; --install-prefix) PACKAGE_INSTALL_PREFIX="$2" shift 2 @@ -88,6 +92,10 @@ while [ : ]; do TEST_PACKAGE_INSTALL_PREFIX="$2" shift 2 ;; + --src-dir) + SRC_DIR="$2" + shift 2 + ;; --build-dir) BUILD_DIR="$2" shift 2 @@ -100,16 +108,8 @@ while [ : ]; do RPM_DIR="$2" shift 2 ;; - --deb-release) - DEB_PACKAGE_RELEASE="$2" - shift 2 - ;; - --rpm-release) - RPM_PACKAGE_RELEASE="$2" - shift 2 - ;; - --cpackgen) - CPACKGEN="$2" + --packgen) + PACKGEN="$2" shift 2 ;; --) @@ -142,17 +142,17 @@ SOURCE_DIRS=( print_input_variables() { echo "********** Input Variables **********" - echo "ROCM_EXAMPLES_ROOT=$ROCM_EXAMPLES_ROOT" echo "PACKAGE_NAME=$PACKAGE_NAME" echo "PACKAGE_VERSION=$PACKAGE_VERSION" + echo "DEB_PACKAGE_RELEASE=$DEB_PACKAGE_RELEASE" + echo "RPM_PACKAGE_RELEASE=$RPM_PACKAGE_RELEASE" echo "PACKAGE_INSTALL_PREFIX=$PACKAGE_INSTALL_PREFIX" echo "TEST_PACKAGE_INSTALL_PREFIX=$TEST_PACKAGE_INSTALL_PREFIX" + echo "SRC_DIR=$SRC_DIR" echo "BUILD_DIR=$BUILD_DIR" echo "DEB_DIR=$DEB_DIR" echo "RPM_DIR=$RPM_DIR" - echo "DEB_PACKAGE_RELEASE=$DEB_PACKAGE_RELEASE" - echo "RPM_PACKAGE_RELEASE=$RPM_PACKAGE_RELEASE" - echo "CPACKGEN=$CPACKGEN" + echo "PACKGEN=$PACKGEN" echo "************************************" } @@ -160,7 +160,7 @@ build_project() { echo "** Building the project **" mkdir -p "$BUILD_DIR" pushd "$BUILD_DIR" || exit - cmake -DCMAKE_INSTALL_PREFIX="$PACKAGE_INSTALL_PREFIX" -DGPU_ARCHITECTURES=all "$ROCM_EXAMPLES_ROOT" + cmake -DCMAKE_INSTALL_PREFIX="$PACKAGE_INSTALL_PREFIX" -DGPU_ARCHITECTURES=all "$SRC_DIR" make -j$(nproc) popd || exit } @@ -171,13 +171,13 @@ copy_sources() { echo "** Copying sources to $STAGING_DIR **" # Copy source files in root to package - cp "$ROCM_EXAMPLES_ROOT/LICENSE.md" "$ROCM_EXAMPLES_ROOT/CMakeLists.txt" "$ROCM_EXAMPLES_ROOT/README.md" "$STAGING_DIR" + cp "$SRC_DIR/LICENSE.md" "$SRC_DIR/CMakeLists.txt" "$SRC_DIR/README.md" "$STAGING_DIR" # Copy source directories to package for dir in "${SOURCE_DIRS[@]}"; do rsync -a --exclude 'build' --exclude '.gitignore' \ --exclude '*.vcxproj**' --exclude '*.sln' --exclude 'bin' \ - --exclude '*.o' --exclude '*.exe' "$ROCM_EXAMPLES_ROOT/$dir" "$STAGING_DIR" + --exclude '*.o' --exclude '*.exe' "$SRC_DIR/$dir" "$STAGING_DIR" done } @@ -404,13 +404,13 @@ copy_sources # Copy CTest files to the test staging directory copy_test_files -# Conditionally create DEB and RPM packages based on CPACKGEN -if [ -z "$CPACKGEN" ] || [ "$CPACKGEN" == "DEB" ]; then +# Conditionally create DEB and RPM packages based on PACKGEN +if [ -z "$PACKGEN" ] || [ "$PACKGEN" == "DEB" ]; then create_deb_package create_deb_test_package fi -if [ -z "$CPACKGEN" ] || [ "$CPACKGEN" == "RPM" ]; then +if [ -z "$PACKGEN" ] || [ "$PACKGEN" == "RPM" ]; then create_rpm_package create_rpm_test_package fi