go/tools/gopackagesdriver: add automatic target detection#2932
Conversation
There was a problem hiding this comment.
Can we continue to support GOPACKAGESDRIVER_BAZEL_QUERY etc? This is important for large repos like Uber's Go monorepo. Although it's huge, most users only work on small subset of targets and only need to index their projects and dependencies. It's quite a waste of time for them to wait for hours for package driver to load //...
|
@linzhp I have updated the PR, it shouldn't load the whole |
|
@linzhp I have added |
|
@linzhp I have fixed lots of bugs, can you try this version? |
|
Here's a summary of the changes:
|
linzhp
left a comment
There was a problem hiding this comment.
It works now. Commented on other minor issues.
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
|
@linzhp can you confirm the CLA please? |
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
|
can't wait this merge to master |
linzhp
left a comment
There was a problem hiding this comment.
Some tests are failing.
It's strange that googlebot thought I didn't have CLA, given I already had several accepted pull requests to this repo.
@googlebot I consent.
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
|
The test failure is unrelated (race) |
|
|
very soon ! |
| fp, _ := filepath.Rel(b.bazel.WorkspaceRoot(), filename) | ||
| filename = fp | ||
| } | ||
| return fmt.Sprintf(`kind("go_library", same_pkg_direct_rdeps("%s"))`, filename) |
There was a problem hiding this comment.
This may return empty result when the filename is a test file like foo_test.go, because no go_library would depend on such file
There was a problem hiding this comment.
yeah, test files are not done atm, if you have an idea, i'm all ears
How should I try it? It seems to be a separate feature. Can you put it in a separate pull request? |
It failed consistently in recent commits, but not in earlier commits or master. So it may be broken by some recent commit |
Just verify that it correctly works as it did before. It's done behind the scenes. Basically Just check that the packagedriver continues to work on your repo. |
|
@linzhp careful:
|
This allows to use gopls in the project itself. Signed-off-by: Steeve Morin <steeve@zen.ly>
…eries When using `--universe_scope=//...`, the whole `//...` is loaded even though we only use `same_pkg_direct_rdeps`. So remove it and specify the scope in the query, such as `importpath` ones. Signed-off-by: Steeve Morin <steeve@zen.ly>
Add the `GOPACKAGESDRIVER_BAZEL_QUERY_SCOPE` environment variable so that bazel queries are limited the given scope. This should save time when doing `importpath` queries on large monorepos. Signed-off-by: Steeve Morin <steeve@zen.ly>
Co-authored-by: Zhongpeng Lin <zplin@uber.com>
While at it, fetch and parse the whole bazel info data.
…ault When fetching the whole graph, default to returning the stdlib packages so that vscode doesn't complain.
Easier to put them there
Guard against packages with the same prefix by happending `/` to HasPrefix and match the exact name if needed.
While it used to work, this is better.
Co-authored-by: Zhongpeng Lin <zplin@uber.com>
When there is no such go_library, the some function would lead to errors like ERROR: Evaluation of query failed: argument set is empty, with exit code 7. It is unclear whether the query has a bug or there is no matching package. If we don't have the some function, Bazel query will exit normally with empty result. We can report a better error to gopls for this case. Co-authored-by: Zhongpeng Lin <zplin@uber.com>
Signed-off-by: Steeve Morin <steeve@zen.ly>
This is done using a brand new build context that is configured using the regular environment variables. Signed-off-by: Steeve Morin <steeve@zen.ly>
Match a/ab and a/ab/c but not a/abc Signed-off-by: Steeve Morin <steeve@zen.ly>
Signed-off-by: Steeve Morin <steeve@zen.ly>
Co-authored-by: Zhongpeng Lin <zplin@uber.com>
Co-authored-by: Zhongpeng Lin <zplin@uber.com>
Signed-off-by: Steeve Morin <steeve@zen.ly>
Signed-off-by: Steeve Morin <steeve@zen.ly>
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
|
awesome |
…2932) This implements the actual fix where we are aggregating the whls and sdists correctly from multiple different requirements lines. Fixes bazel-contrib#2648. Closes bazel-contrib#2658.
What type of PR is this?
Feature
What does this PR do? Why is it needed?
This PR introduces automatic target detection so that no user input
is required after the
GOPACKAGESDRIVERsetup. This effectivelydeprecates the following environment variables:
GOPACKAGESDRIVER_BAZEL_TARGETSGOPACKAGESDRIVER_BAZEL_QUERYGOPACKAGESDRIVER_BAZEL_TAG_FILTERSIt works as follows:
importpathqueries, it willbazel querya matchinggo_librarymatching it
file=queries, it will try to find the matchinggo_libraryin thesame package
unionthosequeries and query that
Once the
go_librarytargets are found, it will try to build them directly,which should dramatically speed up compilation times, at the loss of transition
support (which wasn't used as much as I thought it would be).
I may reintroduce it in the future via a user-defined flag (to only build the
part of the graph that needs building).
In any case, toolchain or platforms can be switched with the following
environment variables it configuration transitions are needed:
GOPACKAGESDRIVER_BAZEL_FLAGSwhich will be passed tobazelinvocationsGOPACKAGESDRIVER_BAZEL_QUERY_FLAGSwhich will be passed tobazel queryinvocations
GOPACKAGESDRIVER_BAZEL_QUERY_SCOPEwhich specifies the scope forimportpathqueries (sincegoplsonly issuesfile=queries, so use if you know what you're doing!)GOPACKAGESDRIVER_BAZEL_BUILD_FLAGSwhich will be passed tobazel buildinvocations
Finally, the driver will not fail in case of a build failure, and even so
uses
--keep_goingand will return whatever packages that did build.Which issues(s) does this PR fix?
It should fix most of the issues from #2858.
Other notes for review
I have added a
.vscodefolder for folks who work onrules_gowith it so thatgoplsnow works there too!