-
-
Notifications
You must be signed in to change notification settings - Fork 696
fix(gopackagesdriver): Improve wildcard package query matching #4288
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
base: master
Are you sure you want to change the base?
fix(gopackagesdriver): Improve wildcard package query matching #4288
Conversation
@@ -116,7 +116,7 @@ func (b *BazelJSONBuilder) adjustToRelativePathIfPossible(request string) string | |||
|
|||
func (b *BazelJSONBuilder) packageQuery(importPath string) string { | |||
if strings.HasSuffix(importPath, "/...") { | |||
importPath = fmt.Sprintf(`^%s(/.+)?$`, strings.TrimSuffix(importPath, "/...")) | |||
importPath = fmt.Sprintf(`%s(/.+)?$`, strings.TrimSuffix(importPath, "/...")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern supplied being treated as a regular expression can result in different behaviour if the input happens to contain regexp special characters. Leaving it as is here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change this, let's fix that as well. Could you wrap the import path into regexp.QuoteMeta
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a commit that escapes both the wild card case and the default case: 23be4f0
But this essentially means that the ./something
query won't work at least against the path that we are seeing //something
as \./something
won't match //something
. I'm unsure if this is correct, and/or if the //something
paths are only specific to our implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay the importpaths it's actually matching against are in the form of github.com/orgname/reponame/something/foo/bar
as defined in go_library() importpath
I'll test if importpath_aliases aliases fixes this for us with something like ./something/foo/bar
as the alias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm but the query is targetting only importpath
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for getting back to this so late, where are we at? Should I take another look?
What does the actual kind look like in that case that it doesn't match the start of string? |
@fmeum all the returned results without "^" start with
I'm not sure if this is what you mean by "kind" |
Thanks, I thought this also affected the usage of |
What type of PR is this?
Bug fix
What does this PR do? Why is it needed?
Improve wildcard package loading (
./something/...
) when using a custom bazelQueryScope e.g.//...
. Currently, the queryFromRequests transformation results in a query like:which fails to return any results due to the
^
start of string matching. This PR also aligns the behaviour more closely to the "non wild card" behaviour (see) by omitting the^
.When using go outside bazel, the following query is valid syntax and correctly loads all the packages under
./something/
:Which issues(s) does this PR fix?
No issue
Other notes for review