4 Commits
Author SHA1 Message Date
misaka00251 b04996dd02 Merge pull request 'docs: init and add license' (#16) from Jvlegod/go2spec:add-docs into master
Reviewed-on: misaka00251/go2spec#16
Reviewed-by: Kiryuu Sakuya <17+misaka00251@noreply.git.openruyi.cn>
2026-08-10 12:04:52 +00:00
Jvle 50dca06727 fix: clean generated spec formatting
Signed-off-by: Jvle <keke.oerv@isrc.iscas.ac.cn>
2026-07-20 13:06:28 +00:00
Jvle 6d6647bbdf fix: normalize license OR parentheses
Signed-off-by: Jvle <keke.oerv@isrc.iscas.ac.cn>
2026-07-20 09:53:58 +00:00
Jvle 540faa9f51 fix: separate pseudo-version commit id
Signed-off-by: Jvle <keke.oerv@isrc.iscas.cn>
2026-07-16 12:02:24 +08:00
5 changed files with 43 additions and 26 deletions
+4 -4
View File
@@ -38,9 +38,8 @@ func shortCommitHash(hash string) string {
// pkgVersionFromGit determines the actual version to be packaged
// from the git repository status and user preference.
// Besides returning the upstream version, the "upstream" struct
// struct fields u.version, u.commitIsh, u.hasRelease and u.isRelease
// are also set.
// Besides returning the upstream version, the "upstream" struct fields
// u.version, u.commitID, u.commitIsh, u.hasRelease and u.isRelease are also set.
// `preferredRev` should be empty if there are no user preferences.
// TODO: also support other VCS
func pkgVersionFromGit(gitdir string, u *upstream, preferredRev string, forcePrerelease bool) (string, error) {
@@ -129,9 +128,10 @@ func pkgVersionFromGit(gitdir string, u *upstream, preferredRev string, forcePre
}
fullCommitHash := strings.TrimSpace(string(fullCommitHashBytes))
lastCommitHash := shortCommitHash(fullCommitHash)
u.commitID = fullCommitHash
u.commitIsh = lastCommitHash
// Snapshot versions are based on the packaging date, not the commit date.
u.version = fmt.Sprintf("0+git%s.%s\n%%define commit_id %s", packagingDateString(), lastCommitHash, fullCommitHash)
u.version = fmt.Sprintf("0+git%s.%s", packagingDateString(), lastCommitHash)
return u.version, nil
}
+2 -1
View File
@@ -38,6 +38,7 @@ type upstream struct {
tarPath string // path to the downloaded or generated orig tarball tempfile
compression string // compression method, either "gz" or "xz"
version string // upstream version number, e.g. 0.0~git20180204.1d24609
commitID string // full commit hash for commit-pinned snapshot builds
tag string // Latest upstream tag, if any
commitIsh string // commit-ish corresponding to upstream version to be packaged
remote string // git remote, set to short hostname if upstream git history is included
@@ -327,7 +328,7 @@ func moduleUsesRepoSubdir(modulePath, repoURL string) bool {
// the upstream version maps cleanly to %{commit_id} or %{version}.
func (u *upstream) sourceRefForSpec() (string, error) {
ref := u.tag
if strings.Contains(u.version, "commit_id") {
if u.commitID != "" {
ref = "%{commit_id}"
} else if u.isRelease && u.tag == "v"+u.version {
ref = "v%{version}"
+8 -4
View File
@@ -358,10 +358,7 @@ func pkgsiteLicenseExpression(licenses []pkgsiteLicense) string {
types = append(types, typ)
}
sort.Strings(types)
group := types[0]
if len(types) > 1 {
group = "(" + strings.Join(types, " OR ") + ")"
}
group := strings.Join(types, " OR ")
seenGroups[group] = true
}
if len(seenGroups) == 0 {
@@ -373,5 +370,12 @@ func pkgsiteLicenseExpression(licenses []pkgsiteLicense) string {
groups = append(groups, group)
}
sort.Strings(groups)
if len(groups) > 1 {
for i, group := range groups {
if strings.Contains(group, " OR ") {
groups[i] = "(" + group + ")"
}
}
}
return strings.Join(groups, " AND ")
}
+22 -6
View File
@@ -48,7 +48,15 @@ func TestPkgsiteLicenseExpression(t *testing.T) {
licenses: []pkgsiteLicense{
{FilePath: "LICENSE", Types: []string{"MIT", "Apache-2.0"}},
},
want: "(Apache-2.0 OR MIT)",
want: "Apache-2.0 OR MIT",
},
{
name: "parenthesizes OR group when joined with AND",
licenses: []pkgsiteLicense{
{FilePath: "LICENSE", Types: []string{"MIT", "Apache-2.0"}},
{FilePath: "COPYING", Types: []string{"BSD-3-Clause"}},
},
want: "(Apache-2.0 OR MIT) AND BSD-3-Clause",
},
{
name: "uses TODO when pkgsite has no SPDX type",
@@ -428,8 +436,9 @@ func TestGetPkgsitePackageRetriesAmbiguousPathWithLongestModule(t *testing.T) {
func TestSourceURLForSpecUsesCommitIDMacro(t *testing.T) {
u := upstream{
repoURL: "https://github.com/example/project",
version: "0+git20260522.abcdef\n%define commit_id 0123456789abcdef",
repoURL: "https://github.com/example/project",
version: "0+git20260522.abcdef",
commitID: "0123456789abcdef",
}
got, err := u.sourceURLForSpec("github.com/example/project")
if err != nil {
@@ -494,8 +503,9 @@ func TestSourceURLForSpecUsesModuleProxyForRepoSubmodule(t *testing.T) {
func TestSourceURLForSpecRejectsCommitIDForRepoSubmodule(t *testing.T) {
u := upstream{
repoURL: "https://github.com/charmbracelet/x",
version: "0+git20260522.abcdef\n%define commit_id abcdef1234567890",
repoURL: "https://github.com/charmbracelet/x",
version: "0+git20260522.abcdef",
commitID: "abcdef1234567890",
}
_, err := u.sourceURLForSpec("github.com/charmbracelet/x/ansi")
if err == nil {
@@ -529,7 +539,7 @@ func TestPkgVersionFromGitUsesPackagingDateAndSevenCharHash(t *testing.T) {
}, "commit", "-m", "initial")
fullHash := strings.TrimSpace(runGit(t, dir, nil, "rev-parse", "HEAD"))
want := "0+git20250808." + fullHash[:7] + "\n%define commit_id " + fullHash
want := "0+git20250808." + fullHash[:7]
u := upstream{}
got, err := pkgVersionFromGit(dir, &u, "", false)
@@ -539,6 +549,12 @@ func TestPkgVersionFromGitUsesPackagingDateAndSevenCharHash(t *testing.T) {
if got != want {
t.Fatalf("pkgVersionFromGit() = %q, want %q", got, want)
}
if strings.Contains(got, "\n") || strings.Contains(got, "commit_id") {
t.Fatalf("pkgVersionFromGit() returned metadata in version: %q", got)
}
if u.commitID != fullHash {
t.Fatalf("commitID = %q, want %q", u.commitID, fullHash)
}
if strings.Contains(got, "19990102") {
t.Fatalf("pkgVersionFromGit() used commit date: %q", got)
}
+7 -11
View File
@@ -122,13 +122,8 @@ func writeSpec(dir, gopkg, openRuyiSrc, openRuyiLib, openRuyiProgram, version st
fmt.Fprintf(f, "%%define _name %s\n", upstreamName)
fmt.Fprintf(f, "%%define go_import_path %s\n", gopkg)
// If pkgVersionFromGit embedded a commit_id define in u.version, extract and write it here
commitRe := regexp.MustCompile(`%define\s+commit_id\s+([0-9a-fA-F]+)`)
if m := commitRe.FindStringSubmatch(u.version); m != nil {
fmt.Fprintf(f, "%%define commit_id %s\n", m[1])
// Remove the embedded %define line from version so it doesn't get written to Version: field
version = commitRe.ReplaceAllString(version, "")
version = strings.TrimSpace(version)
if u.commitID != "" {
fmt.Fprintf(f, "%%define commit_id %s\n", u.commitID)
}
fmt.Fprintf(f, "\n")
@@ -201,17 +196,18 @@ func writeSpec(dir, gopkg, openRuyiSrc, openRuyiLib, openRuyiProgram, version st
log.Fatalf("Invalid pkgType %d in writeRPMSpec(), aborting", pkgType)
}
fmt.Fprintf(f, "\n")
if pkgType != typeLibrary {
fmt.Fprintf(f, "\n")
}
fmt.Fprintf(f, "%%description\n")
fmt.Fprintf(f, "%s\n", longdescription)
fmt.Fprintf(f, "\n")
fmt.Fprintf(f, "%s\n\n", strings.TrimRight(longdescription, "\n"))
// %files
writeRPMFilesSection(f, openRuyiSrc, openRuyiLib, openRuyiProgram, pkgType, assetFiles)
// %changelog
fmt.Fprintf(f, "%%changelog\n")
fmt.Fprintf(f, "%%{?autochangelog}\n\n")
fmt.Fprintf(f, "%%autochangelog\n\n")
return nil
}