Skip to content

Commit

Permalink
[release] src/goPath: remove dependency on util that depends on vscode
Browse files Browse the repository at this point in the history
golang.org/cl/239697 accidentally added the new dependency on util - to find
the value of go.goroot, which broke the debug adapter that runs outside
vscode.

Made getBinPathWithPreferredGopath accept a preferredGoroot param,
and renamed the function to reflect this change.

We need to remove any dependency from src/debugAdapter to src to avoid
a similar bug in the future.

We need to have a test, using the built extension.

Updates #137.

Change-Id: I586438f1f391aaff0c0cdc806de1e9f3fd5deba9
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/240097
Reviewed-by: Rebecca Stambler <[email protected]>
(cherry picked from commit b9d1bad)
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/240117
  • Loading branch information
hyangah committed Jun 26, 2020
1 parent 865d3d9 commit 837852b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { DebugProtocol } from 'vscode-debugprotocol';
import {
envPath,
fixDriveCasingInWindows,
getBinPathWithPreferredGopath,
getBinPathWithPreferredGopathGoroot,
getCurrentGoWorkspaceFromGOPATH,
getInferredGopath,
parseEnvFile
Expand Down Expand Up @@ -471,7 +471,7 @@ export class Delve {
runArgs.push(...launchArgs.args);
}

const goExe = getBinPathWithPreferredGopath('go', []);
const goExe = getBinPathWithPreferredGopathGoroot('go', []);
log(`Current working directory: ${dirname}`);
log(`Running: ${goExe} ${runArgs.join(' ')}`);

Expand Down Expand Up @@ -1934,7 +1934,7 @@ export class GoDebugSession extends LoggingDebugSession {
}
return new Promise((resolve) => {
execFile(
getBinPathWithPreferredGopath('go', []),
getBinPathWithPreferredGopathGoroot('go', []),
['list', '-f', '{{.Name}} {{.ImportPath}}'],
{ cwd: dir, env: this.delve.dlvEnv },
(err, stdout, stderr) => {
Expand Down Expand Up @@ -2335,7 +2335,7 @@ function killProcessTree(p: ChildProcess): Promise<void> {
function queryGOROOT(cwd: any, env: any): Promise<string> {
return new Promise<string>((resolve) => {
execFile(
getBinPathWithPreferredGopath('go', []),
getBinPathWithPreferredGopathGoroot('go', []),
['env', 'GOROOT'],
{ cwd, env },
(err, stdout, stderr) => {
Expand Down
6 changes: 3 additions & 3 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import fs = require('fs');
import os = require('os');
import path = require('path');
import { getGoConfig } from './util';

let binPathCache: { [bin: string]: string } = {};

Expand All @@ -32,9 +31,10 @@ export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appe
return null;
}

export function getBinPathWithPreferredGopath(
export function getBinPathWithPreferredGopathGoroot(
toolName: string,
preferredGopaths: string[],
preferredGoroot?: string,
alternateTool?: string,
useCache = true,
) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export function getBinPathWithPreferredGopath(
}

// Check GOROOT (go, gofmt, godoc would be found here)
const pathFromGoRoot = getBinPathFromEnvVar(binname, getGoConfig().get('goroot') || getCurrentGoRoot(), true);
const pathFromGoRoot = getBinPathFromEnvVar(binname, preferredGoroot || getCurrentGoRoot(), true);
if (pathFromGoRoot) {
binPathCache[toolName] = pathFromGoRoot;
return pathFromGoRoot;
Expand Down
8 changes: 5 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getCurrentPackage } from './goModules';
import {
envPath,
fixDriveCasingInWindows,
getBinPathWithPreferredGopath,
getBinPathWithPreferredGopathGoroot,
getCurrentGoRoot,
getInferredGopath,
resolveHomeDir,
Expand Down Expand Up @@ -436,12 +436,14 @@ function resolveToolsGopath(): string {
}

export function getBinPath(tool: string, useCache = true): string {
const alternateTools: { [key: string]: string } = getGoConfig().get('alternateTools');
const cfg = getGoConfig();
const alternateTools: { [key: string]: string } = cfg.get('alternateTools');
const alternateToolPath: string = alternateTools[tool];

return getBinPathWithPreferredGopath(
return getBinPathWithPreferredGopathGoroot(
tool,
tool === 'go' ? [] : [getToolsGopath(), getCurrentGoPath()],
tool === 'go' && cfg.get('goroot') ? cfg.get('goroot') : undefined,
resolvePath(alternateToolPath),
useCache
);
Expand Down

0 comments on commit 837852b

Please sign in to comment.