Skip to content

Commit 37eeb03

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 37eeb03

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-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,60 @@
1+
From f95df21039af972b8fac7afdbdd133dba41ae456 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+
src/cmd/go/testdata/script/build_version_stamping_git.txt | 3 +++
24+
2 files changed, 9 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..b79c44733a 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("+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..ba0576e55b 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,9 @@ 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+
+# TODO simulate +incompatible version here, as well as +incompatible.dirty
53+
+# how can one locally create +incompatible version?
54+
+
55+
-- $WORK/repo/go.mod --
56+
module example
57+
58+
--
59+
2.43.0
60+

0 commit comments

Comments
 (0)