-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
build: bazel
-generated go binaries should include a synthetic prefix
#64379
Comments
Investigation:
However I see that the final link stage is not done using the @rickystewart informs me that this program comes from https://github.com/bazelbuild/rules_go/tree/master/go/tools/builders?rgh-link-date=2021-04-28T17%3A07%3A05Z I will investigate this next. |
The previous investigation step might be mistaken btw -- I confirmed the files contain a |
So I looked at these The bazel-generated one has The make-generated one has So that means the |
Ok so the low level build command is this:
This suggests that the We have two courses of action I think:
|
@rickystewart what do you reckon is easier? |
|
Ok so a little bit more of sleuthing: the stack traces pull two different strings from object code to construct stack traces:
In the issue at top, the stack traces are incorrect due to incorrect file path. The symbol paths are OK. The builder |
I then looked into how the file paths look like for different files in the repo. For vendored dependencies
For files in a package
For the main function
There are two things that pop to the eye:
|
I think we could perhaps edit various parts of the code that inspect the file prefixes (from memory, that would be sentry-go, logging and error handling) however the case where even the package prefix is stripped entirely would be too limiting. |
Ok I found what happened with that https://github.com/bazelbuild/rules_go/blob/master/go/tools/builders/compilepkg.go#L280 https://github.com/bazelbuild/rules_go/blob/master/go/tools/builders/compilepkg.go#L287 (The The problem is that the It seems incorrect that the truncation would be different depending on whether or not Cgo is being used. |
Here are a couple of possible "next steps" from here:
I'm not sure how much work the 2nd avenue is.
|
I'm going to file yet another issue for that investigation, because it's hairy |
filed #64383 |
The second (finding a way to inject the appropriate source path into the The
|
I have a couple questions about this analysis.
|
I looked at this -- these paths are relative to the execroot, i.e., a Bazel-owned path that looks like It's conceivable we could hack |
I ran
Yes, I understand that -- in the same way, we do not control where each member of the crdb team places their $GOPATH root directory. But that is not what matters here. What we want is to see the package path as suffix (not prefix) in the build. In your example, we would benefit from the source files being copied inside each sandbox inside a path named like this:
With this path structure, we can use There is an alternative approach, which I find a little bit icky but would be simple and would get us 80% of the way wrt ergonomics: modify |
I looked at this. If you replace the
i.e.,
I think you misunderstood me. My point isn't that we can't choose where the sandbox goes. (We actually can! The documentation I linked describes how to do that.) My point is that the inner structure of the sandbox directories is dictated by Bazel, and the sandbox mirrors the structure of the actual workspace. So, can we make it so the files get copied into a subdirectory in the sandbox called If the Bazel directory structure is insufficient, then we have the option of staging the source outside of the sandbox in a temporary directory, as in the I'll also bump #64383 to see how I can help out there. |
Can we make that temporary directory named after the same structure as the source code directory? After all, that is what the go compiler must be doing, otherwise a plain |
Something that wasn't really clarified so far is that today all engineers use text editors which have special support for parsing error messages, stack traces etc so that they can click a source file name and have the editor open it automatically. This uses some form of fuzzy match because often the file name is truncated to a relative path, so the editor knows about a "project root directory" and resolves path names from there. If the bazel sandbox completely shuffles the layout of files during compilation, we're removing that UX benefit. |
Given that bazel is also used for C++ code, and C++ code editors also do this navigation-via-file-name-in-error-messages, I wonder how it works in that case? Aren't C++ files located inside the sandbox using the same directory structure as in the source directory? |
Presumably yes, with a patch. That fixes the |
For the non-cgo case, I think we're somewhat OK for the code editor UX: as determined above alrady, the remaining paths are already stored as (If not, we can apply the same solution as for cgo and move the sources to a We wouldn't be able to auto-navigate easily to the dependency package sources since their path inside the sandbox is being |
Yes, same as (non-
We're moving towards
I agree. OK, I'll check on this and see what I can do for the |
Well in the ideal world, we'd organize the directories inside the sandbox as follows:
then all the paths would align properly and there wouldn't be any ambiguity |
This is a workaround for the issue described at cockroachdb/cockroach#64379 -- this is unnecessarily inefficient, but it does work and avoids some regressions `rules_go` would otherwise introduce.
This is a workaround for the issue described at cockroachdb/cockroach#64379 -- this is unnecessarily inefficient, but it does work and avoids some regressions `rules_go` would otherwise introduce.
After spelunking through the compile code, I realized that |
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This is a workaround for the issue described at cockroachdb/cockroach#64379 -- this is unnecessarily inefficient, but it does work and avoids some regressions `rules_go` would otherwise introduce.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
This fixes the issue described in cockroachdb/cockroach#64379 where the internal paths of the files don't include the `github.com/cockroachdb/cockroach` prefix. We fix this by using the rewrite syntax of `-trimpath`, e.g. `-trimpath=/sandbox/execroot=>github.com/cockroachdb/cockroach`. Figuring out the replacement part is not trivial. We use the package path and strip out the relative path of the source file directory.
bazel
-generated go binaries truncate the path of stored source file namesbazel
-generated go binaries should include a synthetic prefix
I've updated this issue to reflect the fact that the assertional synthetic prefix here actually may make file paths less "correct" as they no longer actually point to a real path on disk depending on where one checks out a workspace. In hindsight workspace-relative paths actually were perhaps more "correct" as they were and we potentially should revert to that behavior. |
Compare running the following command:
Using either a binary produced by
bazel build
, or one produced bymake buildshort
.With
make buildshort
, the stack trace looks like this:With
bazel
, the stack trace looks like this:The 2nd one is incorrect.2024 Edit by @dt : The second one is relative to the workspace root, which does uniquely identify the files. The additional prefix in the first one is not actually more "correct", and may indeed be the incorrect one, as that file path may not actually be a valid file path anywhere on disk at all, depending on where the workspace containing
pkg/sql/values.go
was checked out (i.e. was it checked out in a foldercockroach
? maybe not.)The text was updated successfully, but these errors were encountered: