Check that libc stays at the version the SQLite driver requires
modernc.org/sqlite is C transpiled to Go against one version of modernc.org/libc, and its go.mod names that version exactly: v1.80.1 for v1.64.0, while libc's latest is v1.82.14. A newer libc breaks the driver without a compile error, and a routine go get -u would move it. The owner accepted holding libc there as the one exception to taking each dependency at its latest stable release; it moves only with the driver. tools/libcpin compares the libc that go list -m selects with the one go mod graph shows the selected modernc.org/sqlite requiring, and fails with the go get that restores it. It runs as go run ./tools/libcpin, so it works from PowerShell and in CI alike. test.yml and make check run it after go mod tidy -diff, CLAUDE.md lists it in the gate and records the exception beside the dependency rule, and design.md records it under the stack choices. Moving libc to v1.82.14 with go get made the check fail as it should; the change was not kept. Part of stage 1d of docs/plans/job-store.md (decision 13). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5ae323b570
commit
2926a69598
7 files changed
+147
-8
No files matched your search
@@ -0,0 +1,91 @@
|
||||
// Command libcpin fails unless the module builds with the exact
|
||||
// modernc.org/libc that modernc.org/sqlite requires. The driver is C
|
||||
// transpiled to Go against one libc and works with that one only, so a
|
||||
// libc that a routine `go get -u` moved would break it without a compile
|
||||
// error. The gate runs it from the repository:
|
||||
//
|
||||
// go run ./tools/libcpin
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// The driver, and the module whose version it fixes.
|
||||
const (
|
||||
driver = "modernc.org/sqlite"
|
||||
libc = "modernc.org/libc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "libcpin:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
selected, err := moduleVersion(libc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
driverVersion, err := moduleVersion(driver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
graph, err := goOutput("mod", "graph")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
want, err := requirement(graph, driver+"@"+driverVersion, libc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if selected != want {
|
||||
return fmt.Errorf("%s is %s, but %s %s requires exactly %s: run go get %s@%s",
|
||||
libc, selected, driver, driverVersion, want, libc, want)
|
||||
}
|
||||
fmt.Printf("libcpin: %s %s is the version %s %s requires\n", libc, selected, driver, driverVersion)
|
||||
return nil
|
||||
}
|
||||
|
||||
// requirement returns the version of path that module, written
|
||||
// path@version, requires in graph, the output of go mod graph.
|
||||
func requirement(graph, module, path string) (string, error) {
|
||||
for line := range strings.Lines(graph) {
|
||||
from, to, ok := strings.Cut(strings.TrimSpace(line), " ")
|
||||
if !ok || from != module {
|
||||
continue
|
||||
}
|
||||
if p, version, ok := strings.Cut(to, "@"); ok && p == path {
|
||||
return version, nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("go mod graph shows no %s required by %s", path, module)
|
||||
}
|
||||
|
||||
// moduleVersion returns the version of path the main module selects.
|
||||
func moduleVersion(path string) (string, error) {
|
||||
out, err := goOutput("list", "-m", "-f", "{{.Version}}", path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(out), nil
|
||||
}
|
||||
|
||||
// goOutput runs the go command and returns what it writes to standard
|
||||
// output.
|
||||
func goOutput(args ...string) (string, error) {
|
||||
cmd := exec.Command("go", args...)
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("go %s: %w\n%s", strings.Join(args, " "), err, stderr.Bytes())
|
||||
}
|
||||
return string(out), nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRequirement(t *testing.T) {
|
||||
graph := "uberbringer modernc.org/sqlite@v1.64.0\n" +
|
||||
"uberbringer modernc.org/libc@v1.82.14\n" +
|
||||
"modernc.org/sqlite@v1.63.0 modernc.org/libc@v1.79.0\n" +
|
||||
"modernc.org/sqlite@v1.64.0 golang.org/x/sys@v0.49.0\n" +
|
||||
"modernc.org/sqlite@v1.64.0 modernc.org/libc@v1.80.1\n" +
|
||||
"modernc.org/libc@v1.80.1 modernc.org/memory@v1.12.1\n"
|
||||
tests := []struct {
|
||||
name, module, path, want string
|
||||
}{
|
||||
{"the driver's own requirement", "modernc.org/sqlite@v1.64.0", "modernc.org/libc", "v1.80.1"},
|
||||
{"another version of the driver", "modernc.org/sqlite@v1.63.0", "modernc.org/libc", "v1.79.0"},
|
||||
{"a module the driver does not require", "modernc.org/sqlite@v1.64.0", "modernc.org/memory", ""},
|
||||
{"a driver version not in the graph", "modernc.org/sqlite@v1.65.0", "modernc.org/libc", ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := requirement(graph, tt.module, tt.path)
|
||||
if got != tt.want || (err != nil) != (tt.want == "") {
|
||||
t.Errorf("requirement = %q, %v; want %q", got, err, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user