-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: set module root directory so editors/scripts see filenames in error messages relative to current directory #47399
Comments
And would break other setups that assume paths are relative to the current directory. |
@jwatte Thanks for writing this up. I think I have a better understanding of the problem you're experiencing now. A couple ideas for possible solutions:
Agreed with @rsc above though, we cannot change what |
That's not what I want. I want paths printed in error messages to be relative to the working directory of the invoking script/editor, which is not the root or sub-path of the module, for hopefully good reasons explained above. Any one of the proposals enumerated by @jayconrod would allow me to solve the problems I'm seeing. |
Given #45713, perhaps it would be reasonable for Then you could keep invoking most |
I like that idea. I think I may have suggested it myself in the past a couple of times. 😉 |
If we allow
|
For fixing error messages, let's not make very big changes. |
If by "workspace" you mean "arbitrary file system directory from git/perforce/mercurial/tarballs" where the "workspace" has nothing to do with go itself (other than containing some go code/module in some possibly deep subdirectory) then, yes, that would be one of the options that would work.
That would also work. |
Is there any news on the topic? I just opened an issue for this very problem proposing a solution that works for me: #57215 |
I ran into a similar issue where CICD tools couldn't associate test failures to the correct file in a monorepo. Interestingly This makes it easy to get a valid absolute path OR relative path. And the caller will always know the path and how it should be formatted. For a relative path: For an absolute path: I think this is preferable to an option that just prints absolute paths because it could also be used to produce many valid relative paths. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
First: This issue is created based on the discussion of #47363 but given that that issue was closed without any resolution to the underlying problem, as it didn't make the problem clear enough, here is the refined issue.
What did you see?
This issue is a "user story" (in the sense of "a legitimate user need that is currently not fulfilled") and could be solved in more than one way. Abbreviating from the conclusion, the behavior "the working directory determines the module" coupled with the behavior "diagnostic file names are printed relative to the working directory" breaks a lot of existing tooling in real-world projects.
go build|run|test ./path/to/directory
used the indicated directory as the root from which to discover which module it's ingo
command had an option--module-path
that overrode what the current directory was when determining which module it's in--print-full-paths
that madego
tooling print full paths to files in error/failure messages, rather than relative to the current working directoryWhat did you expect to see?
The problem is one of "I'm a user of go, Typescript, C++, protobuf, and a number of other languages, that all live in a single monorepo, and I want editors to be able to build and test code, and open the correct file when it fails, no matter what particular language is involved in the failure."
One of the subdirectories of this repo contains go code. The root of this monorepo is not a go module. I may not even be focused on a go module when I want to build integration tests.
The working directory of the editor (be it vim, emacs, vscode, or something else) is the root of the monorepo, which is not inside the go module.
Build and test commands invoked by the editor end up being run from the current working directory of the editor, which is the root of the monorepo ;they provide the relative path of the file in question from the editor working directory as argument. This works fine for all the other languages we use.
Currently, I can't find a good way of gluing this presumably not uncommon setup into the go build system, such that the error parser of each kind of editor (vim, emacs, vscode, and more) will find and open the correct file for a test failure (or build failure.)
For the tooling and editors we use, the following things are true:
/home/me/checkout
make -C cpp/path/module
that's appropriate for each languagesubdir/path/module/include/someheader.h:123: template is too complex
, or errors are printed with full paths to filenames.go
builds used to dogo test ./go/src/whatever/package
and that used to work (and withGO111MODULE
still works)With
GO111MODULE
turned off, that invocation now errors out, complaining that the CWD is not within a module, even though the interesting directory in question is within a module.For purposes of this comment, let's consider an overall project that looks like:
If I were to change the build command for the go package to do something like
cd go/src/whatever && go test ./package
then the filename printed will bepackage/myfile_test.go:123: insufficient shoe size
which is relative togo/src/whatever
, not relative to the editor CWD, and thus the editor won't find and open the file.Best would be "if a directory is the argument to the command, then determine the module based on that directory, not based on the CWD" which would make the current setup Just Work.
Second best would be "allow the module-to-assume to be specified using a separate command line option" which means we could specify the go build/test command as go test --module-root=./go/src/whatever whatever/package -- this is a little more cumbersome because of the duplication of "whatever" in the path (it's both the root of the module, and the root package name) but it can be made to work.
Third best would be a command line option that forces the tooling to always output full path filenames. This will let the editor find the right file no matter what the working directory is. We'd invoke it like cd go/src/whatever && go test --print-full-paths whatever/package
The text was updated successfully, but these errors were encountered: