-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add ENABLE_BAZEL_PACKAGES_LOAD_HACK=true for poor Bazel users #40
Conversation
Bazel build systems try to keep hermeticity by setting PATH="." - but Go does not like this as it is a security concern; almost all Go tooling relies on golang.org/x/tools/go/packages.Load which behind the scenes must invoke `go` and uses the secure version of x/sys/execabs, but ultimately this means Go tools like autogold cannot be run in Bazel: golang/go#57304 Autogold relies on `packages.Load` in order to determine the Go package name / path when writing out a Go AST representation of the value passed in; but the issue above means autogold cannot be used with Bazel without removing "." from your PATH, which Bazel claims breaks hermeticity (one of the whole reasons people use Bazel.) For Bazel users, we allow them to set ENABLE_BAZEL_HACKS=true which causes autogold to guess/infer package names and paths using stack trace information and import paths. This is not perfect, it doesn't respect packages whose import paths donot match their defined `package foo` statement for example - but it's sufficient to enable autogold to be used in Bazel build environments where the above Go/Bazel bug is found. Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #40 +/- ##
==========================================
- Coverage 35.26% 32.54% -2.72%
==========================================
Files 5 6 +1
Lines 346 381 +35
==========================================
+ Hits 122 124 +2
- Misses 198 229 +31
- Partials 26 28 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I confirm it's working after testing things on our side. The thing we're wondering about is that if we should name that variable Another solution would be to rename it to |
Gotcha, cool, I'll get this merged soon - as for env var naming, I consider the following in naming this:
Thus I come up with:
I can see how Separately, if we do want a different name (or on-by-default behavior) in sourcegraph we're totally free to fork (really, I don't mind that at all so if that makes sense for us there that works for me.) |
This totally makes sense. I don't believe we'll have any issue with using |
I'm totally fine with
We all agree on that. We're seeing conflicting design goals here and it's great that we can compensate that on
Yes,
Makes sense, thanks. |
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Hello /Sourcegraph employee hat on/ 👋 On behalf of Sourcegraph, we'd like to contribute these changes back to autogold that enable users of the Bazel build systems to make use of autogold despite a bug/disagreement in Go/Bazel (see below.) We agree to the project terms & license these changes under the open source LICENSE, as we don't want the annoyance of maintaining a fork of this code on our side long term.
Context: Bazel build systems try to keep hermeticity by setting PATH="." - but Go does not like this as it is a security concern; almost all Go tooling relies on golang.org/x/tools/go/packages.Load which behind the scenes must invoke
go
and uses the secure version of x/sys/execabs, but ultimately this means Go tools like autogold cannot be run in Bazel:golang/go#57304
Autogold relies on
packages.Load
in order to determine the Go package name / path when writing out a Go AST representation of the value passed in; but the issue above means autogold cannot be used with Bazel without removing "." from your PATH, which Bazel claims breaks hermeticity (one of the whole reasons people use Bazel.)For Bazel users, we allow them to set ENABLE_BAZEL_HACKS=true which causes autogold to guess/infer package names and paths using stack trace information and import paths. This is not perfect, it doesn't respect packages whose import paths donot match their defined
package foo
statement for example - but it's sufficient to enable autogold to be used in Bazel build environments where the above Go/Bazel bug is found.