Skip to content

Commit

Permalink
Generating DEB and RPM files with the source from the rocm-examples. (#…
Browse files Browse the repository at this point in the history
…143)

* copy changes from #131

* exclude binary, object and executable files

* test "bin/*" exclusion

* add build_packages.sh script to generate deb and rpm files from source

* fix issues with rpm file generation

* revert changes to CMakeLists.txt

* add directive ective that prevents the RPM build process from terminating due to missing build ID

* Set build_packages.sh to executable

Signed-off-by: David Galiffi <[email protected]>

* address PR review comments

* Renamed 'packaging' to 'Packaging'

To match casing of the other subfolders

Signed-off-by: David Galiffi <[email protected]>

* Refactor build script to accept PACKAGE_VERSION as a parameter and define PACKAGE_HOMEPAGE_URL variable for consistency in DEB and RPM packages.

* disable the generation of debug packages

* add PACKAGE_NAME,
PACKAGE_VERSION,
PACKAGE_INSTALL_PREFIX,
BUILD_DIR as arguments and add default values

* Add DEB_DIR and RPM_DIRas arguments

Signed-off-by: David Galiffi <[email protected]>

* Fix DEB package directory structure

* Removed "PACKAGE_VENDOR" as it is not used.

* Make RPM_*_DIR variables local to create_rpm_package

* Refactor create_deb_package

Using the "cat EOF" to create DEBIAN/control, rather than multiple "echo" statments. Similar to how the RPM spec files is generated.

* Add DEB_PACKAGE_RELEASE and RPM_PACKAGE_RELEASE as arguments.

* Create a STAGING_DIR contant

Use "STAGING_DIR" constant rather than input parameter to helper functions. This matches the style of other constants being used, like BUILD_DIR and SOURCE_DIR

* Print input variables

Useful for build logs.

* Remove the "clean up" at the end of the package generation.

Artifacts can be used for debugging.

* Add a log at each step

* Fix linting errors found with "shellcheck"

* Another linting issue.

---------

Signed-off-by: David Galiffi <[email protected]>
Co-authored-by: David Galiffi <[email protected]>
  • Loading branch information
Mustaballer and dgaliffiAMD authored Jul 29, 2024
1 parent 92786e2 commit 2e4abc4
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2022-2024 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,7 +21,7 @@
# SOFTWARE.

cmake_minimum_required(VERSION 3.21.3 FATAL_ERROR)
project(ROCMm-SDK-Examples LANGUAGES CXX)
project(ROCm-SDK-Examples LANGUAGES CXX VERSION 6.2.0)
enable_testing()

add_subdirectory(Applications)
Expand Down
201 changes: 201 additions & 0 deletions Scripts/Packaging/build_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
#!/bin/bash
# MIT License
#
# Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set -e

GIT_TOP_LEVEL=$(git rev-parse --show-toplevel)

# Inputs and Defaults
PACKAGE_NAME="${1:-ROCm-SDK-Examples}"
PACKAGE_VERSION="${2:-6.2.0}"
PACKAGE_INSTALL_PREFIX="${3:-/opt/rocm/examples}"
BUILD_DIR="${4:-$GIT_TOP_LEVEL/build}"
DEB_DIR="${5:-$BUILD_DIR/deb}"
RPM_DIR="${6:-$BUILD_DIR/rpm}"
DEB_PACKAGE_RELEASE="${7:-local.9999}"
RPM_PACKAGE_RELEASE="${8:-local.9999}"

STAGING_DIR="$BUILD_DIR"/"$PACKAGE_NAME"-"$PACKAGE_VERSION"

PACKAGE_CONTACT="ROCm Developer Support <[email protected]>"
PACKAGE_DESCRIPTION_SUMMARY="A collection of examples for the ROCm software stack"
PACKAGE_HOMEPAGE_URL="https://github.com/ROCm/ROCm-examples"

# Directories to be included in the package
SOURCE_DIRS=(
"AI"
"Applications"
"Common"
"Dockerfiles"
"External"
"HIP-Basic"
"Libraries"
"LLVM_ASAN"
)


print_input_variables() {
echo "********** Input Variables **********"
echo "PACKAGE_NAME=$PACKAGE_NAME"
echo "PACKAGE_VERSION=$PACKAGE_VERSION"
echo "PACKAGE_INSTALL_PREFIX=$PACKAGE_INSTALL_PREFIX"
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 "************************************"
}


copy_sources() {
mkdir -p "$STAGING_DIR"

echo "** Copying sources to $STAGING_DIR **"

# Copy source files in root to package
cp LICENSE.md CMakeLists.txt 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' "$dir" "$STAGING_DIR"
done
}

create_deb_package() {
local deb_root="$BUILD_DIR/deb_tmp"
local deb_install_dir="$deb_root/$PACKAGE_INSTALL_PREFIX"
local deb_control_file="$deb_root/DEBIAN/control"

# Create directories for DEB package artifacts
mkdir -p "$deb_root/DEBIAN" "$deb_install_dir"

echo "** Creating DEB package in $DEB_DIR **"

# Copy the sources to the install directory
cp -r "$STAGING_DIR"/* "$deb_install_dir"/

# Create control file
cat <<EOF >"$deb_control_file"
Package: $PACKAGE_NAME
Version: $PACKAGE_VERSION
Architecture: amd64
Maintainer: $PACKAGE_CONTACT
Description: $PACKAGE_DESCRIPTION_SUMMARY
Homepage: $PACKAGE_HOMEPAGE_URL
Depends:
Section: devel
Priority: optional
EOF

# Build DEB package
fakeroot dpkg-deb --build "$deb_root" \
"$DEB_DIR"/"$PACKAGE_NAME"_"$PACKAGE_VERSION"-"$DEB_PACKAGE_RELEASE"_amd64.deb

# Clean up
# rm -rf $deb_root
}

create_rpm_package() {
local rpm_root="$BUILD_DIR"/rpm_tmp
local rpm_build_dir="$rpm_root/BUILD"
local rpm_rpms_dir="$rpm_root/RPMS"
local rpm_source_dir="$rpm_root/SOURCES"
local rpm_spec_dir="$rpm_root/SPECS"
local rpm_srpm_dir="$rpm_root/SRPMS"

local spec_file="$rpm_spec_dir/$PACKAGE_NAME.spec"

# Create directories for all the RPM build artifacts
mkdir -p "$rpm_build_dir" "$rpm_rpms_dir" "$rpm_source_dir" "$rpm_spec_dir" "$rpm_srpm_dir"

echo "** Creating RPM package in $RPM_DIR **"

# Create the spec file
cat <<EOF > "$spec_file"
%define _build_id_links none
%global debug_package %{nil}
Name: $PACKAGE_NAME
Version: $PACKAGE_VERSION
Release: $RPM_PACKAGE_RELEASE%{?dist}
Summary: $PACKAGE_DESCRIPTION_SUMMARY
License: MIT
URL: $PACKAGE_HOMEPAGE_URL
Source0: %{name}-%{version}.tar.gz
BuildArch: %{_arch}
%description
$PACKAGE_DESCRIPTION_SUMMARY
%prep
%setup -q
%build
%install
mkdir -p %{buildroot}$PACKAGE_INSTALL_PREFIX
cp -r * %{buildroot}$PACKAGE_INSTALL_PREFIX
%files
$PACKAGE_INSTALL_PREFIX
%changelog
EOF

# Create source tarball
tar czf "$rpm_source_dir/$PACKAGE_NAME-$PACKAGE_VERSION.tar.gz" \
-C "$BUILD_DIR" "$PACKAGE_NAME"-"$PACKAGE_VERSION"

# Build the RPM package
rpmbuild --define "_topdir $rpm_root" -ba "$spec_file"

# Move the generated RPM file to RPM_DIR
find "$rpm_rpms_dir" -name "$PACKAGE_NAME-$PACKAGE_VERSION-*.rpm" -exec mv {} "$RPM_DIR" \;

# Clean up
# rm -rf $rpm_build_dir $rpm_source_dir $rpm_spec_dir $rpm_rpms_dir $rpm_srpm_dir
}

## Main Program ##

# Clean up previous build artifacts
rm -rf "$BUILD_DIR"
mkdir -p "$STAGING_DIR" "$DEB_DIR" "$RPM_DIR"

pushd "$GIT_TOP_LEVEL" || exit

# Print input variables
print_input_variables

# Copy sources to build directory
copy_sources

# Create DEB package
create_deb_package

# Create RPM package
create_rpm_package

popd || exit

0 comments on commit 2e4abc4

Please sign in to comment.