]> Cypherpunks repositories - gostls13.git/commit
internal/buildcfg: initialize GOROOT to runtime.GOROOT
authorBryan C. Mills <bcmills@google.com>
Tue, 15 Mar 2022 20:31:02 +0000 (16:31 -0400)
committerBryan Mills <bcmills@google.com>
Fri, 18 Mar 2022 21:52:11 +0000 (21:52 +0000)
commit9a932c5712bebb2620e0719a93773403f4fb563d
treea87993d2d240930ff2bfbdadfea59623c8ea5cdb
parent67f6b8c98715f265f38aff4052356ef6e6b35dfe
internal/buildcfg: initialize GOROOT to runtime.GOROOT

In the beginning the Go compiler was in C, and C had a function
'getgoroot' that returned GOROOT from either the environment or a
generated constant. 'getgoroot' was mechanically converted to Go
(as obj.Getgoroot) in CL 3046.

obj.Getgoroot begat obj.GOROOT. obj.GOROOT begat objabi.GOROOT,
which begat buildcfg.GOROOT.

As far as I can tell, today's buildcfg.GOROOT is functionally
identical to runtime.GOROOT(). Let's reduce some complexity by
defining it in those terms.

While we're thinking about buildcfg.GOROOT, also check whether it is
non-empty: if the toolchain is built with -trimpath, the value of
GOROOT might not be valid or meaningful if the user invokes
cmd/compile or cmd/link directly, or via a build tool other than
cmd/go that doesn't care as much about GOROOT. (As of CL 390024,
runtime.GOROOT will return the empty string instead of a bogus one
when built with -trimpath.)

For #51461.

Change-Id: I9fec020d5fa65d4aff0dd39b805f5ca93f86c36e
Reviewed-on: https://go-review.googlesource.com/c/go/+/393155
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/logopt/log_opts.go
src/cmd/compile/internal/noder/reader.go
src/cmd/internal/objabi/line.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/main.go
src/internal/buildcfg/cfg.go