Skip to content
Open
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/driver/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 0.3.2
-------------
* Identify generated main packages rather than generating duplicate roots

Version 0.3.1
-------------
* Handle some additional cases for third-party packages
Expand Down
2 changes: 1 addition & 1 deletion tools/driver/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.3.2
27 changes: 26 additions & 1 deletion tools/driver/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"sync"

Expand Down Expand Up @@ -41,6 +42,9 @@ type DriverResponse struct {
Packages []*packages.Package
}

// mainTag is a tag we apply to (apparently) generated main packages
const mainTag = "#main"

// Load reads a set of packages and returns information about them.
// Most of the request structure isn't honoured at the moment.
func Load(req *DriverRequest, files []string) (*DriverResponse, error) {
Expand Down Expand Up @@ -137,6 +141,9 @@ func packagesToResponse(rootpath string, pkgs []*packages.Package, dirs map[stri
roots := []string{}
seenRuntime := false
for _, pkg := range pkgs {
if strings.HasSuffix(pkg.ID, mainTag) {
continue
}
if _, present := dirs[pkg.PkgPath]; present {
seenRoots[pkg.ID] = struct{}{}
roots = append(roots, pkg.ID)
Expand Down Expand Up @@ -283,7 +290,25 @@ func loadPackageInfoFiles(paths []string) ([]*packages.Package, error) {
return nil
})
}
return pkgs, g.Wait()
if err := g.Wait(); err != nil {
return nil, err
}
// Deal with e.g. generated main packages
slices.SortFunc(pkgs, func(a, b *packages.Package) int {
if a.ID > b.ID {
return 1
} else if a.ID < b.ID {
return -1
} else if a.Name == "main" && b.Name != "main" {
a.ID = a.ID + mainTag
return 1
} else if b.Name == "main" && a.Name != "main" {
b.ID = b.ID + mainTag
return -1
}
return 0
})
return pkgs, nil
}

// loadStdlibPackages returns all the packages from the Go stdlib.
Expand Down