diff --git a/auto_package_rust/Readme.md b/auto_package_rust/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..d89c29bb444cd7da49d3224f744b91f0d04e939e --- /dev/null +++ b/auto_package_rust/Readme.md @@ -0,0 +1,25 @@ +## 安装配置 + +``` +#安装 rust2rpm,建议更新为26.1.1以上版本 +dnf install rust2rpm + +#安装脚本所需工具 +dnf install -y rpm-build rpmdevtools + +# changelog中name、email来源于git config +dnf install -y git +git config --global user.email @tencent.com +git config --global user.name +``` + +## 自动打包 +执行章节2.3脚本,一键式打包。参考用法: + +``` +# rust_package.sh 为上述脚本,pyo3为rust的crates名称 +sh rust_package.sh pyo3 +``` + +执行脚本后,本地生成 rust-pyo3 软件包仓库。 +参考示例:https://gitee.com/opencloudos-stream/rust-pyo3/pulls/1 diff --git a/auto_package_rust/rust_package.sh b/auto_package_rust/rust_package.sh new file mode 100755 index 0000000000000000000000000000000000000000..c484ae96f5df00d1f7012da1625b191c3bb64070 --- /dev/null +++ b/auto_package_rust/rust_package.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -e + +function modify_spec(){ + # 按照S-N-V-R-L-U排序 + summary_line=$(grep "^Summary:" "${spec_file}" | head -1) + sed -i "/^${summary_line}/d" "${spec_file}" + sed -i "s/^Name:/${summary_line}\nName:/" "${spec_file}" + # 移除Release后空行 + sed -i '/^Release:/ {N; s/\n$//}' "${spec_file}" + # Source规范命名 + sed -i 's/^Source: %{crates_source}/Source0: %{crates_source}/' "$spec_file" + sed -i 's/^Source: /Source1:/' "$spec_file" + # 移除FIXME + sed -i '/# FIXME: paste output of %%cargo_license_summary here/d' "$spec_file" + sed -i '/License: # FIXME/d' "$spec_file" + + # 补丁编号 + awk ' + BEGIN { patch_num = 3000 } + /^Patch:/ { + sub("Patch:", "Patch" patch_num ":", $0) + patch_num++ + } + { print } + ' "${spec_file}" > "${spec_file}.tmp" && mv "${spec_file}.tmp" "${spec_file}" + + echo "### Edit spec completed! ###" +} + + +crate_name="$1" +repo_name="rust-${crate_name}" +spec_file="${repo_name}.spec" + +rm -rf ${repo_name} +# create repo +mkdir -p ${repo_name} +cd ${repo_name} + +echo "#******************** 1.generate spec ********************#" +# -s:下载Source0 --vendor: 生成并使用vendor +rust2rpm --no-existence-check ${crate_name} -s --vendor + +echo "#********************** 2.edit spec **********************#" +modify_spec +