From 8aaf047373b3df98c8d705d7dd053aa646513ab9 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Mon, 18 Dec 2023 13:38:59 +0000 Subject: [PATCH 1/2] Deal with generated main packages --- tools/driver/packages/packages.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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. From e068fd618fe5f187ff81ea8b04e9da1fe6194730 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Mon, 18 Dec 2023 13:39:36 +0000 Subject: [PATCH 2/2] version --- tools/driver/ChangeLog | 4 ++++ tools/driver/VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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