-
-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/tools/gopackagesdriver: add automatic target detection (#2932)
* go/tools/gopackagesdriver: add automatic target detection This commit introduces automatic target detection so that no user input is required after the `GOPACKAGESDRIVER` setup. This effectively deprecates the following environment variables: - `GOPACKAGESDRIVER_BAZEL_TARGETS` - `GOPACKAGESDRIVER_BAZEL_QUERY` - `GOPACKAGESDRIVER_BAZEL_TAG_FILTERS` It works as follows: - for `importpath` queries, it will `bazel query` a matching `go_library` matching it - for `file=` queries, it will try to find the matching `go_library` in the same package - since it supports multiple queries at the same time, it will `union` those queries and query that Once the `go_library` targets 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_FLAGS` which will be passed to `bazel` invocations - `GOPACKAGESDRIVER_BAZEL_QUERY_FLAGS` which will be passed to `bazel query` invocations - `GOPACKAGESDRIVER_BAZEL_QUERY_SCOPE` which controls the scope of `bazel query` invocations - `GOPACKAGESDRIVER_BAZEL_BUILD_FLAGS` which will be passed to `bazel build` invocations Finally, the driver will not fail in case of a build failure, and even so uses `--keep_going` and will return whatever packages that did build. Signed-off-by: Steeve Morin <[email protected]> * workspace: add vscode configuration This allows to use gopls in the project itself. Signed-off-by: Steeve Morin <[email protected]> * go/tools/gopackagesdriver: don't use //... universe scope for file queries 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 <[email protected]> * go/tools/gopackagesdriver: add GOPACKAGESDRIVER_BAZEL_QUERY_SCOPE 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 <[email protected]> * Allow querying external dependencies with importpath Co-authored-by: Zhongpeng Lin <[email protected]> * go/tools/gopackagesdriver: fetch output_base from bazel info While at it, fetch and parse the whole bazel info data. * go/tools/gopackagesdriver: pull source files and return stdlib by default When fetching the whole graph, default to returning the stdlib packages so that vscode doesn't complain. * Fix typo * Fix formatting * Enable queries on package registry * Move some utiliy functions to the utils file Easier to put them there * Remove unsued bazel struct members * Don't match only by string prefix when matching /... Guard against packages with the same prefix by happending `/` to HasPrefix and match the exact name if needed. * Stdlib files are relative to the output_base, not execroot While it used to work, this is better. * Simpler error checking for bazel errors Co-authored-by: Zhongpeng Lin <[email protected]> * Don't use some on bazel query for package 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 <[email protected]> * CHeck for empty labels when trying to build a target Signed-off-by: Steeve Morin <[email protected]> * Honor build tags when listing files This is done using a brand new build context that is configured using the regular environment variables. Signed-off-by: Steeve Morin <[email protected]> * Properly match full and child importpaths Match a/ab and a/ab/c but not a/abc Signed-off-by: Steeve Morin <[email protected]> * Add a comment telling why we exit(0) Signed-off-by: Steeve Morin <[email protected]> * Better regexp for importpath matching Co-authored-by: Zhongpeng Lin <[email protected]> * Don't append empty bazel queries to bazel build Co-authored-by: Zhongpeng Lin <[email protected]> * Make completion on test files work Signed-off-by: Steeve Morin <[email protected]> * Handle tests that don't have embedded libraries Signed-off-by: Steeve Morin <[email protected]> Co-authored-by: Zhongpeng Lin <[email protected]>
- Loading branch information
Showing
14 changed files
with
437 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"bazelbuild.vscode-bazel", | ||
"golang.go", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"files.trimTrailingWhitespace": true, | ||
"files.insertFinalNewline": true, | ||
"go.goroot": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/go_sdk", | ||
"go.toolsEnvVars": { | ||
"GOPACKAGESDRIVER": "${workspaceFolder}/tools/gopackagesdriver.sh" | ||
}, | ||
"go.enableCodeLens": { | ||
"references": false, | ||
"runtest": false | ||
}, | ||
"gopls": { | ||
"formatting.gofumpt": true, | ||
"formatting.local": "github.com/bazelbuild/rules_go", | ||
"ui.completion.usePlaceholders": true, | ||
"ui.semanticTokens": true, | ||
"ui.codelenses": { | ||
"gc_details": false, | ||
"regenerate_cgo": false, | ||
"generate": false, | ||
"test": false, | ||
"tidy": false, | ||
"upgrade_dependency": false, | ||
"vendor": false | ||
}, | ||
}, | ||
"go.useLanguageServer": true, | ||
"go.buildOnSave": "off", | ||
"go.lintOnSave": "off", | ||
"go.vetOnSave": "off", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.