feat(golangci): use gnopls as GOPACKAGESDRIVER when available#190
Open
feat(golangci): use gnopls as GOPACKAGESDRIVER when available#190
Conversation
Detect gnopls on PATH and require GNOROOT in the environment, then point golangci-lint at gnopls via a once-written shim script so go/packages can resolve gno.land/... imports. Without this wiring the standard Go loader fails for pure-gno packages and golangci-lint exits with empty stdout — the previous commit absorbs that as a silent fallback, so an environment lacking either gnopls or GNOROOT keeps the same behavior as before. GOPACKAGESDRIVER takes a single executable path, which means "gnopls resolve" needs a wrapper. Write a per-pid shim into the OS temp dir on first use and let the OS reclaim it; ship a Windows .cmd variant alongside the unix sh script. Cache the resulting subprocess env so PATH lookup, shim creation, and the os.Environ() snapshot run once per process instead of per CheckPackage call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gnoplsas thego/packagesexternal driver (GOPACKAGESDRIVER) when bothgnoplsis onPATHandGNOROOTis set, sogolangci-lintcan analyze.gnopackages whose imports includegno.land/....golangci-lintexits with empty stdout. The previous fix absorbs that as a silent fallback, so environments lackinggnoplsorGNOROOTsee no behavioral change.GOPACKAGESDRIVERaccepts a single executable path; write a per-pid shim (#!/bin/sh\nexec <gnopls> resolve "$@"on unix,.cmdvariant on Windows) into the OS temp dir on first use and let the OS reclaim it.os.Environ()snapshot once per process so the addition is a single atomic load on the per-file hot path.Background
gnopls implements the
go/packagesexternal-driver protocol: itsgnopls resolvesubcommand walks$GNOROOT/gnovm/stdlibsand$GNOROOT/examples/, parses each directory'sgnomod.toml, and serves a fully populated package graph back to anygo/packages.Loadcaller (whichgolangci-lintuses internally). SettingGOPACKAGESDRIVERto thegnoplsshim is enough — nogolangci-lintfork needed.Test plan
go build ./...make test— race + shuffle cleango test -bench=BenchmarkRun -benchmem -run=^$ -benchtime=10x -count=3 ./internal/matchesmainto within ±0.1% on B/op and allocs/opTestGnoDriverEnv— five subtests covering all detection branches via injectedlookPath/getenv/ensureShimTestWriteGnoplsShim_{Unix,Windows,FailsOnUnwritableDir}— script body, mode bits, error pathgnoplsonPATHandGNOROOTexported, runtlin .against a.gnopackage and confirmgolangci-lintissues now surfacegnopls, confirm fallback (no errors, no per-file warnings)Notes
os.TempDir()after the process exits — relies on OS-level temp cleanup. Per-pid filename avoids collisions.nilenv fromcachedDriverEnvandgolangci-lintruns without a custom driver, which the prior fix already handles.