From 00f01556c0ef18c6f781593af2e5508a7b61d6c4 Mon Sep 17 00:00:00 2001 From: Julian Zhu Date: Sun, 8 Feb 2026 17:43:33 +0800 Subject: [PATCH 1/4] Add more infomation for spec --- spec.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/spec.go b/spec.go index bba9cbb..47a1daa 100644 --- a/spec.go +++ b/spec.go @@ -47,6 +47,14 @@ func writeSpec(dir, gopkg, openRuyiSrc, openRuyiLib, openRuyiProgram, version st // Write the spec file content + // SPDX header + fmt.Fprintf(f, "# SPDX-FileCopyrightText: (C) 2026 Institute of Software, Chinese Academy of Sciences (ISCAS)\n") + fmt.Fprintf(f, "# SPDX-FileCopyrightText: (C) 2026 openRuyi Project Contributors\n") + fmt.Fprintf(f, "# SPDX-FileContributor: \n") + fmt.Fprintf(f, "#\n") + fmt.Fprintf(f, "# SPDX-License-Identifier: MulanPSL-2.0\n") + fmt.Fprintf(f, "\n") + // Macros fmt.Fprintf(f, "%%define _name %s\n", upstreamName) fmt.Fprintf(f, "%%define go_import_path %s\n", gopkg) @@ -59,17 +67,20 @@ func writeSpec(dir, gopkg, openRuyiSrc, openRuyiLib, openRuyiProgram, version st fmt.Fprintf(f, "Summary: %s\n", description) fmt.Fprintf(f, "License: %s\n", license) fmt.Fprintf(f, "URL: https://github.com/%s/%s\n", owner, repo) + fmt.Fprintf(f, "#!RemoteAsset\n") fmt.Fprintf(f, "Source0: https://github.com/%s/%s/archive/v%%{version}.tar.gz#/%%{_name}-%%{version}.tar.gz\n", owner, repo) switch pkgType { case typeLibrary: fmt.Fprintf(f, "BuildArch: noarch\n") + fmt.Fprintf(f, "BuildSystem: golangmodules\n") fmt.Fprintf(f, "\n") case typeProgram, typeLibraryProgram, typeProgramLibrary: fmt.Fprintf(f, "\n") } fmt.Fprintf(f, "BuildRequires: go\n") + fmt.Fprintf(f, "BuildRequires: go-rpm-macros\n") // And other BuildRequires from dependencies rpmDeps := convertDependenciesToRPM(dependencies) sort.Strings(rpmDeps) @@ -137,8 +148,8 @@ func writeSpec(dir, gopkg, openRuyiSrc, openRuyiLib, openRuyiProgram, version st switch pkgType { case typeLibrary: fmt.Fprintf(f, "# Install source code for library package\n") - fmt.Fprintf(f, "install -d %%{buildroot}%%{_datadir}/gocode/src/%%{go_import_path}\n") - fmt.Fprintf(f, "cp -a . %%{buildroot}%%{_datadir}/gocode/src/%%{go_import_path}\n") + fmt.Fprintf(f, "install -d %%{buildroot}%%{go_sys_gopath}/%%{go_import_path}\n") + fmt.Fprintf(f, "cp -a . %%{buildroot}%%{go_sys_gopath}/%%{go_import_path}\n") case typeProgram: fmt.Fprintf(f, "install -D -m 0755 %%{_name} %%{buildroot}%%{_bindir}/%%{_name}\n") case typeLibraryProgram, typeProgramLibrary: @@ -146,8 +157,8 @@ func writeSpec(dir, gopkg, openRuyiSrc, openRuyiLib, openRuyiProgram, version st fmt.Fprintf(f, "install -D -m 0755 %%{_name} %%{buildroot}%%{_bindir}/%%{_name}\n") fmt.Fprintf(f, "\n") fmt.Fprintf(f, "# Install source code for library package\n") - fmt.Fprintf(f, "install -d %%{buildroot}%%{_datadir}/gocode/src/%%{go_import_path}\n") - fmt.Fprintf(f, "cp -a . %%{buildroot}%%{_datadir}/gocode/src/%%{go_import_path}\n") + fmt.Fprintf(f, "install -d %%{buildroot}%%{go_sys_gopath}/%%{go_import_path}\n") + fmt.Fprintf(f, "cp -a . %%{buildroot}%%{go_sys_gopath}/%%{go_import_path}\n") } fmt.Fprintf(f, "\n") @@ -171,7 +182,7 @@ func writeSpec(dir, gopkg, openRuyiSrc, openRuyiLib, openRuyiProgram, version st // For library package func writeRPMLibraryPackage(f *os.File, gopkg, openRuyiLib, longdesc string, deps []string) { fmt.Fprintf(f, "\n") - fmt.Fprintf(f, "Provides: go(%s)\n", gopkg) + fmt.Fprintf(f, "Provides: go(%s) = %%{version}\n", gopkg) // 库包的运行时依赖 if len(deps) > 0 { for _, dep := range deps { @@ -186,7 +197,7 @@ func writeRPMLibrarySubpackage(f *os.File, gopkg, openRuyiLib, openRuyiSrc, long fmt.Fprintf(f, "\n") fmt.Fprintf(f, "%%package -n %s\n", openRuyiLib) fmt.Fprintf(f, "Summary: Development files of %s\n", filepath.Base(gopkg)) - fmt.Fprintf(f, "Provides: go(%s)\n", gopkg) + fmt.Fprintf(f, "Provides: go(%s) = %%{version}\n", gopkg) fmt.Fprintf(f, "BuildArch: noarch\n") for _, dep := range deps { fmt.Fprintf(f, "Requires: %s\n", dep) @@ -216,7 +227,7 @@ func writeRPMFilesSection(f *os.File, openRuyiSrc, openRuyiLib, openRuyiProgram fmt.Fprintf(f, "%%files\n") fmt.Fprintf(f, "%%license LICENSE*\n") fmt.Fprintf(f, "%%doc README*\n") - fmt.Fprintf(f, "%%{_datadir}/gocode/src/%%{go_import_path}\n") + fmt.Fprintf(f, "%%{go_sys_gopath}/%%{go_import_path}\n") fmt.Fprintf(f, "\n") case typeProgram: @@ -231,7 +242,7 @@ func writeRPMFilesSection(f *os.File, openRuyiSrc, openRuyiLib, openRuyiProgram fmt.Fprintf(f, "%%files\n") fmt.Fprintf(f, "%%license LICENSE*\n") fmt.Fprintf(f, "%%doc README*\n") - fmt.Fprintf(f, "%%{_datadir}/gocode/src/%%{go_import_path}\n") + fmt.Fprintf(f, "%%{go_sys_gopath}/%%{go_import_path}\n") fmt.Fprintf(f, "\n") // 程序子包文件 fmt.Fprintf(f, "%%files -n %s\n", openRuyiProgram) @@ -249,7 +260,7 @@ func writeRPMFilesSection(f *os.File, openRuyiSrc, openRuyiLib, openRuyiProgram // 库子包文件 fmt.Fprintf(f, "%%files -n %s\n", openRuyiLib) fmt.Fprintf(f, "%%license LICENSE*\n") - fmt.Fprintf(f, "%%{_datadir}/gocode/src/%%{go_import_path}\n") + fmt.Fprintf(f, "%%{go_sys_gopath}/%%{go_import_path}\n") fmt.Fprintf(f, "\n") } } -- 2.52.0 From dae5376f71de87023bf300eb6b35139b0a36ae65 Mon Sep 17 00:00:00 2001 From: Julian Zhu Date: Sun, 8 Feb 2026 17:48:05 +0800 Subject: [PATCH 2/4] Adjust the spec folder detection logic --- pack.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pack.go b/pack.go index c2e4451..f507ab1 100644 --- a/pack.go +++ b/pack.go @@ -676,6 +676,24 @@ func mainPack(args []string, usage func()) { gopkg, strings.ToLower(gopkg)) } + info, err := os.Stat(openRuyiSrc) + if err == nil { + if !info.IsDir() { + log.Fatalf("%q exists but is not a directory\n", openRuyiSrc) + } + + entries, err := os.ReadDir(openRuyiSrc) + if err != nil { + log.Fatalf("Failed to read directory %q: %v\n", openRuyiSrc, err) + } + + if len(entries) != 0 { + log.Fatalf("Output directory %q exists and is non-empty, aborting\n", openRuyiSrc) + } + } else if !os.IsNotExist(err) { + log.Fatalf("Failed to stat %q: %v\n", openRuyiSrc, err) + } + // Create a tarball of the upstream source u, err := makeUpstreamSourceTarball(gopkg, gitRevision, forcePrerelease) if err != nil { @@ -692,10 +710,6 @@ func mainPack(args []string, usage func()) { } } - if _, err := os.Stat(openRuyiSrc); err == nil { - log.Fatalf("Output directory %q already exists, aborting\n", openRuyiSrc) - } - orig := fmt.Sprintf("%s_%s.orig.tar.%s", openRuyiSrc, u.version, u.compression) log.Printf("Moving tempfile to %q\n", orig) // We need to copy the file, merely renaming is not enough since the file -- 2.52.0 From 0f07c4ba1a6c72864548925c38ef11f695998098 Mon Sep 17 00:00:00 2001 From: Julian Zhu Date: Sun, 8 Feb 2026 22:12:43 +0800 Subject: [PATCH 3/4] Write full commit hash id into spec --- check_version.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/check_version.go b/check_version.go index f4a1d24..5619509 100644 --- a/check_version.go +++ b/check_version.go @@ -153,6 +153,16 @@ func pkgVersionFromGit(gitdir string, u *upstream, preferredRev string, forcePre lastCommitHash = string(submatches[1]) u.commitIsh = strings.TrimSpace(string(describeBytes)) } + + // Fetch full commit hash + cmd = exec.Command("git", "rev-parse", "HEAD") + cmd.Dir = gitdir + fullCommitHashBytes, err := cmd.Output() + if err != nil { + return "", fmt.Errorf("git rev-parse HEAD: %w", err) + } + fullCommitHash := strings.TrimSpace(string(fullCommitHashBytes)) + u.version = fmt.Sprintf("%sgit%s.%s", mainVer, time.Unix(lastCommitUnix, 0).UTC().Format("20060102"), @@ -162,8 +172,8 @@ func pkgVersionFromGit(gitdir string, u *upstream, preferredRev string, forcePre // have tag: 1.2.3.20250101+git9f107c8 u.version = fmt.Sprintf("%s.%s+git%s", u.version, dateStr, lastCommitHash) } else { - // without tag: 20250101+git9f107c8 - u.version = fmt.Sprintf("%s+git%s", dateStr, lastCommitHash) + // without tag: 0.git20250101.96ee002 96ee0021ea0fb9174681b8004d8deba3c499d7f5 + u.version = fmt.Sprintf("0.git%s.%s\n%%define commit_id %s", dateStr, lastCommitHash, fullCommitHash) } return u.version, nil } -- 2.52.0 From dafc545bb61000e191d09ecc033b1b02b276f091 Mon Sep 17 00:00:00 2001 From: Julian Zhu Date: Sun, 8 Feb 2026 22:14:50 +0800 Subject: [PATCH 4/4] Remove prep/build/check part, they was replace by go-rpm-macros --- spec.go | 58 --------------------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/spec.go b/spec.go index 47a1daa..4e75230 100644 --- a/spec.go +++ b/spec.go @@ -111,64 +111,6 @@ func writeSpec(dir, gopkg, openRuyiSrc, openRuyiLib, openRuyiProgram, version st fmt.Fprintf(f, "%s\n", longdescription) fmt.Fprintf(f, "\n") - // %prep - fmt.Fprintf(f, "%%prep\n") - fmt.Fprintf(f, "%%autosetup -n %%{_name}-%%{version}\n") - switch pkgType { - case typeProgram, typeLibraryProgram, typeProgramLibrary: - fmt.Fprintf(f, "mkdir -p %%{_builddir}/go/src/%%{go_import_path}\n") - fmt.Fprintf(f, "cp -a . %%{_builddir}/go/src/%%{go_import_path}\n") - } - if len(u.vendorDirs) > 0 { - fmt.Fprintf(f, "# Remove bundled dependencies\n") - for _, vdir := range u.vendorDirs { - fmt.Fprintf(f, "rm -rf %s\n", vdir) - } - } - if u.hasGodeps { - fmt.Fprintf(f, "rm -rf Godeps/_workspace\n") - } - fmt.Fprintf(f, "\n") - - // %build - fmt.Fprintf(f, "%%build\n") - switch pkgType { - case typeLibrary: - fmt.Fprintf(f, "# Library package - no build needed\n") - case typeProgram, typeLibraryProgram, typeProgramLibrary: - fmt.Fprintf(f, "export GO111MODULE=off\n") - fmt.Fprintf(f, "export GOPATH=%%{_builddir}/go:%%{_datadir}/gocode\n") - fmt.Fprintf(f, "export GOFLAGS=\"-buildmode=pie -trimpath -mod=readonly -modcacherw\"\n") - fmt.Fprintf(f, "go build -v -o %%{_name} .\n") - } - fmt.Fprintf(f, "\n") - - // %install - fmt.Fprintf(f, "%%install\n") - switch pkgType { - case typeLibrary: - fmt.Fprintf(f, "# Install source code for library package\n") - fmt.Fprintf(f, "install -d %%{buildroot}%%{go_sys_gopath}/%%{go_import_path}\n") - fmt.Fprintf(f, "cp -a . %%{buildroot}%%{go_sys_gopath}/%%{go_import_path}\n") - case typeProgram: - fmt.Fprintf(f, "install -D -m 0755 %%{_name} %%{buildroot}%%{_bindir}/%%{_name}\n") - case typeLibraryProgram, typeProgramLibrary: - fmt.Fprintf(f, "# Install binary\n") - fmt.Fprintf(f, "install -D -m 0755 %%{_name} %%{buildroot}%%{_bindir}/%%{_name}\n") - fmt.Fprintf(f, "\n") - fmt.Fprintf(f, "# Install source code for library package\n") - fmt.Fprintf(f, "install -d %%{buildroot}%%{go_sys_gopath}/%%{go_import_path}\n") - fmt.Fprintf(f, "cp -a . %%{buildroot}%%{go_sys_gopath}/%%{go_import_path}\n") - } - fmt.Fprintf(f, "\n") - - // %check - fmt.Fprintf(f, "%%check\n") - fmt.Fprintf(f, "export GO111MODULE=off\n") - fmt.Fprintf(f, "export GOPATH=%%{_builddir}/go:%%{_datadir}/gocode\n") - fmt.Fprintf(f, "go test -v ./...\n") - fmt.Fprintf(f, "\n") - // %files writeRPMFilesSection(f, openRuyiSrc, openRuyiLib, openRuyiProgram, pkgType) -- 2.52.0