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

cmd/go: access $WORK directory from toolexec #45864

Closed
dzonerzy opened this issue Apr 30, 2021 · 9 comments
Closed

cmd/go: access $WORK directory from toolexec #45864

dzonerzy opened this issue Apr 30, 2021 · 9 comments
Labels
FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@dzonerzy
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.16.2 windows/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=on
set GOARCH=386
set GOBIN=
set GOCACHE=C:\Users\DZONERZY\AppData\Local\go-build
set GOENV=C:\Users\DZONERZY\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\DZONERZY\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\DZONERZY\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.2
set GCCGO=gccgo
set GO386=sse2
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=C:\Users\DZONERZY\go\src\github.com\dzonerzy\guzzer\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m32 -fmessage-length=0 -fdebug-prefix-map=C:\Users\DZONERZY\AppData\Local\Temp\go-build4099943664=/tmp/go-build -gno-record-gcc-switches

What did you do?

I'm trying to access $WORK variable via the -toolexec command , in order to modify the content of -importcfg before the compilation of a package

What did you expect to see?

A way to modify -importcfg content before compilation

What did you see instead?

There's not way to access the working directory via -toolexec

@ianlancetaylor ianlancetaylor changed the title Access $WORK directory from toolexec cmd/go: access $WORK directory from toolexec Apr 30, 2021
@ianlancetaylor
Copy link
Contributor

CC @bcmills @jayconrod

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 30, 2021
@cherrymui cherrymui added this to the Unplanned milestone Apr 30, 2021
@bcmills
Copy link
Contributor

bcmills commented Apr 30, 2021

CC @matloob @mvdan

@mvdan
Copy link
Member

mvdan commented Apr 30, 2021

This is possible today, without directly knowing $WORK. You just look at the compiler flags when it runs, and swap or modify the importcfg file.

https://github.com/burrowers/garble/blob/d34406d83279978529dd732ad59e07e867f68c95/main.go#L859-L866

https://github.com/burrowers/garble/blob/d34406d83279978529dd732ad59e07e867f68c95/main.go#L1413

I'm not opposed to exposing $WORK, but I don't think it's necessary for what you want here.

@dzonerzy
Copy link
Author

Actually i need to read the content of the "old" importcfg file and add there some new packagefile directive, so i need to access the old file not only swap it

@mvdan
Copy link
Member

mvdan commented Apr 30, 2021

Right. The code I shared shows a working example of reading the existing file and replacing it with a new one.

@dzonerzy
Copy link
Author

Imo another option is to allow multiple -importcfg switch and just merge them at compile time

@mvdan
Copy link
Member

mvdan commented Apr 30, 2021

I guess that's possible, but I don't see it as necessary. I also don't understand how it's related to your original request for $WORK. You can certainly read, modify, and replace -importcfg currently, so I'd suggest that you try that before suggesting changes to the toolchain.

@mvdan
Copy link
Member

mvdan commented Aug 8, 2021

@dzonerzy I shared details (and even code!) about how this is possible with just a little bit of code today. Can you clarify whether it works for you or not? If it does not, please provide details to keep the issue open for further discussion.

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 8, 2021
@dzonerzy
Copy link
Author

dzonerzy commented Aug 8, 2021

Your code solved my issue

@dzonerzy dzonerzy closed this as completed Aug 8, 2021
@golang golang locked and limited conversation to collaborators Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants