diff --git a/tools/driver/ChangeLog b/tools/driver/ChangeLog index c8f2c990..f0992adf 100644 --- a/tools/driver/ChangeLog +++ b/tools/driver/ChangeLog @@ -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 diff --git a/tools/driver/VERSION b/tools/driver/VERSION index 9e11b32f..d15723fb 100644 --- a/tools/driver/VERSION +++ b/tools/driver/VERSION @@ -1 +1 @@ -0.3.1 +0.3.2 diff --git a/tools/driver/packages/packages.go b/tools/driver/packages/packages.go index fa73ad32..ec0f5555 100644 --- a/tools/driver/packages/packages.go +++ b/tools/driver/packages/packages.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "path/filepath" + "slices" "strings" "sync" @@ -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) { @@ -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) @@ -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.