Skip to content

Commit

Permalink
build(deps): bump github.com/ldez/gomoddirectives from 0.6.0 to 0.6.1 (
Browse files Browse the repository at this point in the history
…#5329)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
  • Loading branch information
dependabot[bot] and ldez authored Jan 16, 2025
1 parent dd0acd0 commit 29eaf2d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 62 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ require (
github.com/kyoh86/exportloopref v0.1.11
github.com/lasiar/canonicalheader v1.1.2
github.com/ldez/exptostd v0.3.1
github.com/ldez/gomoddirectives v0.6.0
github.com/ldez/grignotin v0.8.0
github.com/ldez/gomoddirectives v0.6.1
github.com/ldez/grignotin v0.9.0
github.com/ldez/tagliatelle v0.7.1
github.com/ldez/usetesting v0.4.2
github.com/leonklingele/grouper v1.1.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"cmp"
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -80,20 +81,20 @@ func IsGoGreaterThanOrEqual(current, limit string) bool {
return v1.GreaterThanOrEqual(l)
}

func detectGoVersion() string {
return cmp.Or(detectGoVersionFromGoMod(), "1.17")
func detectGoVersion(ctx context.Context) string {
return cmp.Or(detectGoVersionFromGoMod(ctx), "1.17")
}

// detectGoVersionFromGoMod tries to get Go version from go.mod.
// It returns `toolchain` version if present,
// else it returns `go` version if present,
// else it returns `GOVERSION` version if present,
// else it returns empty.
func detectGoVersionFromGoMod() string {
values, err := goenv.Get(goenv.GOMOD, goenv.GOVERSION)
func detectGoVersionFromGoMod(ctx context.Context) string {
values, err := goenv.Get(ctx, goenv.GOMOD, goenv.GOVERSION)
if err != nil {
values = map[string]string{
goenv.GOMOD: detectGoModFallback(),
goenv.GOMOD: detectGoModFallback(ctx),
}
}

Expand Down Expand Up @@ -143,8 +144,8 @@ func parseGoMod(goMod string) (*modfile.File, error) {
return modfile.Parse("go.mod", raw, nil)
}

func detectGoModFallback() string {
info, err := gomod.GetModuleInfo()
func detectGoModFallback(ctx context.Context) string {
info, err := gomod.GetModuleInfo(ctx)
if err != nil {
return ""
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"cmp"
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -286,7 +287,7 @@ func (l *Loader) appendStringSlice(name string, current *[]string) {

func (l *Loader) handleGoVersion() {
if l.cfg.Run.Go == "" {
l.cfg.Run.Go = detectGoVersion()
l.cfg.Run.Go = detectGoVersion(context.Background())
}

l.cfg.LintersSettings.Govet.Go = l.cfg.Run.Go
Expand Down
3 changes: 2 additions & 1 deletion pkg/goformatters/gci/gci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gci

import (
"context"
"fmt"

gcicfg "github.com/daixiang0/gci/pkg/config"
Expand All @@ -22,7 +23,7 @@ func New(settings *config.GciSettings) (*Formatter, error) {
log.InitLogger()
_ = log.L().Sync()

modPath, err := gomod.GetModulePath()
modPath, err := gomod.GetModulePath(context.Background())
if err != nil {
internal.FormatterLogger.Errorf("gci: %v", err)
}
Expand Down
34 changes: 10 additions & 24 deletions pkg/goutil/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,39 @@ package goutil

import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
"time"

"github.com/ldez/grignotin/goenv"

"github.com/golangci/golangci-lint/pkg/logutils"
)

type EnvKey string

const (
EnvGoCache EnvKey = "GOCACHE"
EnvGoRoot EnvKey = "GOROOT"
)

type Env struct {
vars map[string]string
log logutils.Log
debugf logutils.DebugFunc
vars map[string]string
log logutils.Log
}

func NewEnv(log logutils.Log) *Env {
return &Env{
vars: map[string]string{},
log: log,
debugf: logutils.Debug(logutils.DebugKeyEnv),
vars: map[string]string{},
log: log,
}
}

func (e Env) Discover(ctx context.Context) error {
startedAt := time.Now()

//nolint:gosec // Everything is static here.
cmd := exec.CommandContext(ctx, "go", "env", "-json", string(EnvGoCache), string(EnvGoRoot))

out, err := cmd.Output()
var err error
e.vars, err = goenv.Get(ctx, goenv.GOCACHE, goenv.GOROOT)
if err != nil {
return fmt.Errorf("failed to run '%s': %w", strings.Join(cmd.Args, " "), err)
}

if err = json.Unmarshal(out, &e.vars); err != nil {
return fmt.Errorf("failed to parse '%s' json: %w", strings.Join(cmd.Args, " "), err)
return fmt.Errorf("%w", err)
}

e.debugf("Read go env for %s: %#v", time.Since(startedAt), e.vars)
e.log.Infof("Read go env for %s: %#v", time.Since(startedAt), e.vars)

return nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/lint/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/ldez/grignotin/goenv"
"golang.org/x/tools/go/packages"

"github.com/golangci/golangci-lint/pkg/config"
Expand Down Expand Up @@ -204,12 +205,13 @@ func (l *PackageLoader) debugPrintLoadedPackages(pkgs []*packages.Package) {
func (l *PackageLoader) prepareBuildContext() {
// Set GOROOT to have working cross-compilation: cross-compiled binaries
// have invalid GOROOT. XXX: can't use runtime.GOROOT().
goroot := l.goenv.Get(goutil.EnvGoRoot)
goroot := l.goenv.Get(goenv.GOROOT)
if goroot == "" {
return
}

os.Setenv(string(goutil.EnvGoRoot), goroot)
_ = os.Setenv(goenv.GOROOT, goroot)

build.Default.GOROOT = goroot
build.Default.BuildTags = l.cfg.Run.BuildTags
}
Expand Down
47 changes: 28 additions & 19 deletions pkg/logutils/logutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,47 @@ const EnvTestRun = "GL_TEST_RUN"
// - Some analysis details: `GL_DEBUG=goanalysis/analyze,goanalysis/facts golangci-lint run`
const envDebug = "GL_DEBUG"

const (
DebugKeyBinSalt = "bin_salt"
DebugKeyConfigReader = "config_reader"
DebugKeyEmpty = ""
DebugKeyEnabledLinters = "enabled_linters"
DebugKeyExec = "exec"
DebugKeyFormatter = "formatter"
DebugKeyGoEnv = "goenv"
DebugKeyLinter = "linter"
DebugKeyLintersContext = "linters_context"
DebugKeyLintersDB = "lintersdb"
DebugKeyLintersOutput = "linters_output"
DebugKeyLoader = "loader" // Debugs packages loading (including `go/packages` internal debugging).
DebugKeyPkgCache = "pkgcache"
DebugKeyRunner = "runner"
DebugKeyStopwatch = "stopwatch"
DebugKeyTest = "test"
)

// Printers.
const (
DebugKeyTabPrinter = "tab_printer"
DebugKeyTextPrinter = "text_printer"
)

// Processors.
const (
DebugKeyAutogenExclude = "autogen_exclude" // Debugs a filter excluding autogenerated source code.
DebugKeyBinSalt = "bin_salt"
DebugKeyConfigReader = "config_reader"
DebugKeyEmpty = ""
DebugKeyEnabledLinters = "enabled_linters"
DebugKeyEnv = "env" // Debugs `go env` command.
DebugKeyExcludeRules = "exclude_rules"
DebugKeyExec = "exec"
DebugKeyFilenameUnadjuster = "filename_unadjuster"
DebugKeyFormatter = "formatter"
DebugKeyGoEnv = "goenv"
DebugKeyInvalidIssue = "invalid_issue"
DebugKeyLinter = "linter"
DebugKeyLintersContext = "linters_context"
DebugKeyLintersDB = "lintersdb"
DebugKeyLintersOutput = "linters_output"
DebugKeyLoader = "loader" // Debugs packages loading (including `go/packages` internal debugging).
DebugKeyMaxFromLinter = "max_from_linter"
DebugKeyMaxSameIssues = "max_same_issues"
DebugKeyPathAbsoluter = "path_absoluter"
DebugKeyPathPrettifier = "path_prettifier"
DebugKeyPkgCache = "pkgcache"
DebugKeyRunner = "runner"
DebugKeySeverityRules = "severity_rules"
DebugKeySkipDirs = "skip_dirs"
DebugKeySourceCode = "source_code"
DebugKeyStopwatch = "stopwatch"
DebugKeyTabPrinter = "tab_printer"
DebugKeyTest = "test"
DebugKeyTextPrinter = "text_printer"
)

// Analysis.
const (
DebugKeyGoAnalysis = "goanalysis"

Expand All @@ -61,6 +69,7 @@ const (
DebugKeyGoAnalysisFactsInherit = DebugKeyGoAnalysisFacts + "/inherit"
)

// Linters.
const (
DebugKeyForbidigo = "forbidigo" // Debugs `forbidigo` linter.
DebugKeyGoCritic = "gocritic" // Debugs `gocritic` linter.
Expand Down
6 changes: 4 additions & 2 deletions pkg/result/processors/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"path/filepath"
"strings"

"github.com/ldez/grignotin/goenv"

"github.com/golangci/golangci-lint/pkg/goutil"
"github.com/golangci/golangci-lint/pkg/result"
)
Expand All @@ -19,9 +21,9 @@ type Cgo struct {
goCacheDir string
}

func NewCgo(goenv *goutil.Env) *Cgo {
func NewCgo(env *goutil.Env) *Cgo {
return &Cgo{
goCacheDir: goenv.Get(goutil.EnvGoCache),
goCacheDir: env.Get(goenv.GOCACHE),
}
}

Expand Down

0 comments on commit 29eaf2d

Please sign in to comment.