Skip to content

Commit

Permalink
Handle vendor packages (#251)
Browse files Browse the repository at this point in the history
* Handle vendor packages

* version
  • Loading branch information
peterebden authored Mar 13, 2024
1 parent d58ae58 commit dcd115a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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

0 comments on commit dcd115a

Please sign in to comment.