Skip to content

Commit a8987cb

Browse files
committed
go-1.24: fix go main version not semver compatible
Fix +incompatible+dirty build metadata to be semver compatible.
1 parent f44d9e1 commit a8987cb

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

go-1.24.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package:
22
name: go-1.24
33
version: "1.24.0"
4-
epoch: 0
4+
epoch: 1
55
description: "the Go programming language"
66
copyright:
77
- license: BSD-3-Clause
@@ -41,6 +41,7 @@ pipeline:
4141
patches: |
4242
cmd-go-always-emit-ldflags-version-information.patch
4343
change-default-telemetry-from-local-to-off.patch
44+
go-fix-incompatible-dirty-build-metadata-to-be-SemVe.patch
4445
4546
- runs: |
4647
cd src
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From ee66f3c8fd27506c789810fff86f09880d0354ad Mon Sep 17 00:00:00 2001
2+
From: Dimitri John Ledkov <dimitri.ledkov@surgut.co.uk>
3+
Date: Tue, 19 Jul 2022 11:07:00 -0400
4+
Subject: [PATCH] go: fix +incompatible+dirty build metadata to be SemVer
5+
compatible
6+
7+
Change "+incompatible+dirty" version to be "+incompatible.dirty" such
8+
that it is SemVer spec compatible.
9+
10+
Struggling to add test case for a locally generated module that will
11+
create +incompatible version.
12+
13+
See:
14+
- https://github.com/golang/go/issues/71971
15+
- https://github.com/golang/go/issues/71969
16+
- https://github.com/golang/go/issues/71970
17+
- https://github.com/anchore/grype/issues/2482
18+
- https://semver.org/#spec-item-10
19+
20+
Change-Id: I714ffb3f1ad88c793656c3652367db34739a2144
21+
---
22+
src/cmd/go/internal/load/pkg.go | 7 ++++++-
23+
.../testdata/script/build_version_stamping_git.txt | 13 +++++++++++++
24+
2 files changed, 19 insertions(+), 1 deletion(-)
25+
26+
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
27+
index 0c4639ce82..13add8ad5b 100644
28+
--- a/src/cmd/go/internal/load/pkg.go
29+
+++ b/src/cmd/go/internal/load/pkg.go
30+
@@ -2563,7 +2563,12 @@ func (p *Package) setBuildInfo(ctx context.Context, autoVCS bool) {
31+
vers := revInfo.Version
32+
if vers != "" {
33+
if st.Uncommitted {
34+
- vers += "+dirty"
35+
+ // SemVer build metadata is dot-separated https://semver.org/#spec-item-10
36+
+ if strings.HasSuffix(vers, "+incompatible") {
37+
+ vers += ".dirty"
38+
+ } else {
39+
+ vers += "+dirty"
40+
+ }
41+
}
42+
info.Main.Version = vers
43+
}
44+
diff --git a/src/cmd/go/testdata/script/build_version_stamping_git.txt b/src/cmd/go/testdata/script/build_version_stamping_git.txt
45+
index db804b3847..e7ca8d25df 100644
46+
--- a/src/cmd/go/testdata/script/build_version_stamping_git.txt
47+
+++ b/src/cmd/go/testdata/script/build_version_stamping_git.txt
48+
@@ -108,6 +108,19 @@ go version -m example$GOEXE
49+
stdout '\s+mod\s+example\s+v1.0.3-0.20220719150703-2e239bf29c13\s+'
50+
rm example$GOEXE
51+
52+
+# Create +incompatible module
53+
+exec git checkout v1.0.4
54+
+exec git rm go.mod
55+
+exec git commit -m 'commit 6'
56+
+exec git tag v2.0.0
57+
+exec git checkout HEAD^ go.mod
58+
+# And make the tree +dirty
59+
+mv README4 README5
60+
+go build
61+
+go version -m example$GOEXE
62+
+stdout '\s+mod\s+example\s+v2.0.0+incompatible.dirty\s+'
63+
+rm example$GOEXE
64+
+
65+
-- $WORK/repo/go.mod --
66+
module example
67+
68+
--
69+
2.43.0
70+

0 commit comments

Comments
 (0)