~sircmpwn/gddo

55358d4d592d589c2c3c1a7e081030412732d921 — Adnan Maolood 5 months ago 6d8763f master 1.18.3
internal/proxy: Compute stdlib latest version

The latest Go toolchain version does not have to match the latest Go
stdlib version. Manually compute the latest version instead.
2 files changed, 36 insertions(+), 13 deletions(-)

M internal/proxy/proxy.go
M internal/proxy/stdlib.go
M internal/proxy/proxy.go => internal/proxy/proxy.go +14 -13
@@ 118,19 118,23 @@ func (c *Client) Module(modulePath, version string) (*internal.Module, error) {

func (c *Client) stdlibModule(version string) (*internal.Module, error) {
	// Get version info
	v, err := toolchainVersion(version)
	rawVersions, err := c.listVersions(ToolchainModulePath)
	if err != nil {
		return nil, err
	}
	info, err := c.getInfo(ToolchainModulePath, v)
	if err != nil {
		return nil, err
	versions := stdlibVersions(rawVersions)
	latestVersion := stdlibLatest(versions)

	resolvedVersion := version
	if version == internal.LatestVersion {
		resolvedVersion = latestVersion
	}
	latest, err := c.getInfo(ToolchainModulePath, internal.LatestVersion)

	v, err := toolchainVersion(resolvedVersion)
	if err != nil {
		return nil, err
	}
	versions, err := c.listVersions(ToolchainModulePath)
	info, err := c.getInfo(ToolchainModulePath, v)
	if err != nil {
		return nil, err
	}


@@ 141,19 145,16 @@ func (c *Client) stdlibModule(version string) (*internal.Module, error) {
	}
	// No size limit for Go toolchain modules

	tag := stdlibTag(info.Version)
	latestTag := stdlibTag(latest.Version)

	return &internal.Module{
		ModulePath:    StdlibModulePath,
		RawModulePath: ToolchainModulePath,
		SeriesPath:    StdlibModulePath,
		Version:       versionForTag(tag),
		Version:       resolvedVersion,
		RawVersion:    info.Version,
		Reference:     tag,
		Reference:     stdlibTag(info.Version),
		CommitTime:    info.Time,
		LatestVersion: versionForTag(latestTag),
		Versions:      stdlibVersions(versions),
		LatestVersion: latestVersion,
		Versions:      versions,
		ZipSize:       zipSize,
	}, nil
}

M internal/proxy/stdlib.go => internal/proxy/stdlib.go +22 -0
@@ 6,6 6,7 @@ import (
	"strings"

	"git.sr.ht/~sircmpwn/gddo/internal"
	"golang.org/x/mod/module"
	"golang.org/x/mod/semver"
)



@@ 36,6 37,8 @@ func stdlibTag(v string) string {
	return strings.TrimPrefix(v, "v0.0.1-")
}

// stdlibVersions returns the corresponding semantic versions for the given
// Go toolchain versions.
func stdlibVersions(vs []string) []string {
	result := []string{}
	for i := 0; i < len(vs); i++ {


@@ 47,6 50,25 @@ func stdlibVersions(vs []string) []string {
	return result
}

// stdlibLatest returns the latest standard library version from the given
// semantic versions.
func stdlibLatest(vs []string) string {
	var latestVersion string
	for _, v := range vs {
		if !strings.HasPrefix(v, "v") {
			continue
		}
		if module.IsPseudoVersion(v) || semver.Prerelease(v) != "" {
			// We expect there to always be at least 1 release version.
			continue
		}
		if semver.Compare(v, latestVersion) > 0 {
			latestVersion = v
		}
	}
	return latestVersion
}

// stdlibDir returns the directory of the standard library relative to the toolchain root.
func stdlibDir(version string) string {
	if semver.Compare(version, "v1.4.0-beta.1") >= 0 ||