Go: trimpath doesn't work if working in a symlinked directory
Please does not seem to trimpath correctly when building within a directory that is symlinked. This is really easy to reproduce on MacOS because /tmp is really a symlink to /private/tmp.
Given the following:
Environment Info:
$ plz --version
Please version 15.11.0
$ go version
go version go1.15.5 darwin/amd64
$PLZREPO/tybrown_net/testing/BUILD
go_binary(
name = "testing",
srcs = glob(
["*.go"],
exclude = ["*_test.go"],
),
)
$PLZREPO/tybrown_net/testing/main.go
package main
func testing() {
panic("foo")
}
func main() {
testing()
}
Results
Working in a standard directory
$ cd /private/tmp/plzrepo-copy
$ plz clean -f
$ plz build //tybrown_net/testing:testing
Build finished; total time 1.67s, incrementality 0.0%. Outputs:
//tybrown_net/testing:testing:
plz-out/bin/tybrown_net/testing/testing
$ ./plz-out/bin/tybrown_net/testing/testing
panic: foo
goroutine 1 [running]:
main.testing(...)
tybrown_net/testing/main.go:4
main.main()
tybrown_net/testing/main.go:8 +0x39
Working in a symlinked directory
$ cd /tmp/plzrepo-copy
$ plz clean -f
$ plz build //tybrown_net/testing:testing
Build finished; total time 1.59s, incrementality 0.0%. Outputs:
//tybrown_net/testing:testing:
plz-out/bin/tybrown_net/testing/testing
$ ./plz-out/bin/tybrown_net/testing/testing
panic: foo
goroutine 1 [running]:
main.testing(...)
/private/tmp/plzrepo-copy/plz-out/tmp/tybrown_net/testing/_testing#lib._build/tybrown_net/testing/main.go:4
main.main()
/private/tmp/plzrepo-copy/plz-out/tmp/tybrown_net/testing/_testing#lib._build/tybrown_net/testing/main.go:8 +0x39
So everything on the Please side is actually correct. We're falling afoul of this issue: https://github.com/golang/go/issues/17198
Essentially we're setting the command directory to be $(os.Getwd())/plz-out/tmp/... where os.Getwd() is returning the unexpanded fake path from bash. os/exec doesn't have the same smarts.
One way to fix this would be to make Please follow the symlinks for the repo root using something like this: https://github.com/yookoala/realpath/blob/master/realpath.go
Seems quite awkward to fix... Is this causing you serious problems?
@Tatskaari Thanks for the reply... Not serious/critical for me by any means, it's a nice to have. Was confused as to why the stacktraces were so long/hard to read, and that the packages built locally on my Mac were not matching what was building in CI... this explained it. :)
This issue has been automatically marked as stale because it has not had any recent activity in the past 90 days. It will be closed if no further activity occurs. If you require additional support, please reply to this message. Thank you for your contributions.
Is it solved?
No, but I suppose it could be with a little effort. Will revisit when I have v16 out the door. It's going to be quite slow to build in /tmp though isn't it? Please will have to do full copies because it can't hardlink files across filesystems. Is there a reason you want to build out of a symlinked dir?
The biggest reason I use a symlink is because I have a case-sensitive filesystem on my Mac for dealing with repos that require case-sensitivity, but prefer to access it at something like ~/repos instead of /Volumes/repos, which is where macOS really, really wants it to be mounted... so I just put a symlink at ~/repos -> /Volumes/repos and it seems to work most of the time. This was one of those times where it tripped me up a bit.
Like I said, not a huge issue... just breaks some of the hermetic build guarantees that I was expecting. There are workarounds, so probably low priority, just figured I'd put it on y'alls radar. :)