From 30ce23e55f29355174a3be830fd04f37dd601c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=99=A8=E5=8D=89?= Date: Tue, 3 Jun 2025 20:08:25 +0800 Subject: [PATCH] Dynamically set SRC_BRANCH from git. (cherry picked from commit ced46c54ef35ae1653b793e6a052125cbcea5f71) --- download.sh | 19 +++++++++---------- gcc-cross.spec | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/download.sh b/download.sh index 7903f1e..da86fbf 100755 --- a/download.sh +++ b/download.sh @@ -5,9 +5,7 @@ readonly LIB_PATH="$PWD/../open_source" source $PWD/config.xml build_rpmdir=`rpm --eval "%{_builddir}"` src_rpmdir=`rpm --eval "%{_sourcedir}"` -SRC_BRANCH="openEuler-25.03" - -#judge the open_source +echo $SRC_BRANCH [ ! -d "$LIB_PATH" ] && mkdir $LIB_PATH @@ -35,25 +33,26 @@ function do_patch() { fi popd } -echo "Download $GCC" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/gcc.git + +echo "Download $GCC" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/gcc.git --depth 1 do_patch $GCC -echo "Download $GLIBC" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/glibc.git +echo "Download $GLIBC" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/glibc.git --depth 1 do_patch $GLIBC -echo "Download $BINUTILS" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/binutils.git +echo "Download $BINUTILS" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/binutils.git --depth 1 do_patch $BINUTILS -echo "Download $GMP" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/gmp.git +echo "Download $GMP" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/gmp.git --depth 1 do_patch $GMP -echo "Download $MPFR" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/mpfr.git +echo "Download $MPFR" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/mpfr.git --depth 1 do_patch $MPFR -echo "Download $MPC" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/libmpc.git +echo "Download $MPC" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/libmpc.git --depth 1 do_patch $MPC -echo "Download $ISL" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/isl.git +echo "Download $ISL" && git clone -b $SRC_BRANCH https://gitee.com/src-openeuler/isl.git --depth 1 do_patch $ISL echo "Download $LINUX_KERNEL" && git clone -b 6.4.0-1.0.1 https://gitee.com/openeuler/kernel.git --depth 1 diff --git a/gcc-cross.spec b/gcc-cross.spec index 29480c9..950865f 100644 --- a/gcc-cross.spec +++ b/gcc-cross.spec @@ -1,7 +1,7 @@ Summary: C/C++ Cross Compiler Toolchain Name: gcc-cross Version: 1.0 -Release: 8 +Release: 9 # libgcc, libgfortran, libmudflap, libgomp, libstdc++ and crtstuff have # GCC Runtime Exception. License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD @@ -30,12 +30,50 @@ cd %{_builddir}/%{name}-%{version} cp -r %{_sourcedir}/* ./ %build +export SRC_BRANCH="%{dist}" + +parse_branch() { + local raw_branch=$(echo "$SRC_BRANCH" | sed 's/^[ .]*//' | tr '[:upper:]' '[:lower:]') + + if [[ ! "$raw_branch" =~ ^oe([0-9]{2})([0-9]{2})(sp[0-9]+)?$ ]]; then + echo "错误:分支格式不正确" >&2 + return 1 + fi + + local major=${BASH_REMATCH[1]} + local minor=${BASH_REMATCH[2]} + local sp=${BASH_REMATCH[3]} + local version="${major}.${minor}" + + # 构建候选分支列表 + local candidates=() + if [[ -n "$sp" ]]; then + candidates+=("openEuler-${version}-LTS-${sp^^}") + else + candidates+=("openEuler-${version}-LTS-Next") + candidates+=("openEuler-${version}") + fi + + # 验证分支存在性 + for branch in "${candidates[@]}"; do + if git ls-remote --heads https://gitee.com/src-openeuler/gcc.git "$branch" | grep -q "refs/heads/$branch"; then + SRC_BRANCH="$branch" + return 0 + fi + done + + echo "错误:未找到有效的 ${version} 系列分支" >&2 + return 1 +} +parse_branch +export SRC_BRANCH + cd %{_builddir}/%{name}-%{version} files=$(ls *.tar.gz 2> /dev/null | wc -l) if [ "$files" != 0 ]; then ls *.tar.gz | xargs -n1 tar xvf fi -bash download.sh +./download.sh bash build.sh gcc_arm64le & bash build.sh gcc_arm32le wait @@ -50,6 +88,12 @@ cp %{_builddir}/output/gcc_arm32le/gcc_arm32le.tar.gz %{buildroot}/tmp %attr(755, root, root) /tmp/gcc_arm32le.tar.gz %changelog +* Tue Jun 3 2025 zhengchenhui - 1.0-9 +-Type:Refactor +-ID:NA +-SUG:NA +-DESC: Dynamically set SRC_BRANCH from git. + * Thu Feb 20 2025 zhengchenhui - 1.0-8 -Type:Fix -ID:NA -- Gitee