Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go.toolsEnvVars does not substitute env variables #2680

Closed
kmathewmk opened this issue Feb 22, 2023 · 5 comments
Closed

go.toolsEnvVars does not substitute env variables #2680

kmathewmk opened this issue Feb 22, 2023 · 5 comments
Assignees
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@kmathewmk
Copy link

kmathewmk commented Feb 22, 2023

Type: Bug

My settings.json has:

{
    "[go]": {
        "editor.defaultFormatter": "golang.go",
        "editor.codeActionsOnSave": {
            "source.organizeImports": false
        }
    },
    "go.gopath": "${workspaceFolder}/microservices/operators/test",
    "go.toolsGopath": "~/.vscode/goTools",
    "go.toolsEnvVars": {
        "GOPROXY": "https://${env:USERNAME_UENC}:${env:PASSWORD}@packages.foobar.com/jf/api/go/mpd-go-dev",
        "GONOSUMDB": "foobar.com/*"
    },
    "terminal.integrated.env.linux": {
        "GOPROXY": "https://${env:USERNAME_UENC}:${env:PASSWORD}@packages.foobar.com/jf/api/go/mpd-go-dev",
        "GONOSUMDB": "foobar.com/*"
    }    
}

and with this I get the following errors:

Tools environment: GOPATH=/home/john.doe/.vscode/goTools
Installing 3 tools at /home/john.doe/.vscode/goTools/bin in module mode.
  dlv
  staticcheck
  gopls

Installing github.com/go-delve/delve/cmd/dlv@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "/usr/bin/go install -v github.com/go-delve/delve/cmd/dlv@latest",
 "stdout": "",
 "stderr": "go: github.com/go-delve/delve/cmd/dlv@latest: parse \"https://${env:USERNAME_UENC}:${env:PASSWORD}@packages.foobar.com/jf/api/go/mpd-go-dev\": net/url: invalid userinfo\n"
}
Installing honnef.co/go/tools/cmd/staticcheck@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "/usr/bin/go install -v honnef.co/go/tools/cmd/staticcheck@latest",
 "stdout": "",
 "stderr": "go: honnef.co/go/tools/cmd/staticcheck@latest: parse \"https://${env:USERNAME_UENC}:${env:PASSWORD}@packages.foobar.com/jf/api/go/mpd-go-dev\": net/url: invalid userinfo\n"
}
Installing golang.org/x/tools/gopls@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "/usr/bin/go install -v golang.org/x/tools/gopls@latest",
 "stdout": "",
 "stderr": "go: golang.org/x/tools/gopls@latest: parse \"https://${env:USERNAME_UENC}:${env:PASSWORD}@packages.foobar.com/jf/api/go/mpd-go-dev\": net/url: invalid userinfo\n"
}

3 tools failed to install.

dlv: failed to install dlv(github.com/go-delve/delve/cmd/dlv@latest): Error: Command failed: /usr/bin/go install -v github.com/go-delve/delve/cmd/dlv@latest
go: github.com/go-delve/delve/cmd/dlv@latest: parse "https://${env:USERNAME_UENC}:${env:PASSWORD}@packages.foobar.com/jf/api/go/mpd-go-dev": net/url: invalid userinfo
 
staticcheck: failed to install staticcheck(honnef.co/go/tools/cmd/staticcheck@latest): Error: Command failed: /usr/bin/go install -v honnef.co/go/tools/cmd/staticcheck@latest
go: honnef.co/go/tools/cmd/staticcheck@latest: parse "https://${env:USERNAME_UENC}:${env:PASSWORD}@packages.foobar.com/jf/api/go/mpd-go-dev": net/url: invalid userinfo
 
gopls: failed to install gopls(golang.org/x/tools/gopls@latest): Error: Command failed: /usr/bin/go install -v golang.org/x/tools/gopls@latest
go: golang.org/x/tools/gopls@latest: parse "https://${env:USERNAME_UENC}:${env:PASSWORD}@packages.foobar.com/jf/api/go/mpd-go-dev": net/url: invalid userinfo

If I replace the environment variable with actual values like below:

"GOPROXY": "https://john.doe%40foobar.com:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@packages.foobar.com/jf/api/go/mpd-go-dev",

the installation of tools succeed:

Tools environment: GOPATH=/home/john.doe/.vscode/goTools
Installing 3 tools at /home/john.doe/.vscode/goTools/bin in module mode.
  dlv
  staticcheck
  gopls

Installing github.com/go-delve/delve/cmd/dlv@latest (/home/john.doe/.vscode/goTools/bin/dlv) SUCCEEDED
Installing honnef.co/go/tools/cmd/staticcheck@latest (/home/john.doe/.vscode/goTools/bin/staticcheck) SUCCEEDED
Installing golang.org/x/tools/gopls@latest (/home/john.doe/.vscode/goTools/bin/gopls) SUCCEEDED

All tools successfully installed. You are ready to Go. :)

Extension version: 0.37.1
VS Code version: Code 1.75.1 (441438abd1ac652551dbe4d408dfcec8a499b8bf, 2023-02-08T21:32:34.589Z)
OS version: Windows_NT x64 10.0.19042
Modes:
Sandboxed: No
Remote OS version: Linux x64 5.15.0-1027-gcp
Remote OS version: Linux x64 5.15.0-1027-gcp
Remote OS version: Linux x64 5.15.0-1027-gcp

System Info
Item Value
CPUs Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz (8 x 2112)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 15.84GB (4.86GB free)
Process Argv --crash-reporter-id b3737b9c-e0e4-4933-bf23-5d589eabe47f
Screen Reader no
VM 0%
Item Value
Remote SSH: gcp-vm2
OS Linux x64 5.15.0-1027-gcp
CPUs Intel(R) Xeon(R) CPU @ 2.80GHz (4 x 2800)
Memory (System) 10.70GB (6.73GB free)
VM 0%
Item Value
Remote SSH: gcp-vm2
OS Linux x64 5.15.0-1027-gcp
CPUs Intel(R) Xeon(R) CPU @ 2.80GHz (4 x 2800)
Memory (System) 10.70GB (6.73GB free)
VM 0%
Item Value
Remote SSH: gcp-vm2
OS Linux x64 5.15.0-1027-gcp
CPUs Intel(R) Xeon(R) CPU @ 2.80GHz (4 x 2800)
Memory (System) 10.70GB (6.73GB free)
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewvextcfv2:30669238
azure-dev_surveyone:30548225
pyindex848:30662994
nodejswelcome1:30587005
282f8724:30602487
pyind779cf:30662993
f6dab269:30613381
pythonsymbol12:30657548

@gopherbot gopherbot added this to the Untriaged milestone Feb 22, 2023
@adonovan adonovan added FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 23, 2023
@adonovan adonovan modified the milestones: Untriaged, vscode-go/later Feb 23, 2023
@STiAT
Copy link

STiAT commented Mar 2, 2023

This would be a really neat feature. I usually have CGO disabled, but require CGO for some tools (as saprfc), where I require to set CGO_LDFLAGS and CGO_CFLAGS, which would be neat if it could be handled via the env war which is required anyway - ${env:NWRFCSDK_INCLUDE} and ${env:NWRFCSDK_LIBS}.

Thus, the checked in .vscode/settings.json would be standardized for all developers and wouldn't require to have the lib installed in either the same dir or devs to create their own.

@ian-h-chamberlain
Copy link

I think this is a regression, rather than a feature request. The change for #413 (https://golang.org/cl/246958) looks like it claims to support ${env:} variables

@STiAT
Copy link

STiAT commented Mar 2, 2023

@ian-h-chamberlain thanks for the hint - that's a good catch, I've read the linked report and it seems to cover the same issue. Fact is, with golang 1.20.1 and the latest vscode (stable) I'm having this exact issue. So either it was not fixed completely or it's indeed a regression.

I just tested it again, with using fixed pathes instead of the environment variables it works perfectly well, using the env variables it fails to compile gorfc due to missing libraries.

I need to delete the compiled gorfc libs though between trying, since if gorfc was compiled once it seems vscode recognizes this (probably because we do find a precompiled binary for the library, it just complains then not finding the saprfc.h file (which is yet another env var), but that's out of my depth knowing how this works to be true, I didn't try to get in the code deeper yet and would not know where to start. And I am not really very fond of javascript :D .. so that could be an issue since my knowledge there is very limited.

If I can help debugging this I'd be happy to do so though.

@hyangah
Copy link
Contributor

hyangah commented Mar 3, 2023

It's not a regression - it looks like this was never implemented.

I see the CL description of cl/246958) is confusing, but the fix for #413 is to support only a small set of known variables such as ${workspaceFolder} and ${workspaceRoot}. ${env:*} substitution was added partially in microsoft/vscode-go#1743 but only for go.toolsGopath setting.
The variable substitutions in configuration were never consistent with vscode's task.json or launch.json since it isn't handled by vscode microsoft/vscode#2809 but added case-by-case.

We are looking into a way to consolidate and handle across the extension consistently.

@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/534980 mentions this issue: src/goEnv: apply substituteEnv to go.toolsEnvVars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants