Skip to content

Commit ee54b02

Browse files
committed
[release] src/goToolsInformation: use the commit hash to pin dlv-dap version
We cannot rely on pseudo-version reliably yet. Fixes #1682 Change-Id: Ibf36627d9f5755f513876751bbab6ce62d135e56 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/341529 Trust: Hyang-Ah Hana Kim <[email protected]> Trust: Suzy Mueller <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]> (cherry picked from commit 46b3efe) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/341609
1 parent 8ee5144 commit ee54b02

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

src/goDebugFactory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { ChildProcess, ChildProcessWithoutNullStreams, spawn } from 'child_proce
88
import stream = require('stream');
99
import vscode = require('vscode');
1010
import { OutputEvent, TerminatedEvent } from 'vscode-debugadapter';
11-
import { killProcessTree } from './utils/processUtils';
1211
import getPort = require('get-port');
1312
import path = require('path');
1413
import * as fs from 'fs';

src/goToolsInformation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export const allToolsInformation: { [key: string]: Tool } = {
223223
replacedByGopls: false,
224224
isImportant: true,
225225
description: 'Go debugger & debug adapter (Delve DAP)',
226-
defaultVersion: 'v1.7.1-0.20210804080032-f95340ae1bf9', // pinned version
226+
defaultVersion: 'f95340ae1bf9', // pinned version
227227
minimumGoVersion: semver.coerce('1.12'), // dlv requires 1.12+ for build
228228
latestVersion: semver.parse('v1.7.1-0.20210804080032-f95340ae1bf9'),
229229
latestVersionTimestamp: moment('2021-08-04', 'YYYY-MM-DD')

test/integration/install.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,12 @@ function buildFakeProxy(testCases: installationTestCase[]) {
213213
fs.writeFileSync(path.join(dir, 'list'), `${versions.join('\n')}\n`);
214214

215215
versions.map((version) => {
216-
if (version === 'master') {
217-
// for dlv-dap that retrieves the version from master
216+
if (!version.match(/^v\d+\.\d+\.\d+/)) {
217+
// for dlv-dap that retrieves the version from a revision (commit hash)
218218
const resolvedVersion = tool.latestVersion?.toString() || '1.0.0';
219+
const infoPath = path.join(dir, `${version}.info`);
219220
version = `v${resolvedVersion}`;
220-
fs.writeFileSync(
221-
path.join(dir, 'master.info'),
222-
`{ "Version": "${version}", "Time": "2020-04-07T14:45:07Z" } `
223-
);
221+
fs.writeFileSync(infoPath, `{ "Version": "${version}", "Time": "2020-04-07T14:45:07Z" } `);
224222
}
225223

226224
// Write the go.mod file.

tools/generate.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package main
1515
import (
1616
"bytes"
1717
"encoding/json"
18+
"errors"
1819
"flag"
1920
"fmt"
2021
"io"
@@ -23,6 +24,7 @@ import (
2324
"os"
2425
"os/exec"
2526
"path/filepath"
27+
"regexp"
2628
"sort"
2729
"strings"
2830

@@ -235,6 +237,12 @@ func main() {
235237
if err != nil {
236238
log.Fatal(err)
237239
}
240+
// Due to https://github.com/golang/vscode-go/issues/1682, we cannot use
241+
// pseudo-version as the pinned version reliably.
242+
dlvRevOrStable := dlvVersion.Version
243+
if rev, err := pseudoVersionRev(dlvVersion.Version); err == nil { // pseudo-version
244+
dlvRevOrStable = rev
245+
}
238246

239247
// Check for the latest gopls version.
240248
versions, err := listAllModuleVersions("golang.org/x/tools/gopls")
@@ -269,7 +277,7 @@ func main() {
269277
}
270278

271279
// TODO(suzmue): change input to json and avoid magic string printing.
272-
toolsString := fmt.Sprintf(string(data), goplsVersion.Version, goplsVersion.Time[:len("YYYY-MM-DD")], goplsVersionPre.Version, goplsVersionPre.Time[:len("YYYY-MM-DD")], dlvVersion.Version, dlvVersion.Version, dlvVersion.Time[:len("YYYY-MM-DD")])
280+
toolsString := fmt.Sprintf(string(data), goplsVersion.Version, goplsVersion.Time[:len("YYYY-MM-DD")], goplsVersionPre.Version, goplsVersionPre.Time[:len("YYYY-MM-DD")], dlvRevOrStable, dlvVersion.Version, dlvVersion.Time[:len("YYYY-MM-DD")])
273281

274282
// Write tools section.
275283
b.WriteString(toolsString)
@@ -685,3 +693,19 @@ func describeDebugProperty(p *Property) string {
685693
}
686694
return b.String()
687695
}
696+
697+
// pseudoVersionRev extracts the revision info if the given version is pseudo version.
698+
// We wanted to use golang.org/x/mod/module.PseudoVersionRev, but couldn't due to
699+
// an error in the CI. This is a workaround.
700+
//
701+
// It assumes the version string came from the proxy, so a valid, canonical version
702+
// string. Thus, the check for pseudoversion is not as robust as golang.org/x/mod/module
703+
// offers.
704+
func pseudoVersionRev(ver string) (rev string, _ error) {
705+
var pseudoVersionRE = regexp.MustCompile(`^v[0-9]+\.(0\.0-|\d+\.\d+-([^+]*\.)?0\.)\d{14}-[A-Za-z0-9]+(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$`)
706+
if strings.Count(ver, "-") < 2 || !pseudoVersionRE.MatchString(ver) {
707+
return "", errors.New("not a pseudo version")
708+
}
709+
j := strings.LastIndex(ver, "-")
710+
return ver[j+1:], nil
711+
}

0 commit comments

Comments
 (0)