Skip to content
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

Handle vendor packages #251

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/please_go/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 1.10.6
--------------
* packageinfo files correctly account for stdlib vendoring

Version 1.10.5
--------------
* upgrade x/mod to support new directives
Expand Down
2 changes: 1 addition & 1 deletion tools/please_go/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.5
1.10.6
14 changes: 14 additions & 0 deletions tools/please_go/packageinfo/packageinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ func WritePackageInfo(importPath string, srcRoot, importconfig string, imports m
return !present
})
}
// Vendor packages. They aren't identified by the original imports but we know what they are now.
vendorised := map[string]*packages.Package{}
for _, pkg := range pkgs {
if strings.HasPrefix(pkg.PkgPath, "vendor/") {
vendorised[strings.TrimPrefix(pkg.PkgPath, "vendor/")] = pkg
}
}
for _, pkg := range pkgs {
for k := range pkg.Imports {
if v, present := vendorised[k]; present {
pkg.Imports[k] = v
}
}
}
// Ensure output is deterministic
sort.Slice(pkgs, func(i, j int) bool {
return pkgs[i].ID < pkgs[j].ID
Expand Down
Loading