mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Support Go 1.18: Upgrade gqlgen to v0.17.2 (#2443)
* Upgrade gqlgen to v0.17.2 This enables builds on Go 1.18. github.com/vektah/gqlparser is upgraded to the newest version too. Getting this to work is a bit of a hazzle. I had to first remove vendoring from the repository, perform the upgrade and then re-introduce the vendor directory. I think gqlgens analysis went wrong for some reason on the upgrade. It would seem a clean-room installation fixed it. * Bump project to 1.18 * Update all packages, address gqlgenc breaking changes * Let `go mod tidy` handle the go.mod file * Upgrade linter to 1.45.2 * Introduce v1.45.2 of the linter The linter now correctly warns on `strings.Title` because it isn't unicode-aware. Fix this by using the suggested fix from x/text/cases to produce unicode-aware strings. The mapping isn't entirely 1-1 as this new approach has a larger iface: it spans all of unicode rather than just ASCII. It coincides for ASCII however, so things should be largely the same. * Ready ourselves for errchkjson and contextcheck. * Revert dockerfile golang version changes for now Co-authored-by: Kermie <kermie@isinthe.house> Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
54
vendor/github.com/99designs/gqlgen/internal/code/packages.go
generated
vendored
54
vendor/github.com/99designs/gqlgen/internal/code/packages.go
generated
vendored
@@ -2,9 +2,12 @@ package code
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
@@ -13,7 +16,9 @@ var mode = packages.NeedName |
|
||||
packages.NeedImports |
|
||||
packages.NeedTypes |
|
||||
packages.NeedSyntax |
|
||||
packages.NeedTypesInfo
|
||||
packages.NeedTypesInfo |
|
||||
packages.NeedModule |
|
||||
packages.NeedDeps
|
||||
|
||||
// Packages is a wrapper around x/tools/go/packages that maintains a (hopefully prewarmed) cache of packages
|
||||
// that can be invalidated as writes are made and packages are known to change.
|
||||
@@ -26,6 +31,22 @@ type Packages struct {
|
||||
numNameCalls int // stupid test steam. ignore.
|
||||
}
|
||||
|
||||
// ReloadAll will call LoadAll after clearing the package cache, so we can reload
|
||||
// packages in the case that the packages have changed
|
||||
func (p *Packages) ReloadAll(importPaths ...string) []*packages.Package {
|
||||
p.packages = nil
|
||||
return p.LoadAll(importPaths...)
|
||||
}
|
||||
|
||||
func (p *Packages) checkModuleLoaded(pkgs []*packages.Package) bool {
|
||||
for i := range pkgs {
|
||||
if pkgs[i] == nil || pkgs[i].Module == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// LoadAll will call packages.Load and return the package data for the given packages,
|
||||
// but if the package already have been loaded it will return cached values instead.
|
||||
func (p *Packages) LoadAll(importPaths ...string) []*packages.Package {
|
||||
@@ -44,6 +65,13 @@ func (p *Packages) LoadAll(importPaths ...string) []*packages.Package {
|
||||
if len(missing) > 0 {
|
||||
p.numLoadCalls++
|
||||
pkgs, err := packages.Load(&packages.Config{Mode: mode}, missing...)
|
||||
|
||||
// Sometimes packages.Load not loaded the module info. Call it again to reload it.
|
||||
if !p.checkModuleLoaded(pkgs) {
|
||||
fmt.Println("reloading module info")
|
||||
pkgs, err = packages.Load(&packages.Config{Mode: mode}, missing...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
p.loadErrors = append(p.loadErrors, err)
|
||||
}
|
||||
@@ -72,6 +100,13 @@ func (p *Packages) addToCache(pkg *packages.Package) {
|
||||
|
||||
// Load works the same as LoadAll, except a single package at a time.
|
||||
func (p *Packages) Load(importPath string) *packages.Package {
|
||||
// Quick cache check first to avoid expensive allocations of LoadAll()
|
||||
if p.packages != nil {
|
||||
if pkg, ok := p.packages[importPath]; ok {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
|
||||
pkgs := p.LoadAll(importPath)
|
||||
if len(pkgs) == 0 {
|
||||
return nil
|
||||
@@ -149,6 +184,17 @@ func (p *Packages) Evict(importPath string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Packages) ModTidy() error {
|
||||
p.packages = nil
|
||||
tidyCmd := exec.Command("go", "mod", "tidy")
|
||||
tidyCmd.Stdout = os.Stdout
|
||||
tidyCmd.Stderr = os.Stdout
|
||||
if err := tidyCmd.Run(); err != nil {
|
||||
return fmt.Errorf("go mod tidy failed: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Errors returns any errors that were returned by Load, either from the call itself or any of the loaded packages.
|
||||
func (p *Packages) Errors() PkgErrors {
|
||||
var res []error //nolint:prealloc
|
||||
@@ -161,6 +207,10 @@ func (p *Packages) Errors() PkgErrors {
|
||||
return res
|
||||
}
|
||||
|
||||
func (p *Packages) Count() int {
|
||||
return len(p.packages)
|
||||
}
|
||||
|
||||
type PkgErrors []error
|
||||
|
||||
func (p PkgErrors) Error() string {
|
||||
|
||||
Reference in New Issue
Block a user