From b0bdac9502c59878a11e5522a6ed728c43056ac0 Mon Sep 17 00:00:00 2001 From: Hongyu Shi Date: Tue, 12 Aug 2025 19:15:28 +0800 Subject: [PATCH] feat(build): add build scripts Signed-off-by: Hongyu Shi --- .gitignore | 3 +++ README.md | 39 ++++++++++++++++++++++++++------- scripts/build/build_rpm.sh | 29 ++++++++++++++++++++++++ scripts/build/create_tarball.sh | 23 +++++++++++++++++++ 4 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 scripts/build/build_rpm.sh create mode 100644 scripts/build/create_tarball.sh diff --git a/.gitignore b/.gitignore index dcce618..9d90b27 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ **/*.egg-info/ **/*.so **/*.o +# 保留 scripts/build 目录 +!scripts/build/ +!scripts/build/** .env diff --git a/README.md b/README.md index aa50b91..dab8989 100644 --- a/README.md +++ b/README.md @@ -284,17 +284,40 @@ oi --init 日志文件同时输出到控制台和文件,便于开发调试和生产环境监控。详细说明请参考 [日志功能文档](docs/development/日志功能说明.md)。 -## RPM 打包 +## 在 openEuler 系统下的 RPM 打包 -我们提供了一个 spec 文件,可以使用 PyInstaller 打包并生成 RPM 包: +以下步骤演示如何在 openEuler 24.03 LTS 或更高版本上,使用自带脚本打包生成 RPM 包。 -```sh -# 创建源代码归档 -tar czf euler-copilot-shell-0.10.0.tar.gz --transform 's,^smart-shell,euler-copilot-shell-0.10.0,' smart-shell +前提条件: -# 构建RPM包(需要已安装rpm-build工具) -rpmbuild -ba distribution/linux/euler-copilot-shell.spec -``` +- 操作系统:openEuler 24.03 LTS 或更高版本 +- 工具依赖:rpmdevtools、git、bash +- 具有管理员权限(sudo) + +构建步骤: + +1. 克隆仓库并切换到对应分支: + + ```sh + git clone https://gitee.com/openeuler/euler-copilot-shell.git + cd euler-copilot-shell + git checkout main + ``` + +2. 为构建脚本添加可执行权限: + + ```sh + chmod +x scripts/build/create_tarball.sh scripts/build/build_rpm.sh + ``` + +3. 运行 RPM 构建脚本: + + ```sh + cd scripts/build + ./build_rpm.sh + ``` + + 脚本执行完成后,会在临时构建目录下的 `RPMS` 和 `SRPMS` 子目录中生成相应的二进制包和源码包,并在终端输出具体路径。 ## 高级功能 diff --git a/scripts/build/build_rpm.sh b/scripts/build/build_rpm.sh new file mode 100644 index 0000000..a929b29 --- /dev/null +++ b/scripts/build/build_rpm.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# build_rpm.sh: build RPM package using the tarball created by create_tarball.sh +set -euo pipefail + +# Determine script directory and repo root +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" + +# Create the tarball and set BUILD_DIR and TARBALL +eval "$("${SCRIPT_DIR}/create_tarball.sh")" + +# Spec file path +SPEC_FILE="${REPO_ROOT}/distribution/linux/euler-copilot-shell.spec" + +# Prepare RPM build directories under BUILD_DIR +mkdir -p "${BUILD_DIR}/"{BUILD,RPMS,SOURCES,SPECS,SRPMS,BUILDROOT} + +# Copy source tarball and spec into RPM tree +cp "${BUILD_DIR}/${TARBALL}" "${BUILD_DIR}/SOURCES/" +cp "${SPEC_FILE}" "${BUILD_DIR}/SPECS/" + +# Build the RPMs +echo "Building RPM using topdir ${BUILD_DIR}" +rpmbuild --define "_topdir ${BUILD_DIR}" -ba "${BUILD_DIR}/SPECS/$(basename "${SPEC_FILE}")" + +# Output locations +echo "RPM build complete." +echo "SRPMs: ${BUILD_DIR}/SRPMS" +echo "Binary RPMs: ${BUILD_DIR}/RPMS" diff --git a/scripts/build/create_tarball.sh b/scripts/build/create_tarball.sh new file mode 100644 index 0000000..3f6c8bc --- /dev/null +++ b/scripts/build/create_tarball.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# create_tarball.sh: create a tarball of current repo for RPM build. +set -euo pipefail + +# Locate spec file relative to repo root +SPEC_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/distribution/linux/euler-copilot-shell.spec" + +# Extract name and version from spec +NAME=$(grep -E '^Name:' "$SPEC_FILE" | awk '{print $2}') +VERSION=$(grep -E '^Version:' "$SPEC_FILE" | awk '{print $2}') + +# Create temporary build directory +BUILD_DIR=$(mktemp -d) +TARBALL="${NAME}-${VERSION}.tar.gz" + +echo "Creating tarball ${TARBALL} in ${BUILD_DIR}" +# Archive the current HEAD into tarball with proper prefix +git archive --format=tar.gz --prefix="${NAME}-${VERSION}/" -o "${BUILD_DIR}/${TARBALL}" HEAD + +# Export variables for reuse by build_rpm.sh +# Usage: eval "$(./create_tarball.sh)" +echo "export BUILD_DIR=${BUILD_DIR}" +echo "export TARBALL=${TARBALL}" -- Gitee