TUN-9016: update go to 1.24

## Summary

Update several moving parts of cloudflared build system:

* use goboring 1.24.2 in cfsetup
* update linter and fix lint issues
* update packages namely **quic-go and net**
* install script for macos
* update docker files to use go 1.24.1
* remove usage of cloudflare-go
* pin golang linter

Closes TUN-9016
This commit is contained in:
Luis Neto
2025-06-06 09:05:49 +00:00
parent e144eac2af
commit 96ce66bd30
585 changed files with 23572 additions and 21356 deletions

View File

@@ -393,8 +393,8 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac
// try base0, base1, ...
pkgName := base
if _, ok := definedImports[base]; ok {
pkgName = definedImports[base]
if _, ok := definedImports[pth]; ok {
pkgName = definedImports[pth]
}
i := 0
@@ -758,6 +758,17 @@ func (g *generator) GenerateMockReturnCallMethod(intf *model.Interface, m *model
return nil
}
// nameExistsAsPackage returns true if the name exists as a package name.
// This is used to avoid name collisions when generating mock method arguments.
func (g *generator) nameExistsAsPackage(name string) bool {
for _, symbolName := range g.packageMap {
if symbolName == name {
return true
}
}
return false
}
func (g *generator) getArgNames(m *model.Method, in bool) []string {
var params []*model.Parameter
if in {
@@ -766,16 +777,19 @@ func (g *generator) getArgNames(m *model.Method, in bool) []string {
params = m.Out
}
argNames := make([]string, len(params))
for i, p := range params {
name := p.Name
if name == "" || name == "_" {
if name == "" || name == "_" || g.nameExistsAsPackage(name) {
name = fmt.Sprintf("arg%d", i)
}
argNames[i] = name
}
if m.Variadic != nil && in {
name := m.Variadic.Name
if name == "" {
if name == "" || g.nameExistsAsPackage(name) {
name = fmt.Sprintf("arg%d", len(params))
}
argNames = append(argNames, name)

View File

@@ -4,6 +4,7 @@ import (
"errors"
"flag"
"fmt"
"go/ast"
"go/types"
"strings"
@@ -17,6 +18,20 @@ var (
type packageModeParser struct {
pkgName string
// Mapping from underlying types to aliases used within the package source.
//
// We prefer to use aliases used in the source rather than underlying type names
// as those may be unexported or internal.
// TODO(joaks): Once mock is Go1.23+ only, we can remove this
// as the casing for types.Alias will automatically handle this
// in all cases.
aliasReplacements map[types.Type]aliasReplacement
}
type aliasReplacement struct {
name string
pkg string
}
func (p *packageModeParser) parsePackage(packageName string, ifaces []string) (*model.Package, error) {
@@ -27,6 +42,8 @@ func (p *packageModeParser) parsePackage(packageName string, ifaces []string) (*
return nil, fmt.Errorf("load package: %w", err)
}
p.buildAliasReplacements(pkg)
interfaces, err := p.extractInterfacesFromPackage(pkg, ifaces)
if err != nil {
return nil, fmt.Errorf("extract interfaces from package: %w", err)
@@ -39,6 +56,90 @@ func (p *packageModeParser) parsePackage(packageName string, ifaces []string) (*
}, nil
}
// buildAliasReplacements finds and records any references to aliases
// within the given package's source.
// These aliases will be preferred when parsing types
// over the underlying name counterparts, as those may be unexported / internal.
//
// If a type has more than one alias within the source package,
// the latest one to be inspected will be the one used for mapping.
// This is fine, since all aliases and their underlying types are interchangeable
// from a type-checking standpoint.
func (p *packageModeParser) buildAliasReplacements(pkg *packages.Package) {
p.aliasReplacements = make(map[types.Type]aliasReplacement)
// checkIdent checks if the given identifier exists
// in the given package as an alias, and adds it to
// the alias replacements map if so.
checkIdent := func(pkg *types.Package, ident string) bool {
scope := pkg.Scope()
if scope == nil {
return true
}
obj := scope.Lookup(ident)
if obj == nil {
return true
}
objTypeName, ok := obj.(*types.TypeName)
if !ok {
return true
}
if !objTypeName.IsAlias() {
return true
}
typ := objTypeName.Type()
if typ == nil {
return true
}
p.aliasReplacements[typ] = aliasReplacement{
name: objTypeName.Name(),
pkg: pkg.Path(),
}
return false
}
for _, f := range pkg.Syntax {
fileScope, ok := pkg.TypesInfo.Scopes[f]
if !ok {
continue
}
ast.Inspect(f, func(node ast.Node) bool {
// Simple identifiers: check if it is an alias
// from the source package.
if ident, ok := node.(*ast.Ident); ok {
return checkIdent(pkg.Types, ident.String())
}
// Selector expressions: check if it is an alias
// from the package represented by the qualifier.
selExpr, ok := node.(*ast.SelectorExpr)
if !ok {
return true
}
x, sel := selExpr.X, selExpr.Sel
xident, ok := x.(*ast.Ident)
if !ok {
return true
}
xObj := fileScope.Lookup(xident.String())
pkgName, ok := xObj.(*types.PkgName)
if !ok {
return true
}
xPkg := pkgName.Imported()
if xPkg == nil {
return true
}
return checkIdent(xPkg, sel.String())
})
}
}
func (p *packageModeParser) loadPackage(packageName string) (*packages.Package, error) {
var buildFlagsSet []string
if *buildFlags != "" {
@@ -46,7 +147,7 @@ func (p *packageModeParser) loadPackage(packageName string) (*packages.Package,
}
cfg := &packages.Config{
Mode: packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedEmbedFiles,
Mode: packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedEmbedFiles | packages.LoadSyntax,
BuildFlags: buildFlagsSet,
}
pkgs, err := packages.Load(cfg, packageName)
@@ -193,17 +294,26 @@ func (p *packageModeParser) parseType(t types.Type) (model.Type, error) {
return sig, nil
case *types.Named, *types.Alias:
object := t.(interface{ Obj() *types.TypeName })
name := object.Obj().Name()
var pkg string
if object.Obj().Pkg() != nil {
pkg = object.Obj().Pkg().Path()
}
// If there was an alias to this type used somewhere in the source,
// use that alias instead of the underlying type,
// since the underlying type might be unexported.
if alias, ok := p.aliasReplacements[t]; ok {
name = alias.name
pkg = alias.pkg
}
// TypeArgs method not available for aliases in go1.22
genericType, ok := t.(interface{ TypeArgs() *types.TypeList })
if !ok || genericType.TypeArgs() == nil {
return &model.NamedType{
Package: pkg,
Type: object.Obj().Name(),
Type: name,
}, nil
}
@@ -220,7 +330,7 @@ func (p *packageModeParser) parseType(t types.Type) (model.Type, error) {
return &model.NamedType{
Package: pkg,
Type: object.Obj().Name(),
Type: name,
TypeParams: typeParams,
}, nil
case *types.Interface: