vendorstamp
v1.64.0
Documentation
pkg.go.dev ↗Package vendorstamp checks vendor.json, the record make vendor writes of where the generated code in lib/ and vec/ came from.
make vendor copies transpiled Go from sibling checkouts of modernc.org/libsqlite3 and modernc.org/libsqlite_vec. Neither is a module dependency, so without this record the revisions that produced a release could not be recovered from the repository. vendor.json names them, the Go toolchain the vendoring ran under, and a digest of the files it produced, so that a later edit of those files, or a stamp left over from an earlier run, is caught.
Check is what the test suite and the pipeline run. The file is written by vendor_libs/main.go, which is a separate, build-tagged tool; it computes OutputDigest the same way, and a disagreement between the two fails Check.
Constants
FileName
const FileName = "vendor.json"
FileName is the stamp, at the repository root.
Variables
OutputPatterns
var OutputPatterns = []string{"lib/sqlite*.go", "vec/vec*.go", "LICENSE-SQLITE_VEC"}
OutputPatterns are the files make vendor produces, as globs relative to the repository root. The hand-written files in lib/ and vec/ match none of them.
Functions
Check
func Check(root string) error
Check reads the stamp at root and verifies it: its fields, its libc against root's go.mod, and its output digest against the files on disk.
GoModFields
func GoModFields(line string) []string
GoModFields splits one line of a go.mod file into its tokens: the comment is dropped, parentheses are tokens of their own and quoted strings are unquoted, as the go.mod grammar allows. Module paths contain neither spaces nor "//".
GoModRequire
func GoModRequire(name, path string) (string, error)
GoModRequire returns the version of path that the go.mod file at name requires, or "" if it requires none. A path required twice is an error rather than a guess at which requirement wins.
OutputDigest
func OutputDigest(root string) (int, string, error)
OutputDigest returns the number of output files under root and a digest of them: the SHA-256 of lines "<sha256 of file> <path>\n", in path order, the format sha256sum prints. Carriage returns before a line feed are dropped before hashing a file, so that a checkout converting line endings does not change the digest; they carry no meaning in Go source or in the notice.
OutputFiles
func OutputFiles(root string) ([]string, error)
OutputFiles lists the files matching OutputPatterns under root, sorted, with slash-separated paths relative to root.
Types
Output
type Output struct {
Files int `json:"files"`
SHA256 string `json:"sha256"`
}
Output identifies the files make vendor produced.
Source
type Source struct {
Module string `json:"module"`
// Into is the directory of this repository the source was vendored into.
Into string `json:"into"`
Commit string `json:"commit"`
Tags []string `json:"tags"`
// Dirty is a pointer so that an absent value is an error, not false.
Dirty *bool `json:"dirty"`
// Requires holds what the checkout's go.mod declares, which is not proof
// of the binaries that generated its files: a go.work workspace can
// override them. The first line of each generated file records the
// generator invocation itself.
Requires map[string]string `json:"requires"`
}
Source is one sibling checkout make vendor read from.
Stamp
type Stamp struct {
// Go is the toolchain make vendor ran under, as go env GOVERSION reports it.
// It matters: gofmt output differs between Go releases.
Go string `json:"go"`
// Undup is the pinned deduplicator, as pkg@version.
Undup string `json:"undup"`
Sources []Source `json:"sources"`
Output Output `json:"output"`
}
Stamp is the content of vendor.json.
Read
func Read(root string) (*Stamp, error)
Read decodes the stamp at root.
Stamp.Validate
func (s *Stamp) Validate(goModLibc string) error
Validate checks the stamp on its own and against goModLibc, the version of modernc.org/libc this repository's go.mod requires.