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